The DSL builds an AST so all the information should be availabnle for deciding whether to insert parenthesis around lower precendence operators that occur as sub-expressions within higher precendene expressions, or equal precenence expressions but with the wrong direction of associativity.
The DSL builds an AST so all the information should be availabnle for deciding whether to insert parenthesis around lower precendence operators that occur as sub-expressions within higher precendene expressions, or equal precenence expressions but with the wrong direction of associativity.
So
Should render as:
(1 + 2) * 3
This logic would be put in the pretty printer, in the
adjustExpressionParentheses
function or possibly inprettyOperatorApplication
.Other cases where parens can automatically be inserted in expressions?