@@ -30,8 +30,7 @@ func (pcpServer *PcpServer) Execute(source string, attachment interface{}) (inte
30
30
31
31
// @param arr. Pure Json Object.
32
32
func (pcpServer * PcpServer ) ExecuteJsonObj (arr interface {}, attachment interface {}) (interface {}, error ) {
33
- ast := parseAst (arr )
34
- return pcpServer .ExecuteAst (ast , attachment )
33
+ return pcpServer .ExecuteAst (ParseJsonObjectToAst (arr ), attachment )
35
34
}
36
35
37
36
func (p * PcpServer ) ExecuteAst (ast interface {}, attachment interface {}) (interface {}, error ) {
@@ -47,6 +46,7 @@ func (p *PcpServer) ExecuteAst(ast interface{}, attachment interface{}) (interfa
47
46
48
47
var err error = nil
49
48
49
+ // resolve params in concurrent way
50
50
for i , param := range funNode .params {
51
51
wg .Add (1 )
52
52
go func (i int , param interface {}) {
@@ -78,7 +78,8 @@ func (p *PcpServer) ExecuteAst(ast interface{}, attachment interface{}) (interfa
78
78
return ast , nil
79
79
}
80
80
81
- func parseAst (source interface {}) interface {} {
81
+ // convert source object to ast
82
+ func ParseJsonObjectToAst (source interface {}) interface {} {
82
83
switch arr := source .(type ) {
83
84
case []interface {}:
84
85
if len (arr ) == 0 {
@@ -87,13 +88,13 @@ func parseAst(source interface{}) interface{} {
87
88
88
89
switch head := arr [0 ].(type ) {
89
90
case string :
90
- if head == "'" {
91
+ if head == "'" { // escape parsing array
91
92
return arr [1 :]
92
93
} else {
93
94
var params []interface {}
94
95
95
96
for i := 1 ; i < len (arr ); i ++ {
96
- params = append (params , parseAst (arr [i ]))
97
+ params = append (params , ParseJsonObjectToAst (arr [i ]))
97
98
}
98
99
99
100
return FunNode {head , params }
@@ -106,6 +107,25 @@ func parseAst(source interface{}) interface{} {
106
107
}
107
108
}
108
109
110
+ // convert ast to source object
111
+ func ParseAstToJsonObject (ast interface {}) interface {} {
112
+ switch funNode := ast .(type ) {
113
+
114
+ case FunNode :
115
+ list := []interface {}{funNode .funName }
116
+ for _ , param := range funNode .params {
117
+ list = append (list , ParseAstToJsonObject (param ))
118
+ }
119
+ return list
120
+
121
+ case []interface {}:
122
+ return append ([]interface {}{"'" }, funNode ... )
123
+
124
+ default :
125
+ return funNode
126
+ }
127
+ }
128
+
109
129
// NewPcpServer merge sandbox with default sandbox
110
130
func NewPcpServer (sandbox * Sandbox ) * PcpServer {
111
131
return & PcpServer {sandbox }
0 commit comments