Repository navigation
fix(parser): read a lone capital glued to a string past its word as one invalid token, as beancount does - #2988
Merged
Merged
Conversation
…ne invalid token, as beancount does (#2977) A lone capital glued to a string or comment that reaches past its run of non-blank characters (A@"x with the string closing on a later line, T"x y", T;x y) is, with the run, one invalid token, as in beancount, so the quote opens no string and the next line lexes on its own. The dated window from #2979 now leaves a line alone only where the lexer still reads such a capital as a token of its own. WASM cache 121; the loader cache is unchanged (every changed source has a parse error before and after). Co-Authored-By: Claude Opus 5.5 <[email protected]>
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?
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
The check after a lone capital lexed a comment or string in its run to the token end, then threw it away when the run ended at a blank, so a line of A;x words was quadratic. It now decides from the run bytes whether a comment (; % #! #+) or a string reaches past the run, which also makes lines of A%x and A#!x words linear (quadratic on main too). A byte counter guards it. Tests for T%x y in the flag position and for a T( inside a string no longer ending #2979s dated window. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 15, 2026
Merged
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
A lone capital glued to a string or comment that reaches past its run of non-blank characters is now, with that run, one invalid token, as in beancount 3.2.3.
beancount lexes a lone capital only before a blank (
[A-Z]/[ \t\n]). Glued to anything else, its invalid token[^ \t\n\r]+takes the run up to the next blank, a quote or;included, so the quote opens no string and the;no comment, and the next line lexes on its own. Here the capital stayed a token whenever the rest of its run lexed (TokenIter::error_later_in_run), and a"lexed even when its string ran past a blank or onto later lines. So the string swallowed the lines after it:A@"x/foo"(the issue)T"x y" 1(after two opens)k: T"a b"(metadata)T"x/2024-01-03 open Assets:C/"2024-01-02 open Assets:C T;x y2024-01-02 T"x y"then two postingsHow
error_later_in_run,crates/rustledger-parser/src/logos_lexer.rs): a token that starts in the capital's run and ends past the run's end (a string with a blank or a line break inside, a comment) counts as an error in the run. The lexer handed back stands at the run's end, so the error is the run, as beancount's is, and lexing resumes at the blank. TheErrarm does not take it for a stray quote (its start is past the quote), so no line-at-a-time mode is entered. A string that closes inside the run (T"x") is unchanged: the capital stays a token, which the glued one-letter rules report, one error as in beancount.holds_a_lone_capital_glued_to_a_non_blank,crates/rustledger-parser/src/cst/convert.rs): fix(parser): a dated line that opens no directive is one error, as in beancount (#2979) #2985 left a line holding a capital glued to punctuation as main had it, because the lexer read that capital otherwise. It now asks the lexer, and applies only where the capital is still a token of its own. Where the run is now one invalid token, the line is an ordinary failed line:2024-01-02 T"x y"with postings is {3:2} as in beancount, where the postings would otherwise each get an error. This also stops it matching aT"inside a string.Caches
CACHE_VERSION120 to 121: both payloads archive parse errors, which move.Parse-error parity corpus (pinned fuzz 9bc79f4)
57 inputs newly match, 3 no longer do, and 27 mismatching inputs changed category.
--checkpasses with the updated manifest.The 3 lost (
10971147319b,97eb7bfdb11b,9f2a05fd77d0) each count exactly what main counts with an ordinary invalid token ($q) in place of the glued run, so the run now lexes as beancount's does and the difference is rledger's recovery on that line:qR:R"\r'"0...under a failed dated line: beancount's two invalid tokens,R"and'"0..., are now this PR's too, plus the grammar error rledger reports on such a line (3 against 2). Main matched because itsRand string covered the'.1114-2-13T%Ù\tK+:T%Ùis now one invalid token;K+(a capital glued to a+that lexes) is still two tokens here, compat(parser): a word like U~SD after an invalid token is one error fewer than beancount #2982's gap, so the line is 1 against beancount's 2.The 4 ledger2beancount files the local fetch reported as unpinned are upstream content changes, unrelated to this PR; their rows are left out of the manifest.
Generated differential
A generator of lone capitals (and controls: lowercase, two-letter,
USD, an account, a digit) glued to every ASCII punctuation character,\x11,€and a BOM; quotes closing on the line, past a blank, on a later line or never, several quotes,;, escaped quotes, tabs; in 10 contexts (column 0, after two opens, after a date, after a transaction's narration, a posting amount, a metadata value, anopen, a posting's account, aprice, a cost); followed by 0 to 3 lines with postings, metadata, quotes, directives, blank and comment lines; 15% CRLF, 20% without a final newline. Each changed input was also run through main with the glued run replaced by$q, an ordinary invalid token, which main lexes as beancount lexes the run.In this generator, every regressed, further and sideways input (777) counts exactly what main counts with
$qin place of the glued run. No crash. They fall in two families, both #2872's recovery, which main reached the same way only because the string swallowed the lines involved:359 have only the first, 302 only the second, and 116 both:
U*"\"/; c/Assets:B/"is beancount {1, 4}, this PR {1, 3, 4}, main {1, 4}.A+"#tin a posting, then a posting, then"and"x" "y": beancount {4, 7}, this PR {4, 6, 7}, main {4, 7}.Probes of the issue and the shapes above, 26 inputs: 16 gained, the rest unchanged.
The round-1 review's own generator (300,000 glued inputs and 60,000 controls, more fragments per input) measured 33,226 gained, 30,076 closer, 985 regressed, 2,480 further and 4,943 sideways; controls changed only where a real glued capital exists; no error-free input changed. All but 16 of its regressed, further and sideways inputs count what main counts with
$qin place of the run. 14 of those 16 are one shape, documented here and left as is: a mid-line BOM inside the glued run. The run is now one error token led by a capital, which gets the capital-led "Invalid account" reading and the BOM's ownBomInDirectiveBodybeside it, where$qgets neither:2024-01-01 open Assets:BthenJ;<BOM>Assets:A 1 USDis beancount {2:1}, main {2:1}, this PR {2:2};J"<BOM>Assets:A y"is beancount {1:2}, main {1:1}, this PR {1:3}.Speed
Linear. The check after a lone capital decides from the run's own bytes whether a comment (
;,%,#!,#+) or a string in the run reaches past it: a comment runs to its line break, so it does exactly when the run ends at a blank; a string does when no unescaped"closes it inside the run. It never lexes such a token to its end. (The first version did, and a line ofA;xwords was quadratic, 3.45 s at 80k; a line ofA%xorA#!xwords already was on main.)test_tokenize_lossless_lone_capital_lookahead_reads_no_token_past_its_runguards it with a byte counter.Seconds at 20k / 40k / 80k repetitions, main against this PR:
A@"x/foo"linesA"linesT"x y"on one lineA@"x, N postings, then"X;c dlines2024-01-02 T"x y"and a postingA@"x\" y"linesA;xon one line (and 160k)2024-01-01 open Assets:A+T;xon one line (and 160k)A%xon one line (and 160k)A#!xon one line (and 160k)A"xon one line (and 160k)A"x\on one line (and 160k)A"x"on one line (and 160k)How to test
Every expected count in
capital_glued_to_a_string.rswas checked against bean-check 3.2.3: the 15 sources of the main table, each also with CRLF, plus2024-01-02 T%x ywith postings ({3:2}) and2024-01-02 ~ "a T("with postings ({3:1}, where main reported each posting too: aT(inside a string no longer counts as a glued capital in #2979's dated window), each with CRLF too.Closes #2977
🤖 Generated with Claude Code