Fix lexer column tracking - #803
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The changes directly address the described column-tracking defects and include targeted regression tests for both indentation and multibyte scenarios.
Pull request overview
This PR fixes incorrect lexer column reporting by computing columns as character offsets (not byte offsets) and by avoiding newline consumption as part of generic whitespace scanning, which previously caused indentation columns to be misreported after line breaks.
Changes:
- Compute
Lexer#columnas a character count from the current line start to the scanner position. - Scan
\nseparately from other whitespace so indentation after a newline doesn’t reset the line-start pointer incorrectly. - Add regression specs for indented trailing-whitespace lines and multibyte input.
File summaries
| File | Description |
|---|---|
| spec/lrama/lexer_spec.rb | Adds regression coverage for indentation-after-newline column reporting and multibyte character column offsets. |
| lib/lrama/lexer.rb | Updates column calculation and refines whitespace/newline scanning to preserve correct line-start tracking. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Lexer#columnusedStringScanner#posdirectly, causing columns after multibyte characters to be reported as byte offsets.Whitespace scanning also consumed newlines together with indentation from the following line. This moved the line-start position past the indentation and incorrectly reported column zero.
Calculate columns as character offsets and process newlines separately from other whitespace. Add regression coverage for indented lines with trailing whitespace and multibyte input.