Repository navigation
Lexer location fixes and tests - #74
Merged
Merged
Conversation
The comment on Lexer::loc said the column was computed on demand, but it has been set eagerly for every token. Add a unit test pinning the Endl location and the deferred line advance introduced in #73. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The lexer only advanced the line counter for whitespace and comment newlines, so every token after a multi-line string literal reported the wrong line and a column measured from an earlier line. Replace the "previous token was Endl" check with a pending_lines counter that both the newline handler and the string scanner bump. The line advances when the next token is lexed, so the string token keeps the line of its opening quote. The parser's struct-literal backtrack now saves and restores the counter along with the rest of the lexer state. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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
Follow-up to #73.
tok == Endlcheck with apending_linescounter. Both the newline handler and the string scanner bump it, and the line advances when the next token is lexed. This removes the dependency ontokalways holding the previously returned token. The parser's struct-literal backtrack saves and restores the counter with the rest of the lexer state.Lexer::locclaimed the column was computed on demand. It is set eagerly for every token.test_token_locations, pinning theEndlposition at the newline on the line it ends, the deferred line advance across blank lines, the newline after a//comment, locations after a multi-line string, and whereEndlands after a trailing newline.Before, for a stray
}on line 5 after a two-line string:After:
Test plan
cargo test --workspacepasses (unit tests plus all four golden runners)rustfmt --checkclean on the touched files🤖 Generated with Claude Code