Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix print with precedence #678

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

zhuliquan
Copy link
Contributor

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:

expr/ast/print.go

Lines 75 to 80 in 9713880

if lb.Operator == "??" {
lwrap = true
}
if operator.IsBoolean(lb.Operator) && n.Operator != lb.Operator {
lwrap = true
}

expr/ast/print.go

Lines 86 to 88 in 9713880

if operator.IsBoolean(rb.Operator) && n.Operator != rb.Operator {
rwrap = true
}

because, these code logical can be covered with the logical of precedence and associative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant