Skip to content

New location tracking Location, SpanManager#46

Merged
ehwan merged 26 commits into
mainfrom
new_location
Jun 17, 2026
Merged

New location tracking Location, SpanManager#46
ehwan merged 26 commits into
mainfrom
new_location

Conversation

@ehwan

@ehwan ehwan commented Jun 17, 2026

Copy link
Copy Markdown
Owner
  • New location system that is not depending on proc_macro2
  • Added unit tests
  • Fixed deterministic & nondeterministic context stack calculation bug

@ehwan ehwan self-assigned this Jun 17, 2026
@ehwan
ehwan requested a review from Copilot June 17, 2026 04:23

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the location tracking system across the codebase to use a new Location and SpanManager infrastructure instead of raw proc_macro2::Span or SpanPair. This change allows mapping byte ranges back to spans for more precise error reporting. Deterministic and non-deterministic parser contexts have been updated to pass Location directly rather than wrapping it in an Option, and error types now hold a non-optional Location. Additionally, the lexer, parser, grammar, and pattern modules have been updated to use Located<T> and Location. A minor issue was found in rusty_lr_core/src/parser/nondeterministic/context.rs where a doc comment is duplicated on consecutive lines.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread rusty_lr_core/src/parser/nondeterministic/context.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors RustyLR’s location tracking to use a new Location + SpanManager mechanism (index ranges into a collected span table) instead of the previous SpanPair approach, and updates parsing/error-reporting/codegen paths accordingly. It also adjusts deterministic/nondeterministic parser contexts to compute default locations more consistently (including EOF) and adds unit tests validating error recovery + EOF location behavior in the JSON example.

Changes:

  • Replace %location SpanPair with %location Location and introduce parser::location::{Location, Located, SpanManager} for mapping locations to spans/byte ranges.
  • Update grammar parsing, pattern/terminal-set handling, error types, and code emission to use Location/Located<T> throughout.
  • Fix context/tag-stack truncation logic and add bootstrap/test coverage (including JSON example unit tests).

Reviewed changes

Copilot reviewed 31 out of 32 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
scripts/diff/json.rs Regenerated JSON diff output reflecting new literal/terminal-set printing and userdata location capture.
scripts/diff/calculator.rs Regenerated calculator diff output; includes tag-stack handling fixes.
scripts/diff/calculator_u8.rs Regenerated u8 calculator diff output; includes naming + tag-stack truncation fixes.
scripts/bootstrap_test.sh Runs cargo test during bootstrap comparisons to validate generated output builds/tests.
rusty_lr_parser/src/utils.rs Switch helper utilities to the new Location/SpanManager-based identifier construction.
rusty_lr_parser/src/token.rs Replace proc-macro spans with Location and make mapto location-aware (Located<String>).
rusty_lr_parser/src/terminalset.rs Convert terminal-set AST to use Located<T> + Location for error reporting and ranges.
rusty_lr_parser/src/terminal_info.rs Make terminal identifiers string-based and store precedence with Located<usize>.
rusty_lr_parser/src/pattern.rs Update pattern lowering to use Location and typed literals (Byte/Char/String/...).
rusty_lr_parser/src/parser/span_pair.rs Removed old SpanPair location mechanism.
rusty_lr_parser/src/parser/parser.rs Update grammar parser rules/tokens to emit Location + typed literals.
rusty_lr_parser/src/parser/mod.rs Register new location module; drop span_pair module.
rusty_lr_parser/src/parser/location.rs New location system (Location, Located<T>, SpanManager) + unit tests.
rusty_lr_parser/src/parser/lexer.rs Collect spans into SpanManager and feed Location instead of SpanPair.
rusty_lr_parser/src/parser/args.rs Update grammar-arg structures to store Location/Located<T>; refine precedence/literal handling.
rusty_lr_parser/src/nonterminal_info.rs Store nonterminal names and rule metadata using Location/Located.
rusty_lr_parser/src/lib.rs Re-export Location for external consumers.
rusty_lr_parser/src/error.rs Refactor errors to use Location and emit diagnostics via SpanManager.
rusty_lr_parser/src/emit.rs Emit generated code using correct spans derived from SpanManager locations.
rusty_lr_parser/Cargo.toml Enable proc-macro2 span-locations feature to support byte-range mapping.
rusty_lr_derive/src/lib.rs Thread SpanManager through error emission in the proc-macro entrypoint.
rusty_lr_core/src/rule.rs Minor doc formatting change.
rusty_lr_core/src/parser/nondeterministic/error.rs Make parse error location non-optional.
rusty_lr_core/src/parser/nondeterministic/context.rs Compute default locations (incl. EOF) from stacks and align stack behavior.
rusty_lr_core/src/parser/deterministic/error.rs Make parse error location non-optional.
rusty_lr_core/src/parser/deterministic/context.rs Compute default locations from stacks and always push locations (incl. EOF).
rusty_lr_buildscript/src/utils.rs Remove old byte-range helpers now superseded by SpanManager.
rusty_lr_buildscript/src/lib.rs Switch diagnostics to use SpanManager for byte-range extraction from Location.
example/json/src/parser.rs Use userdata to capture recovered error locations instead of printing.
example/json/src/main.rs Pass userdata through parsing and add unit tests for success, recovery location, and EOF location.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rusty_lr_parser/src/parser/location.rs
Comment thread rusty_lr_parser/src/error.rs Outdated
Comment thread rusty_lr_parser/src/error.rs
Comment thread rusty_lr_parser/src/error.rs
@ehwan ehwan changed the title New location New location tracking Location, SpanManager Jun 17, 2026
ehwan and others added 4 commits June 17, 2026 13:29
@ehwan
ehwan merged commit c4ab229 into main Jun 17, 2026
1 check passed
@ehwan
ehwan deleted the new_location branch June 17, 2026 04:51
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.

3 participants