Fix inconsistent conflict resolution for try
and ternary
#75
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.
In most places in the grammar, we rely on our conflicts resolving
themselves with only one parse interpretation being valid. With
try
andternary, that isn't the case: both of
try (foo() ? bar() : baz)
and(try foo()) ? bar() : baz
are valid. This matters becausebar()
could also be a
throws
function, and ourtry
is supposed to coverit.
The rules for dynamic precedence are described here:
tree-sitter/tree-sitter#678
Based on those, it seems like we were getting the correct parse result
in our test cases solely because of some rule definition order, which
"isn't really meant to be relied on." This exposes itself in some
unrelated changes for a custom string interpolation (not included in
this PR) where the rule order changes and flips our interpretation to
the wrong one.
Instead of relying on the ordering behavior, this change tells the
parser to choose
try (foo() ? ...)
over(try foo()) ? ...
by givingit a dynamic precedence value. This makes our ordering consistent even
in the face of later rule changes.