diff --git a/node.go b/node.go index 862ccc3..65f63c3 100644 --- a/node.go +++ b/node.go @@ -1490,6 +1490,17 @@ func (this *conversionState) convertBinaryCommon(left, right node.Node, goBinary rhs = "(" + rhs + ")" } + // We can elide even more parens in case of some commutative operators + // We can only do this in the left-associative case + // FIXME Plus and Concat aren't necessarily commutative together even though they both have + here(!!) + if _, ok := left.(*binary.Plus); ok && goBinaryOperator == `+` { + lhs = removeParens(lhs) + } + if _, ok := left.(*binary.Concat); ok && goBinaryOperator == `+` { + lhs = removeParens(lhs) + } + + // Done return "(" + lhs + " " + goBinaryOperator + " " + rhs + ")", nil }