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

Fixed parsing precedence and associativity #391

Merged
merged 5 commits into from
Dec 1, 2020
Merged

Conversation

vallentin
Copy link
Collaborator

Fixes #381

This pull request fixes the parser, such that it produces a correct AST in relation to precedence and associativity.

As mentioned in the issue, given that Askama emits the expressions unmodified, then in that regard there isn't any noticeable change. However, with a correct AST it prevents any potential future problems.

In short a + b == c was previously parsed as (a + (b == c)) and now is correctly parsed as ((a + b) == c).

I also added a few test cases to check that the parser upholds precedence and associativity. (If you want the test cases split into multiple functions, then mention it and I'll split them.)

This does not introduce any breaking changes.

@djc
Copy link
Owner

djc commented Dec 1, 2020

Awesome, thanks for fixing this! I'll merge as soon as this passes CI.

@vallentin
Copy link
Collaborator Author

Fixing the issue.

@djc djc merged commit 266c606 into djc:main Dec 1, 2020
@vallentin vallentin deleted the associativity branch December 1, 2020 09:04
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.

The operator parser gets precedences wrong
2 participants