9
9
)
10
10
11
11
// Dump an Ast node as a string
12
- func AstDump (ast Ast ) string {
12
+ func Dump (ast Ast ) string {
13
13
if ast == nil {
14
14
return "<nil>"
15
15
}
@@ -21,7 +21,18 @@ func AstDump(ast Ast) string {
21
21
fieldType := astType .Field (i )
22
22
fieldValue := astValue .Field (i )
23
23
fname := fieldType .Name
24
- if fieldValue .CanInterface () {
24
+ if fieldValue .Kind () == reflect .Slice {
25
+ strs := make ([]string , fieldValue .Len ())
26
+ for i := 0 ; i < fieldValue .Len (); i ++ {
27
+ element := fieldValue .Index (i )
28
+ if element .CanInterface () {
29
+ if x , ok := element .Interface ().(Ast ); ok {
30
+ strs [i ] = Dump (x )
31
+ }
32
+ }
33
+ }
34
+ args = append (args , fmt .Sprintf ("%s=[%s]" , fname , strings .Join (strs , "," )))
35
+ } else if fieldValue .CanInterface () {
25
36
v := fieldValue .Interface ()
26
37
switch x := v .(type ) {
27
38
case py.String :
@@ -32,7 +43,7 @@ func AstDump(ast Ast) string {
32
43
case SliceBase :
33
44
case Pos :
34
45
case Ast :
35
- args = append (args , fmt .Sprintf ("%s=%s" , fname , AstDump (x )))
46
+ args = append (args , fmt .Sprintf ("%s=%s" , fname , Dump (x )))
36
47
default :
37
48
args = append (args , fmt .Sprintf ("%s=%v" , fname , x ))
38
49
}
0 commit comments