feat(parser): error reporting, API cleanup, and FOLLOW removal#45
Merged
Conversation
…ases Rule.follow, Rule.follow_built, Rule.calc_first, Rule.first, Rule.first_built, Rule.calc_follow, and compute_follow_sets are removed. Since T6 the LALR(1) lookahead table drives all reduce decisions; FOLLOW sets were no longer used. Phase numbering updated: old Phase 4→3, 5→4, 6→5. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ed_tokens Table.force_update renamed to Table.resolve_conflict to make the intent explicit: it is only called after a conflict has been decided, not for arbitrary table overwrites. Table.expected_tokens(state) is a new helper that returns the terminal classes with an action in a given state. It will be used by Parser.parse to populate ParsingError.expected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… ParsingError LexingError gains __init__(message, lineno, offset) and a __str__ that formats as "Line X, col Y: <message>". ParsingError gains __init__(message, token, lineno, offset, expected) and a matching __str__. Both errors use the same "Line X, col Y:" prefix so callers can parse error output uniformly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…d tokens Parser.parse now tracks last_token to carry position context into the end-of-input error. All three ParsingError raise sites pass the offending token (or None for EOF), lineno, offset, and the list of expected terminal classes for the current state. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Six tests cover: - ParsingError.token, .lineno, .offset, .expected on unexpected token - str(ParsingError) contains "Line X, col Y:" prefix and expected class name - ParsingError.expected is non-empty when input is truncated - LexingError.lineno, .offset, .message fields - str(LexingError) "Line X, col Y:" format Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove redundant issubclass in Table.expected_tokens (isinstance(sym, type) already narrows Symbol to type[Token]). Remove redundant isinstance in the case _ fallthrough (token is already Token at that point). Add GrammarEntry type alias to test_error_reporting.py so the GRAMMAR dict is fully typed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The LALR(1) implementation no longer uses FOLLOW sets; reduce actions fire on per-item lookaheads computed by ASU §9.6. Remove the SLR(1)-vs-LALR(1) comparison phrasing that mentioned FOLLOW. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace FOLLOW set computations and SLR(1)-vs-LALR(1) comparisons in the section header and two test docstrings with plain descriptions of the per-item lookahead behaviour. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…r_conflict Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…port No circular dependency exists between exception.py and token.py. 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 |
henrylee97
enabled auto-merge (squash)
May 12, 2026 14:45
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
Remove dead FOLLOW infrastructure:
compute_follow_sets,Rule.calc_follow,Rule.calc_first, and all related attributes are deleted. Since T6, LALR(1)per-item lookaheads drive all reduce decisions; FOLLOW sets are no longer needed.
Phase numbering updated (old 4→3, 5→4, 6→5).
TableAPI cleanup:force_updaterenamed toresolve_conflict(makes intentexplicit). New
Table.expected_tokens(state)helper returns the terminal classesvalid in a given state.
Structured exceptions:
LexingErrorandParsingErrornow carrylineno,offset, and (forParsingError) the offendingtokenand anexpectedlist ofvalid token classes. Both format as
"Line X, col Y: <message>".Parser.parsetracks
last_tokento provide position context even on end-of-input errors.FOLLOW references removed from docs/comments: All mentions of FOLLOW sets in
docstrings, comments, and test descriptions replaced with per-item lookahead
language. LALR(1)-only test functions renamed from
follow_inflationtoresolves_rr_conflict.Test plan
pytest -q— 38 passed, 0 xfailedpyright— 0 errorsblack --check .andisort --check .— cleantest_error_reporting.py— 6 new tests assertingParsingError/LexingErrorfield values and
str()format