@@ -58,17 +58,43 @@ func (n *UnaryNode) String() string {
58
58
}
59
59
60
60
func (n * BinaryNode ) String () string {
61
+ if n .Operator == ".." {
62
+ return fmt .Sprintf ("%s..%s" , n .Left , n .Right )
63
+ }
64
+
61
65
var lhs , rhs string
66
+ var lwrap , rwrap bool
62
67
63
68
lb , ok := n .Left .(* BinaryNode )
64
- if ok && (operator .Less (lb .Operator , n .Operator ) || lb .Operator == "??" ) {
69
+ if ok {
70
+ if operator .Less (lb .Operator , n .Operator ) {
71
+ lwrap = true
72
+ }
73
+ if lb .Operator == "??" {
74
+ lwrap = true
75
+ }
76
+ if operator .IsBoolean (lb .Operator ) && n .Operator != lb .Operator {
77
+ lwrap = true
78
+ }
79
+ }
80
+
81
+ rb , ok := n .Right .(* BinaryNode )
82
+ if ok {
83
+ if operator .Less (rb .Operator , n .Operator ) {
84
+ rwrap = true
85
+ }
86
+ if operator .IsBoolean (rb .Operator ) && n .Operator != rb .Operator {
87
+ rwrap = true
88
+ }
89
+ }
90
+
91
+ if lwrap {
65
92
lhs = fmt .Sprintf ("(%s)" , n .Left .String ())
66
93
} else {
67
94
lhs = n .Left .String ()
68
95
}
69
96
70
- rb , ok := n .Right .(* BinaryNode )
71
- if ok && operator .Less (rb .Operator , n .Operator ) {
97
+ if rwrap {
72
98
rhs = fmt .Sprintf ("(%s)" , n .Right .String ())
73
99
} else {
74
100
rhs = n .Right .String ()
@@ -132,7 +158,7 @@ func (n *ClosureNode) String() string {
132
158
}
133
159
134
160
func (n * PointerNode ) String () string {
135
- return "#"
161
+ return fmt . Sprintf ( "#%s" , n . Name )
136
162
}
137
163
138
164
func (n * VariableDeclaratorNode ) String () string {
0 commit comments