Repository navigation
fix(parser): end a column-0 # comment before the CRLF that follows it - #2773
Merged
Merged
Conversation
The comment token ran to the \n, so on a CRLF line it included the \r that the \r?\n Newline token also starts at. The two tokens overlapped by one byte: the CST text and lossless tokens came out one byte longer than the source, and the directive after the comment was reported as "top-level directive must start at column 0". bean-check accepts the same file. ; comments were never affected (their regex stops before \r). The comment now ends before the one \r the Newline token claims; extra \r bytes before it, and a lone \r at EOF, stay in the comment. Closes #2769 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
This was referenced Oct 28, 2026
Review follow-ups for the CRLF # comment fix: - Loader CACHE_VERSION 44 and WASM 59 (pin follows): the fix changes parser output. A file ending in a CRLF # comment parsed clean before, so it was cached with its last directive span one byte past the end of the file; the WASM cache also archives parse errors and would keep serving P0012. - CHANGELOG entry under Fixed. - Tests: a lexer unit test pinning the comment text and span (it ends where the Newline token starts); the in-bounds EOF span and comment value; the BOM-prefix and post-pushtag cases; try_format_source (what rledger format calls) now formats a CRLF # file like the LF one. All fail with the fix reverted. Test names follow test_<function>_<scenario>. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
What changed
TokenIter's column-0#comment arm (crates/rustledger-parser/src/logos_lexer.rs) now ends the comment before the one\rthat the followingNewlinetoken (\r?\n) claims. Extra\rbytes before it, and a lone\rat EOF (no\nfollows, so no newline token claims it), stay in the comment.CACHE_VERSION43 -> 44 and WASM 58 -> 59 (LOADER_CACHE_VERSION_PINfollows; fixture pins updated). This is a parser OUTPUT change with no archived layout move: a file ending in a CRLF#comment parsed clean before the fix, so the CLI cached it with its last directive's span one byte past the end of the file, and the WASM cache also archivesparse_errors, so a stale blob would keep serving P0012.### Fixed.Why
The comment span ran to the
\n, so on a CRLF line it included the\rthe newline token also starts at. The two tokens overlapped by one byte, so the CST text and the lossless token stream came out one byte longer than the source, and the directive after the comment failed withP0012 top-level directive must start at column 0.rledger checkreported a valid ledger as broken andrledger formatrefused to run, whilebean-check(beancount 3.2.3) accepts the same file. Beancount's own lexer treats a column-0#line as a comment (^[\*\:\#]/.skips the line) and\ras whitespace.;comments were never affected because their regex (;[^\n\r]*) stops before\r.How to test
cargo test -p rustledger-parser --test crlf_hash_commentandcargo test -p rustledger-parser --lib test_tokenize_lossless_hash_comment_ends_before_crlf. The tests cover:Newlinetoken starts (# note\r\ngives# noteat 0..6 and the newline at 6..8;# note\r\r\nkeeps one\rin the comment);parse_structured(..).text()and the concatenatedtokenize_losslessspans equal the source for#and;comments followed by\n,\r\n,\r\r\nand\r\r\r\n;parsereports no errors and both directives after a#comment with each of those endings (and;with\n/\r\n), after a BOM, and after apushtagline;#comment as the last line (with\r\n, with no ending, with a lone trailing\r), including that the last directive's span ends at the source length and the comment value has no\r;try_format_source(whatrledger formatcalls) formats a CRLF#file to the same output as the LF one.All 7 tests fail with the fix disabled. Parser, loader and WASM suites: 1200 passed, 0 failed; workspace clippy, docs (including private items) and fmt clean.
Reviewed in depth before merge: a ~307k-input differential (base vs this branch) found 0 token overlaps left (base: 4,689), no new lossless gaps, no panics, and CRLF results identical to the LF versions;
rledger checkandformatnow agree withbean-checkon every CRLF#case tried.Not in this PR
\rbefore the line ending elsewhere (after a directive line, or after a;comment, e.g.\r\r\n) is reported as "unexpected input", whilebean-checkaccepts it: fix(parser): a stray \r before the line ending is a parse error; bean-check accepts it #2774. The;control in the parse test is limited to\n/\r\nfor that reason."inside a column-0#comment silently drops the following directives (same lexer arm, pre-existing, worse): fix(parser): a " in a column-0 # comment silently drops the following directives #2775. The remaining lossless gaps in the differential all come from it.rledger formatdeletes#!/#+lines that follow a directive: fix(format): rledger format deletes #! and #+ lines that follow a directive #2776.Closes #2769
🤖 Generated with Claude Code