Repository navigation
Grammar fix - #5
Merged
Merged
Conversation
Collaborator
|
Thank you for the fix, merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm working on a static analyzer for circom and ran into a precedence issue in this grammar: array access (
a[i]) and member access (a.b) bind weaker than assignments and binary operators.array_access_expressionhas no precedence (it is 0), andmember_expressionusesprec.dynamic(1), which only breaks ties at runtime and doesn't resolve conflicts when the parser is generated. Assignments have 1 and binary operators 2–7, so when the parser sees[or.right after an operator, it closes the operation first and applies the access to the whole thing. For example,The tree today (each node shows the code it covers):
And it is read as
((div[k] <-- longdiv)[0])[k]. But it should be:The fix
Gave both rules the highest precedence
[$.member_expression, $._expression]fromconflicts; precedence resolves it now andtree-sitter generateflagged it as unnecessary.-
src/was regenerated with tree-sitter-cli 0.23.0, the same version the currentparser.cwas generated with, to keep the diff to what actually changed.Tests
Five corpus tests had the old, incorrect trees saved as their expected output, so I updated them with
tree-sitter test --update