expr-lang / expr

Expression language and expression evaluation for Go
https://expr-lang.org
MIT License
6.35k stars 408 forks source link

Fix print with precedence #678

Open zhuliquan opened 5 months ago

zhuliquan commented 5 months ago

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.