| 211 | } |
| 212 | |
| 213 | func (n *ConditionalNode) String() string { |
| 214 | if !n.Ternary { |
| 215 | cond := n.Cond.String() |
| 216 | exp1 := n.Exp1.String() |
| 217 | if c2, ok := n.Exp2.(*ConditionalNode); ok && !c2.Ternary { |
| 218 | return fmt.Sprintf("if %s { %s } else %s", cond, exp1, c2.String()) |
| 219 | } |
| 220 | exp2 := n.Exp2.String() |
| 221 | return fmt.Sprintf("if %s { %s } else { %s }", cond, exp1, exp2) |
| 222 | } |
| 223 | |
| 224 | var cond, exp1, exp2 string |
| 225 | if _, ok := n.Cond.(*ConditionalNode); ok { |
| 226 | cond = fmt.Sprintf("(%s)", n.Cond.String()) |
| 227 | } else { |
| 228 | cond = n.Cond.String() |
| 229 | } |
| 230 | if _, ok := n.Exp1.(*ConditionalNode); ok { |
| 231 | exp1 = fmt.Sprintf("(%s)", n.Exp1.String()) |
| 232 | } else { |
| 233 | exp1 = n.Exp1.String() |
| 234 | } |
| 235 | if _, ok := n.Exp2.(*ConditionalNode); ok { |
| 236 | exp2 = fmt.Sprintf("(%s)", n.Exp2.String()) |
| 237 | } else { |
| 238 | exp2 = n.Exp2.String() |
| 239 | } |
| 240 | return fmt.Sprintf("%s ? %s : %s", cond, exp1, exp2) |
| 241 | } |
| 242 | |
| 243 | func (n *ArrayNode) String() string { |
| 244 | nodes := make([]string, len(n.Nodes)) |