expr icon indicating copy to clipboard operation
expr copied to clipboard

Fix print with precedence

Open zhuliquan opened this issue 1 year ago • 0 comments

consider the precedence of operators and their associative law when printing unary and binary nodes fix error expr print: 1、(-(1+1)) ** 2 => -(1 + 1) ** 2 2、(2 ** 2) ** 3 => 2 ** 2 ** 3 3、(3 + 5) / (5 % 3) => (3 + 5) / 5 % 3

Beside,I think should remove below code: https://github.com/expr-lang/expr/blob/971388017260b2241784c4ed216f8e6eb91ef7f5/ast/print.go#L75-L80 https://github.com/expr-lang/expr/blob/971388017260b2241784c4ed216f8e6eb91ef7f5/ast/print.go#L86-L88 because, these code logical can be covered with the logical of precedence and associative.

zhuliquan avatar Jun 26 '24 15:06 zhuliquan