fix(token): default associative "right" to match yacc/bison shift-first behavior#48
Merged
Merged
Conversation
Without an explicit precedence declaration, S/R conflicts now resolve to shift (matching yacc/bison behavior) instead of reduce. Previously the "left" default caused reduce to always win at precedence 0, which made the dangling-else attach to the outer if instead of the inner one. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add explicit associative="left" to PLUS_SR so the left-associativity test continues to pass under the new "right" default - Update Section 2 header and docstring to reflect that left-assoc now requires an explicit declaration rather than being the default - Remove @pytest.mark.xfail from test_dangling_else_inner_if_gets_else; else now correctly binds to the inner if (shift wins at precedence 0) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pytest ReportTest Results
Comment by ✨sambyeol/publish-pytest-action |
Pytest ReportTest Results
Comment by ✨sambyeol/publish-pytest-action |
Super-linter summary
All files and directories linted successfully For more information, see the GitHub Actions workflow run Powered by Super-linter |
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.
Summary
Token.associativedefault changed from"left"to"right"to shift (matching yacc/bison behavior) instead of reduce
if c1 then if c2 then s1 else s2now correctly produces
IfThenD(c1, IfThenElseD(c2, s1, s2))Root Cause
The S/R conflict resolution condition in
parser.py:With the old
"left"default, the second branch was always true atprecedence 0, so reduce always won — contradicting yacc/bison, which
defaults to shift when no declaration is present.
Migration
Grammars that relied on the implicit left-associativity of undeclared
tokens must now add an explicit
associative = "left"to their tokenclass (as done for
PLUS_SRin the test suite).Test Plan
test_dangling_else_inner_if_gets_else— xfail removed, now passestest_default_sr_conflict_is_left_associative— still passes with explicitassociative = "left"onPLUS_SR