Skip to content

fix(parser): run a mid-line BOM's invalid token to the next blank, as beancount does - #2931

Merged
robcohen merged 41 commits into
mainfrom
fix/bom-run-extent
Nov 13, 2026
Merged

robcohen merged 41 commits into
mainfrom
fix/bom-run-extent

Conversation

@robcohen

@robcohen robcohen commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

What

Part 1 of #2928. A BOM-led invalid token keeps its own extent only where a BOM starts its line. In the middle of a line it runs to the next space, tab or line ending, as beancount's <INVALID>[^ \t\n\r]+ does. So the quote, #! or #+ after a mid-line BOM no longer starts a token of its own.

  • Lexer (logos_lexer.rs):
    • The Err arm keeps a BOM's own extent only when at_line_start && span.start == last_newline_end.
    • error_later_in_run no longer stops at a BOM. A run that goes on after a lone capital is never at line start, so A<BOM>"x" is one error token.
  • CST recovery (cst/convert.rs, cst/green.rs):
    • Three places used to treat every BOM-led error token as layout: report_invalid_tokens_of_error_line, quiet_after_invalid_tokens and holds_an_invalid_token.
    • A BOM that starts its line keeps its own extent, and is_line_start_bom_token tells it apart from a mid-line one. It looks only at the character before the token, so it costs the same however long the token is.
    • Only report_invalid_tokens_of_error_line asks that rule. A line-start BOM is always on an ERROR_NODE line, so holds_an_invalid_token (which walks an open or a transaction) never meets one. quiet_after_invalid_tokens counts it as its line's first invalid token, as beancount does, which changes no output (review round 15).
    • holds_an_invalid_token now walks tokens in source order, so a token of BOMs alone is followed by the token after it.
    • A mid-line BOM-led run counts as the invalid token it is. Without this, merging the BOM into the token lost that token's own error: 313<BOM>x was 1 error where bean-check reports 2.
    • When the line's primary error is another kind (an invalid account), the secondary BomInDirectiveBody stands for the line's first BOM-led token, so that token is not counted twice.
  • Unchanged rules:
  • Caches:

Why

At the start of a line the own extent keeps layout transparent: the directive of a concatenated file after a BOM still lexes, under one P0026. In the middle of a line it does nothing for layout, and it splits one beancount token into two or more. That makes an extra error for <BOM>#!d, <BOM>#+x, <BOM><BOM>"x" and <BOM>abc, and it let a quote after a BOM open a string.

Before / after (bean-check 3.2.3, full output)

The error counts are parse errors, from rledger check on main (68 / 90) and on this branch. Each case is two open lines followed by the line shown.

Shape bean-check 3.2.3 main this PR
file-start BOM 1 (Invalid token: '2024-01-01') 0 (stripped; deliberate) 0 (unchanged)
<BOM>2024-01-02 open ... (line start) 1 1 P0026 1 P0026 (unchanged)
two BOMs at line start 1 1 1 (unchanged)
<BOM> Assets:A 1 USD (BOM before indentation) 1 2 (P0026 + next posting) 2 (unchanged, pre-existing)
<BOM>Assets:A 1 USD (BOM in indentation, in a transaction with Assets:B -1 USD) 1 (Invalid account name: <BOM>Assets:A, a parse error), then Invalid reference to unknown account P0012 + P0026, then E3004, E3001 P0026, then E3004, E3001
2024-01-02 * <BOM>"x" 1 Invalid token: '"x"' 1, but the quote opened a string and x was kept as the narration 1, and the quote is part of the token
2024-01-02 * "x" <BOM>#!d 1 2 1
2024-01-02 * "x" <BOM>#+x 1 2 1
2024-01-02 * "x" x<BOM>"y" 1 1 1
2024-01-02 * <BOM><BOM>"x" 1 2 1
2024-01-02 * "x" <BOM>abc 1 2 1
2024-01-02 * "a<BOM>b" (BOM in string) 0 0 0 (unchanged, #2926)
313<BOM>x 2 2 2
2024-01-01 open Assets:A USD "BAD" <BOM>x 1 2 1

Known change vs main: a BOM before a price or cost (#2954)

A BOM right before a posting's price or cost now loses that price or cost. Each case is two open lines, then 2024-01-02 * "x" with Assets:A 1 HOOL <tail> and Assets:B -2 USD:

<tail> bean-check 3.2.3 main this PR
<BOM>@ 2 USD 1 1 3 (P0026, then E3001 twice: residual 1 HOOL, residual -2 USD)
<BOM>@@ 2 USD 1 1 3 (same)
<BOM>{2 USD} 1 1 3 (same)
HOOL<BOM>@ 2 USD, <BOM>@@, <BOM>{2 USD}, glued to the currency (round 21) 1 1 3 (same; the parse error alone was 2 before round 21)

The BOM's run now takes the @ or {, as beancount's invalid token does, and recovery keeps the posting without its price or cost, so the transaction no longer balances. Main already does this after any other invalid character (\x11{2 USD}). By the maintainer's decision it is fixed separately, in #2954. test_parse_bom_before_price_or_cost_drops_it_issue_2954 pins the current output and names #2954, so that fix must update it on purpose. The CHANGELOG entry says so too.

Parse-error parity

compat-parse-error-parity.py --check at the pinned fuzz commit 9bc79f4f:

  • Matching inputs after round 9: 78,461 of 111,323, up from 78,225 on main (78,306 in round 0, 78,367 in round 1, 78,399 in rounds 2 and 3, 78,461 in rounds 4 and 5, 78,460 in rounds 6 to 8).
  • Round 0 against main: 85 inputs newly match, 4 regress, and 108 mismatches changed category. Round 1 adds 61 more matches and 0 regressions (see "Review round 1").
  • Every changed row up to round 20 is a fuzz input. Round 21 adds 78,478: 17 matrix rows newly match (an invalid token glued to a balance's number before ~, or inside a posting's arithmetic), so their pins are dropped. tracked and compat are unchanged.
  • The manifest is updated with --update. The changed rows are listed below.

The lexer change alone made 52 inputs match and 21 regress (the prototype measured 48 and 16 against an older main). Then I traced the regressions:

  • All 21 had the same cause. The CST recovery skipped every BOM-led error token as layout. Once the BOM merged into the token, that token's own Invalid token error vanished:
    • its per-token report was skipped (report_invalid_tokens_of_error_line);
    • an error starting at it was dropped as "after an invalid token" (quiet_after_invalid_tokens).
      On main, the split-off rest of the token (x after <BOM>) carried that error by accident. None of the 21 is part 2: a #! or #+ appears only inside an invalid run there, never as a mid-line token.
  • All 21 are fixed by the CST rule above, which is in scope and small.
  • Counting the BOM-led token added 9 regressions. Five were a double count: the line's secondary BomInDirectiveBody already stood for that token. The secondary-BOM rule fixed those five.
  • 4 remain. None belongs to part 2. On main, the BOM-led token's missing error happened to offset a different, pre-existing extra error. Each one reproduces on main with \x11 in place of the BOM:
Input Cause
fuzz_green_eq_red/e12a04af... (1c622c0ec38b) A stray mid-line \r is an error here and a space in beancount. This is deliberately stricter (see stray_cr_trivia_end). The lone mid-line <BOM> is now correctly reported, so the extra \r error shows.
fuzz_green_eq_red/30086eb8... (31751db8eeca) Same \r cause, three stray \r on one line.
fuzz_green_eq_red/09638cc2... (50cf239632e8) Same \r cause: ...7\r<BOM>\n.
fuzz_parse/ee342d5d... (c1ad7a224d1d) 2<BOM>?02 on the last line, with no trailing newline. beancount reports no grammar error there; rledger's readable_start_of_an_error_line assumes one. Same on main for 2\x11?02.

I also measured a broader rule that reports every token holding a BOM, including ones with the BOM in the middle. It reaches 78,485 matching inputs, but it changes 640 rows and regresses 97 more. That is outside this part's scope; it would be a follow-up.

Changed manifest rows (197)

Newly matching (85), each fuzz, was:

  • lexer-token-split (45): 00bff79e00c2 0a4412765569 29327951290d 2eec4b6b1066 436ccf4aaf86 489840f9da40 499892e6701c 5d92e53e7cb3 5f4b321109cf 6094f18ce0a0 60967e88f654 6d6498e373da 6f5c1e1a22e1 70af62b6b80c 773af97fe525 77f4dc79b08a 79e796c2f635 8129f1f74ec9 827022265322 82bbbe7082b5 8e4ac280c6f4 9cf8e527af5b a8e6d3485866 b3e2e15e2f29 bc080f33dce9 c8e376ef9566 dae6b8127fc3 de6a4c9d70c9 e00fe268c0b6 e33ba04c68d2 e7d4ea695c1f e83ea93a3b5d e94b1632bf3e e9bc7b54e5f4 ea3cc1cbb387 ee775fd6ca82 ef604305392b f25486dac7a8 f4b5b81417f5 f5bff14ef8c6 f80e8e9dfc0f f91e1a7977a2 fb662b631e49 fd977a96665a fd985dd987a0
  • lexer-tokens-merged (34): 052e8df57237 06aa84858d93 09ed99ac3104 0c6c4c30dcbb 0ee989902457 12fee2c23ef7 1d447878aa20 2db18a3f58be 37c5b8d62a0c 45f03e75e033 48143d8808bb 5bf0d0ffe539 6e25dee8b48a 7576f439476e 80b4f5b06708 849286c169ae 8ed73afd7272 907cf8e3b3d3 969c7bfe75d5 a208b3588c0b a3d57fc9d089 ae18aec3ec5c aed6e4978392 b0074bd491eb b6a8766ca2d3 becbfe50174e c3f08eb81fa7 cf30e1693387 d36d9b92fa09 dc7fb3abe0e6 e9c9bfc830ed eee379a457ef f6c480009fbf fbc119b3165c
  • more-on-line (6): 1c1a98601857 5d5b977d59e9 843ae81b28c0 9d5484f61dc4 dfab5ad5342f f9dc4e5b47b4

Recategorized mismatches (108), each fuzz:

  • lexer-token-split to lexer-tokens-merged (26): 1158adc29149 1381daa79f1f 1c2449827fa3 27638e950342 29491c325d07 453523b63b15 7a36fce2798a 7abc598e2416 804d9dfd2d4d 8120079b0e28 86e68ae5bf70 9b2f1475b5b2 9bded2eea40d a3fa0b6b23af b7077e6df3dd bdac17d7856c be8087979eb6 ca617e441a3f cbaf9819143e daf4cd32d74b db15a6682346 db41fd554476 e31fab0005cb e7dd4486909a eaa3c4e387ea f423c93142a8
  • lexer-token-split to more-on-line (1): d52de8e8a912
  • lexer-token-split to rl-indented-line (64): 0473ca666708 12543bd1c639 13cd74b50283 1496a74f235e 272d6a0393c1 2f78e45f0d6c 31d3c570ed40 3211fd1eb90f 328cd9e3fa89 334a85e60a0c 346b801a73bf 34874d1f1974 35ca29e30049 3791245e5531 3d5ce380df92 3ea7ecf06fa2 40725296503b 431f6b6def05 4488494b7172 4ccfc041a0b1 4d7a3bcb8fd3 4e6d32399684 60f828411bd8 64bef92afdf2 68f7edeaf965 6b9b77b1830f 6c1a5e5cee6e 6e6ef32ddc25 7580ca7d88aa 75ff0e0fca49 7f79be80cf96 8a5128a2888d 8b9f2480fb1c 8c4204fdfc12 8d060ae44380 8fa4bdfc0e6c 90f877ec3024 91bcea98b61a 9609441fd6f6 97003fbfcfa8 9768507e8d8a 9978ff2c4d82 a17eee5a750d a27b20f0b7fa a4df784c7c43 a7ba71bdfafa a9c982f622f0 aaddf79a2e85 ab8ca73a43ea ae7c6bf00e8a b5689fbe139e b5b4bd1986e1 b82359f3c216 c27c97a51265 ca9b340bcd4f d15ec77bb761 d9ea47088ea2 edf73b46d815 f0bf508d5b7a f3af83130021 f5201670fb1a f5e20b556e79 f7a15f80272e ffe0ec6ed399
  • lexer-token-split to rl-top-level-line (1): 7ee3ab67507b
  • lexer-tokens-merged to lexer-token-split (8): 01283cce0de0 0f4f2a7e4876 1b981a834b98 6e40212a8779 94b216c154b8 c447a18bbc64 c7e5825f971e e1415bc92edd
  • lexer-tokens-merged to rl-top-level-line (2): 2e1a2755a94c 9a0736d1ca77
  • more-on-line to lexer-token-split (3): 40f6d82e3e43 4b59f9a08e2d 872c5b5c9629
  • rl-indented-line to lexer-token-split (1): 7ae55f67a8ae
  • rl-misses-line to lexer-tokens-merged (1): 5502dcdbaeb7
  • rl-top-level-line to lexer-tokens-merged (1): 7f0ea757e7b5

Regressed (4), each fuzz: 1c622c0ec38b (now lexer-token-split) 31751db8eeca (now more-on-line) 50cf239632e8 (now more-on-line) c1ad7a224d1d (now lexer-token-split)

Green / red

  • fuzz_green_eq_red regressions and green_red_properties pass.
  • I also ran a one-off green-equals-red check (directives, errors, comments) over all 44,589 inputs of the pinned fuzz corpus. All agree.
  • The new integration tests parse both paths and require identical payloads.

Review round 1

1. A BOM-led token in a directive's argument or account gave 2 errors (main 1, bean-check 1). Fixed.

  • Cause: when the header grammar first fails at the BOM-led token, the converter drops the directive with a generic line P0012, and the token's inline P0026 also survives. drop_errors_inside_a_line_error only merged SyntaxErrors.
  • Fix: that function now also takes an inline BomInDirectiveBody as an inner error. When the header grammar first fails at that token (grammar_failures, the same check that merges 2024-01-01 open Ass'ets:A), it drops the inner error. The line error then takes the BOM kind and hint.
    • The line error is kept rather than the inner one because the formatter's verbatim-copy ranges are read from the outer errors.
    • This runs in the shared finalization, so both walks get the same result. No new rule was added.
  • Result: one P0026 for each of these, as on main:
    • balance (amount and currency positions);
    • price (both currencies);
    • commodity;
    • note / event / document / custom / query with a BOM before a string;
    • the account position of open (space and tab), close, pad (both accounts), balance and note.
      is_stray_bom_at still finds each BOM.
  • Tests:
    • test_parse_bom_led_argument_of_directive_is_one_error covers all of the above and checks the loaded directives.
    • test_load_included_file_with_mid_line_bom_reports_one_error is the included-file case: one P0026 in child.beancount, and the surrounding directives load.
    • test_parse_bom_led_run_stops_at_blank_inside_quotes pins that query "q" <BOM>"select 1" is 2 errors. bean-check also reports 2, since its run stops at the blank.

2. The secondary-BOM rule could swallow a real error. Fixed.

  • The first token with a stray BOM consumes the flag, whether the BOM leads it or sits inside it.
  • Ü:A x<BOM>y <BOM>z is now 3 errors, matching bean-check and main.
  • Test: test_parse_secondary_bom_error_stands_for_first_bom_token_of_either_kind.

3. Transaction headers with an invalid token where a string belongs. Out of scope here; tracked in #2932.

This is the existing recovery model for every invalid token, not something new to BOMs. On main, the same code path already gives:

Header main (any invalid token, e.g. \x11) this PR, <BOM>
* \x11"x" / * <BOM>"x" kept, narration "" kept, narration ""
* "p" \x11"y" / * "p" <BOM>"y" kept, payee none, narration "p" same
* "p" \x11 kept, narration "p" n/a

The PR makes BOM-led tokens behave like every other invalid token here. Changing it means dropping any transaction whose header holds an invalid token. That conflicts with the documented recovery policy: rledger keeps the entry under its error-recovery policy (see report_duplicate_metadata), and test_parse_reports_no_booking_method_with_an_invalid_token_on_a_metadata_line asserts the directive is kept. It is a separate change across the parser, now tracked in #2932.

Nits

Parity in round 1

  • --check passes after an --update.
  • 61 inputs newly match. All are fuzz inputs where the directive's line error and the BOM token's error were both counted.
  • 5 mismatches changed category; their first differing line moved to a pre-existing difference.
  • 0 regressions. The same 4 pre-existing ones remain.
  • STRICT corpus and CST baselines pass.
Round-1 changed manifest rows (66)
  • lexer-token-split to lexer-tokens-merged (1): 443bc94d6c76
  • lexer-token-split to match (60): 03acb0aeac9d 0599ea4acdad 11e908578421 1eac62ce4a28 1fe24a05d1c4 2038e8769d60 2042401a006f 258ff6360f10 2b23d2b6b974 2f3ccd694467 2fa154334bd8 424f68d57ff1 464afdb789d2 494b3030da57 4a484b0974e7 4e870a62785b 510af458d74b 51dbe39f5e92 561668ba9e9f 5b065aad0237 60ce9d5387af 67e9345292f5 7245d692c532 748497374e7a 75bf807f6b74 75eaec0aa9b0 7606850727fb 771b513cbb6e 78a1a7d4e22b 7a0976af058a 7a4e701d2f70 874175155924 8c5656195cb7 90ca025a7859 92b9a89d8db6 937afaec0e0d 9e46603298d9 a01dfeea0b78 a5815aba6b71 a73b9eae421b aa0801291abe ac20a7874c8c af7b2f3e197e b43b9364f06d b5dee0f8d2c0 b6ce2c29d779 c65251203ea2 cbd17ea1c45e cc3293bcfeac ce1a5977c444 d3ce2bd9ec93 d4964befb162 d5a444bbbe8b d5ed47874216 e3a54ce4fc26 f000c1326f3e f125caa712f7 f41f0ba2f9f5 f4e6ce62b0db fdd701707444
  • lexer-token-split to rl-indented-line (1): cbd2aae7977f
  • lexer-token-split to rl-top-level-line (3): 1c49750d2569 d081dbe1aaf4 d964ffbd235b
  • more-on-line to match (1): 1b7174eb2559

Review round 2

1. The merged P0026 was reported over the whole directive. Fixed.

  • In drop_errors_inside_a_line_error, when the header grammar first fails at a BOM-led token, the token's own BomInDirectiveBody is now kept and the generic whole-node error is dropped. Round 1 did the reverse: it kept the generic error and renamed it.
  • So the error has the token's kind, hint and span, BOM to the next blank. price USD 1 <BOM>EUR on line 5 reports at 5:24, where main also reports it.
  • The formatter still copies the directive verbatim, metadata lines included. Its verbatim test is "any error range overlaps the top-level node", and the token lies inside the node.
  • This runs in the shared finalization, so green and red stay identical.
  • Tests:
    • test_parse_bom_led_argument_error_is_at_the_token pins span, line and column for price, commodity, balance and note, plus a price and an event with metadata lines.
    • test_format_source_keeps_directive_with_bom_led_argument.
    • LSP: test_parse_errors_to_diagnostics_bom_led_argument_ranges_over_the_token checks that the diagnostic range equals the BOM token.

2. A BOM-led token before an inner-BOM token still dropped an error. Fixed with the suggested change.

  • had_secondary: inner-BOM tokens are left to the BOM diagnostic only when that diagnostic is the line's primary error.
  • Ü:A <BOM>z x<BOM>y (3), Ü:A <BOM>a x<BOM>y <BOM>z (4), Ü:A x<BOM>y z<BOM>w (3) and Ü:A <BOM>a <BOM>b (3) all match bean-check. The last two were 2 and 4 on main.
  • Test: test_parse_secondary_bom_error_with_several_bom_tokens.

The 3 regressions the suggested change caused:

Input Cause Status
fuzz_parse/c2fe8dcc... (0098545b393f) The line starts with a BOM glued to an invalid run (<BOM>tApoptA...), which beancount reads as one invalid token that starts the line. report_invalid_tokens_of_error_line took the line-start BOM token as the line's first invalid token, so the run after it never counted as the one the line error stands for. Fixed (cheap): the first-token check now skips line-start BOM tokens and trims them from the prefix. Test: test_parse_line_start_bom_glued_to_invalid_run_is_one_error.
fuzz_green_eq_red/bf85c694... (441740b7ea14) Pre-existing. The second line is an indented account (R:Rꦝ...). It comes right after a line beancount could not read, and bison is still recovering there, so beancount reports no grammar error for it. rledger's line error (here P0006) counts as that grammar error. On main and in round 1, the skipped inner-BOM token offset the extra error by accident. Remaining. Recovery-state estimation is #2872 territory.
fuzz_parse/09ae2404... (7f5ab8dfd98e) Pre-existing, the same cause, plus three stray mid-line \r errors (stricter on purpose). Remaining.

Parity in round 2

  • 78,399 of 111,323 match: 78,367 in round 1, 78,225 on main.
  • Against round 1: 34 new matches (24 from the round-2 counting change, 10 from the line-start fix), 2 regressions (the two above), 21 mismatches changed category.
  • Against main in total: 180 new matches and 6 regressions. The 6 are the 4 from round 0 and the 2 above, all pre-existing causes.
  • --check passes after an --update.
  • STRICT corpus and CST baselines pass.
  • Green and red agree on the whole pinned fuzz corpus.
Round-2 changed manifest rows (57)
  • lexer-token-split to lexer-tokens-merged (1): e8844718a38e
  • lexer-token-split to match (10): 036051335d4b 16ab138dfd5f 491291571096 52a0c792ec64 866909c6e517 9a7db77e5488 a6c0a8f87d41 dd804649bb66 e61fb64bccc3 fc9f1bd4c97d
  • lexer-tokens-merged to lexer-token-split (20): 0b419c04c43a 1381daa79f1f 17b545306a80 27638e950342 3d783ba37847 44fc5614a263 453523b63b15 48d5cd4aedb3 7ff14715f27b 804d9dfd2d4d 8120079b0e28 86e68ae5bf70 9f66f36e422d a3fa0b6b23af a9bcf4c5b851 bae66d5fe2d6 e31fab0005cb e7dd4486909a f423c93142a8 f4c90421d552
  • lexer-tokens-merged to match (24): 1a01923bcf87 20b10d01c58c 2efe8b1053ce 3f279815a119 47d0634fdbe3 559af3dda56b 5602e8a8a1c7 5b8fd5eb2267 615176dafa93 6d0f54d33263 717fe293a31d 77dc7e3365e2 79653e955fbe 8b4ab29c1c48 90d465ff7940 91216601b71c 96e0cceacc16 aa7734c9d07c b26419f2f1e1 b82b7b3d8e04 ca6869a0c663 cb81186cb729 d40d88fbfb9d e7006002de8a
  • match to lexer-token-split (2): 441740b7ea14 7f5ab8dfd98e

Review round 3

1. A line-start BOM glued to a run, then an inner-BOM token, lost an error. Fixed.

  • A BOM that starts its line keeps its own extent here, where beancount's invalid token runs on through whatever is glued to it. So report_invalid_tokens_of_error_line now treats it as the line's first invalid token, the one the line error stands for:

    • an invalid run glued to it (<BOM>foo) is part of that token;
    • a run that only follows it (<BOM> k:) is one more token.
  • Once the line's BOM diagnostic stands for that BOM, a run with a BOM inside it later on the line gets its own error. This is the reviewer's suggested rule, generalised so that it also covers a BOM followed by a blank.

  • These now match bean-check (and main):

    Input bean-check
    <BOM>foo x<BOM>y 2
    <BOM>tApo x<BOM>y 2
    <BOM>$x x<BOM>y 2
    <BOM>foo <BOM>a x<BOM>y 3
  • Test: test_parse_line_start_glued_bom_then_inner_bom_token_counts_both.

2. A BOM before a metadata line's indentation lost an error. Fixed by the same rule.

  • <BOM> k: Ü:A <BOM>a0 x<BOM>y1 is 4 and <BOM> k: Ü:A x<BOM>y0 is 3, as in bean-check and main.
  • Round 2 had taken k: as the line's first invalid token. In beancount it is the <BOM> itself, which a blank follows, so k: is one more token.
  • Test: test_parse_bom_before_metadata_indentation_counts_the_key.

Guard: tests/bom_combination_matrix.rs.

  • scripts/bom-combination-matrix.py records beancount 3.2.3's per-line parse-error counts into tests/data/bom_combination_matrix.tsv. It uses the parity harness's filtering. The table covers 1,078 inputs:
    • every combination of 0 to 3 tokens: BOM-led <BOM>a, inner-BOM x<BOM>y, plain invalid $n;
    • three line-start prefixes: none, <BOM> glued to the line, <BOM>g (glued to a run);
    • nine contexts: alone, after an invalid account, after an invalid token, after a number, transaction header, posting, metadata line, metadata line with an invalid account, directive header.
      The prefix goes before the indentation of an indented line.
  • The test checks every row on both parse paths, which must agree. It runs in about 0.6 s.
  • The 386 inputs that still differ are listed in tests/data/bom_combination_matrix_known.tsv, each with rledger's counts and one of three causes. The causes are named and commented in CAUSES.
  • A known input that changes, for better or worse, fails the test, so the list cannot go stale.
  • I checked that the guard fails on the round-2 code: 374 inputs flagged.

The three known causes

All three predate #2928. On main, each of the 386 inputs differed from beancount by as much or more. 200 of them are closer to beancount than on main; none is further.

Cause Inputs What happens
orphan-lines 320 A line that starts with a BOM breaks its transaction. rledger reports each indented line after it; beancount's recovery skips them in silence (#2872). This includes shape 4 of the round-0 table.
inner-bom-under-line-error 62 A run with a BOM inside it, on a line whose BOM diagnostic already stands for the line's first error (foo x<BOM>y), is left to that diagnostic. That is one error fewer than beancount; main is the same.
account-after-invalid-token 12 An invalid account after the line's first invalid token is still reported. beancount reports nothing more for the statement (#2872).

Eight inputs carry both orphan-lines and account-after-invalid-token, which is why the counts add up to more than 386.

I measured a fix for inner-bom-under-line-error: report every inner-BOM token. It fixes 62 more matrix rows and 248 more fuzz inputs, but it turns 88 matching fuzz inputs into mismatches, each a difference the old count happened to offset. I left it for a change of its own.

Nit: CRLF. In query "q" <BOM>"select 1" with CRLF line endings and metadata after it, the \r after the second " stays inside the string after formatting. Since round 0, that quote opens a string across the CRLF, as in beancount. Known, not changed.

Parity in round 3

  • Still 78,399 of 111,323.
  • One mismatch changed category: e8844718a38e. Its <BOM> Ra line now matches beancount (2), so its first differing line moved to a pre-existing posting-line difference. The manifest is updated for it.
  • --check passes. STRICT baselines pass.

Merge. I merged origin/main (#2927, query crate only) with a plain merge and kept both CHANGELOG Fixed entries. No rebase, no force-push.

Review round 4

1. A BOM-led first token after a date or indentation did not spend the BOM diagnostic. Fixed.

  • When the line error stands for the line's first invalid token and that token starts with a BOM, later runs with a BOM inside them now get their own error.

  • These now match bean-check:

    Input bean-check
    2024-01-02 <BOM>a x<BOM>y 2
    the same with a tab or two spaces after the date 2
    2024-01-02 <BOM>a x<BOM>y x<BOM>z 3
  • A related gap showed up on indented lines inside a transaction. <BOM>a gave the posting line's generic error plus the token's P0026, which is 2 where bean-check reports 1.

    • drop_errors_inside_a_line_error now applies the same "the line's grammar fails first at this token" check to an inner BOM error that it applies to a generic one: the header case from round 1, plus an indented line whose start before the token beancount reads.
    • The generic line error is then dropped for the token's P0026.
    • This also fixes the nit: <BOM>; c is 2, as in bean-check.
    • <BOM>a x<BOM>y is 2.
  • I measured the broader variant you mentioned (spend the diagnostic for any first token that holds a BOM). It gains 11 more fuzz inputs but loses 7, so I kept the BOM-led condition.

  • Test: test_parse_bom_led_first_token_spends_the_bom_diagnostic.

2. A line-start BOM glued through valid tokens to an invalid one was counted twice. Fixed.

  • Every invalid token in the same blank-free run as the BOMs that start the line is part of the BOM's token. The check is that the text between the BOMs' end and the token holds no space or tab.
  • One exception: the unread rest of a <BOM>* heading line holds a blank. That token reaches past the run, so it is still reported.
    • The fuzz corpus caught this: <BOM><BOM><BOM><BOM>*7 Z# is 2 in bean-check, and the first version of the fix gave 1.
  • <BOM>12$ x<BOM>y, <BOM>2024-01-02$x x<BOM>y, <BOM>USD$ x<BOM>y, <BOM>#t$ x<BOM>y and <BOM>"s"$ x<BOM>y are 2. <BOM>12<BOM>z and <BOM>2024-01-02<BOM>a are 1.
  • Tests: test_parse_line_start_bom_run_through_valid_tokens_is_one_token and test_parse_line_start_bom_heading_rest_is_not_glued.

3. The matrix now guards these fixes.

  • I added four contexts:

    • a date alone (2024-01-02 {T});
    • a metadata line under 2024-01-02 *;
    • a BOM after the indentation glued to a run;
    • a BOM after the indentation glued to ;.
  • I added two prefixes that glue a valid token to an invalid one: <BOM>12$ and <BOM>USD$ .

  • The matrix is regenerated with the script: 2,598 inputs, and the test runs in about 1 s.

  • Reverting each fix makes the matrix test fail:

    Revert Inputs flagged
    Round 3, the line-start BOM spends the diagnostic 1,124
    Round 3, the round-2 prefix trim restored (<BOM> k: taken as the first token) 119
    Round 4, a BOM-led first token spends the diagnostic 6
    Round 4, blank-free run (glue only a directly adjacent token) 1,040
    Round 4, indented BOM merge 80
  • The first = false on a line-start BOM is now redundant with the prefix check: a prefix holding a BOM is never a readable start. Removing it alone changes nothing, so the guarded behaviour is the trim, which fails as shown above.

  • The heading-rest exception is guarded by its unit test.

Known list

1,207 inputs, each with rledger's counts. None is further from beancount than on main, and 760 are closer.

Cause Inputs
orphan-lines 1,120
inner-bom-under-line-error 74
account-after-line-start-bom 28
eol-reported-on-next-line 1

Sixteen inputs carry both orphan-lines and account-after-line-start-bom, which is why the counts add up to more than 1,207.

  • The account cause is corrected. It was account-after-invalid-token, and the Parse-error recovery differences from bean-check around invalid dates and column-0 markers #2872 pointer is dropped.
    • The extra P0006 appears only when the line's first token is a BOM that starts it: the line then gets the account's error and the BOM diagnostic, where beancount's one invalid token (the BOM's run) is all.
    • Without the BOM the counts agree.
  • eol-reported-on-next-line is new and has nothing to do with BOMs. The date context exposed it: beancount reports a bare date's unexpected EOL on the next line.
  • Re-measured with this round's code: reporting every inner-BOM token (inner-bom-under-line-error) would fix 256 more fuzz inputs and break 98.

Parity in round 4

  • 78,461 of 111,323, up from 78,399 in round 3.
  • 62 new matches, all fuzz, 0 regressions.
  • 11 mismatches changed category: their first differing line moved to a pre-existing difference.
  • --check passes after an --update. STRICT baselines pass.
Round-4 changed manifest rows (73)
  • lexer-token-split to match, fuzz (61): 0019c86dd547 03dfb80f9899 082f741d17b3 0a86ad16d2a4 0d0a08109052 20939c6b5fd5 21d920b94109 24df619fcc30 27f3411d07cb 2dbadd56d42c 39f84c149202 4021abac1121 46d8c5cf8ef8 49bc5987f20a 4b027f3c7817 4bf331a5eeae 535e6205797f 538f8242fa85 5a7afc05116e 612ffb845c44 6a8ed08aafb6 738c7b10a91a 74707def4258 781b3985538f 7f188ad3d614 8099343a9ad8 83dcfed07a87 841cde17b86c 873535c0090d 8d5f92508181 8ef16f45970e 96724bc20973 999ce260cc1e 9a8e03d22684 9ad4772675fb 9c4aa6d4c930 9daa0b90a6c4 a152587beb97 a155db2cf8ae a3e27cbab418 a580d681b853 aa0ff0f5a607 ab3cc15137d6 ae79a50fb03d b70f3e3d448b be6fc1db9fc3 c332d837eb8c c6ba92b14560 ca159aa6e972 d40c5758117e d61931d1dbe3 d8679aa637c4 d8d2480e585d da0b14e06365 df2518c828e6 e25864e96cbb e2b5a3fde783 f1ad5accc03a f8b06642bf94 f94b1607cc5f fa6bd3f6e459
  • lexer-token-split to rl-indented-line, fuzz (7): 0fd0fbf8ebdb 2ab11a7a7159 6f2a95563e6e 6f7502e0222a 9017f346aee8 ad3161751e13 ae0bd2457622
  • lexer-token-split to rl-top-level-line, fuzz (3): 5064df6042ff d178a244d222 d6cf3b84ea47
  • lexer-tokens-merged to lexer-token-split, fuzz (1): 39b03d391592
  • lexer-tokens-merged to match, fuzz (1): d5fd1d713a30

Review round 5

A. A BOM glued to an account shape is an account now. Fixed in the lexer.

  • Beancount's account type is ([A-Z]|{UTF-8-ONLY})..., and a BOM is UTF-8-only. So <BOM>Assets:A, <BOM>Ü:A and <BOM>1:A are each one ACCOUNT there, and the BOM only makes the name invalid at load time.

  • The canonical Token::Account regex no longer excludes U+FEFF from the first character, so the lexer reads the same. The account-name check (E1005) rejects the account on load.

    • Test: rustledger-validate's test_validate_bom_led_account_is_invalid_account_name.
  • <BOM>A, <BOM>USD and <BOM>Assets: are not account shapes and stay invalid tokens.

  • Because a BOM can now start an account, logos may scan a line-start BOM into a failed account (<BOM>2024-01-02). The Err arm therefore caps a line-start BOM's own extent at the BOM itself and lexes the rest afresh. The concatenated-file case is unchanged.

  • is_valid_account_name now lexes \u{feff}Assets:A as one account and rejects it. The lexer test pins both.

  • Effect:

    Input bean-check before now
    $x <BOM>Assets:A 1 2 1
    <BOM>\t<BOM>Assets:A 1 2 1
    open <BOM>Assets:C and the other account positions no parse error 1 no parse error
  • Test: test_parse_bom_led_account_is_an_account. The round-1 test no longer lists account positions.

B. A<BOM>b is counted again.

  • A lone capital glued to a BOM is one invalid token from the capital on. It now counts as BOM-led in report_invalid_tokens_of_error_line, so it is never left to the line's BOM diagnostic.
  • Only that part of the inner-BOM rule moved.
  • $x A<BOM>b is 2 and @ ! A<BOM>b %x is 3, as in bean-check and main.
  • Test: test_parse_lone_capital_glued_to_bom_is_counted.

C. The heading rest after <BOM>* is counted as beancount lexes it.

  • The part up to the first blank belongs to the BOM's token. The text after the blank is lexed with the lossless tokenizer, and each blank-free run it cannot read whole is one more error. A run is unreadable if it holds an error token or has a lone capital glued to the token after it (beancount's CAPITAL needs a blank).

  • quiet_after_invalid_tokens keeps errors that start inside such an unread token.

  • Results, all matching bean-check:

    Input bean-check
    <BOM>*7<BOM>* #tag 1
    <BOM>**<BOM>*\t"s<BOM>t" 1
    <BOM>* Heading with words 4 (was 1 on main)
    <BOM><BOM><BOM><BOM>*7 Z# 2
  • Test: test_parse_line_start_bom_heading_counts_the_rest.

Nit. first = false is removed. The comment on first explains why a line-start BOM never leaves it set for the next token to read.

Guard

  • Token kinds. The matrix gains K (<BOM>Assets:A{i}) and C (A<BOM>b{i}). It now has every combination of up to two tokens of all five kinds, plus the three-token combinations of L/I/N, across 13 contexts and 5 prefixes: 3,769 inputs.

  • EXTRA. Twenty hand-picked shapes from the reviews, each pinned.

  • Seeded random probe. PROBE_SEED = 2931, 2,000 inputs, generated by the same script.

    • Each input has lines of 4-5 tokens with mixed blanks, BOM tokens and ordinary ones: strings, comments, headings, #!/#+, %, push directives, cost and price, tags, links.
    • The lines sit under every directive type, with indented metadata and posting lines, CRLF in about one in five, and no final newline in about one in five.
    • Each input is parsed in a forked child. 37 are left out because an unclosed pushmeta makes beancount's builder raise; the script names them on stderr.
  • Table. 5,727 rows, test about 2 s. The tab and \r escapes are new.

  • Known list. 2,991 rows, each with rledger's counts and a cause:

    Cause Rows
    orphan-lines 1,574
    no-worse-than-main 1,094
    like-main-without-bom 146
    inner-bom-under-line-error 117
    orphan-lines + account-after-line-start-bom 32
    orphan-lines + inner-bom-under-line-error 3
    recovery-after-error-line 1

No row further than main, checked against a main build.

  • 147 rows are further from beancount than main. For each, every line that is worse was checked against the same input with each BOM replaced by an ordinary character (<BOM> to $, <BOM>Assets to ÜAssets). For 146 rows that line counts the same way on main as here, with beancount's count unchanged.
    • This is the new cause like-main-without-bom. It covers your example <BOM>12$ 2024-01-02 open Assets:C USD #tag against $x 2024-01-02 ...: after a line's first invalid token, beancount keeps parsing and reports a later grammar error, where rledger reports one diagnostic per line.
  • The one remaining row (recovery-after-error-line) is an indented line right after a line beancount could not read. Beancount's recovery reports no grammar error there; rledger does (Parse-error recovery differences from bean-check around invalid dates and column-0 markers #2872). Its replacement analog differs only because the replacement changes the line before it.

Parity in round 5

  • Still 78,461.

  • 2 new matches and 2 regressions:

    Input Cause
    fuzz_parse/3d32b9d6 <BOM>G:3#\x00 is now an account glued to #, on an indented line after a broken one. rledger reports the glued #; beancount's recovery does not. Main did the same for G:3#\x00 without a BOM.
    fuzz_parse/c71bf0c5 Same cause.
  • 15 mismatches changed category.

  • --check passes after an --update. STRICT baselines pass.

Round-5 changed manifest rows (19)
  • lexer-token-split to lexer-tokens-merged, fuzz (1): 01283cce0de0
  • lexer-token-split to match, fuzz (2): 28cfa3f0fdd6 59766d726781
  • lexer-tokens-merged to lexer-token-split, fuzz (7): 1c2449827fa3 9b2f1475b5b2 9bded2eea40d bdac17d7856c be8087979eb6 ca617e441a3f daf4cd32d74b
  • lexer-tokens-merged to rl-top-level-line, fuzz (1): 6820e6c5d32f
  • match to lexer-token-split, fuzz (2): 4021abac1121 4b027f3c7817
  • rl-indented-line to lexer-token-split, fuzz (6): 40725296503b 9978ff2c4d82 a9c982f622f0 d15ec77bb761 d9ea47088ea2 f7a15f80272e

Review round 6

Change A is reverted. Token::Account is as on main.

  • With A, a BOM could start an account. That made a line of BOMs quadratic. It also hid the BOM from users:
    • E1005 never named the BOM;
    • the "Remove BOM" quick fix was gone;
    • the LSP offered open <BOM>Assets:D.
  • The narrower rule replaces it, in the lexer's Err arm. When the text after a mid-line run of BOMs is account-shaped, the run keeps its own extent, as line-start BOMs do.
    • "Account-shaped" means the lexer's first token there is Token::Account. This is checked by logos_lexer::starts_with_account, which reads no further than the next blank. There is no new regex.
    • The run is one token however many BOMs it holds.
  • Results:
    • open <BOM>Assets:C is one P0026 with its quick fix again, and the directive keeps Assets:C.
    • $x <BOM>Assets:A and <BOM>\t<BOM>Assets:A are 1 error, as in bean-check: beancount's own error there is the load-time account-name check, which the matrix filters out.
  • In the CST recovery, such a run is no invalid token of beancount's, so it is never counted as one (is_bom_run_before_account). This applies in:
    • report_invalid_tokens_of_error_line;
    • quiet_after_invalid_tokens;
    • holds_an_invalid_token, which holds a BOM-only token until the next one says whether it is an account.
  • Tests:
    • test_parse_bom_glued_to_account_keeps_the_account replaces round 5's account test;
    • the LSP quick-fix test gains open <BOM>Assets:C and open <BOM><BOM>Assets:C;
    • rustledger-validate's round-5 test is reverted.
  • The loaded account is the same as on main, so no cache note changes.

Linear by construction, with a guard.

  • A line-start BOM is one logos error of one character, as on main, so nothing re-enters logos per BOM.

  • A mid-line run is taken whole.

  • The CST's lookahead checks only the character after a BOM token. A token followed by another BOM stops there.

  • My first version of the revert still had a quadratic lookahead in the CST: it trimmed the rest of the run for each line-start BOM, and a 1 MB line took 50 s. The guard below caught it.

  • New guard, test_tokenize_long_bom_runs_are_linear:

    • It lexes and parses runs of 20,000 and 350,000 BOMs: at a line's start and in its middle, glued to a and to an account, and with a blank before a.
    • It counts the bytes logos scanned into error spans, the bytes the account lookahead read, and the bytes restarts saw, and fails above 8 × the input size.
    • It fails on round 5's lexer (600 MB counted for a 60 KB input, in 4 s), and on the quadratic CST lookahead.
  • Timings, release build of parse_error_lines, best of 3:

    Input main PR
    1 MB line of BOMs + a 0.034 s 0.035 s
    1 MB mid-line BOM run + account 0.030 s 0.005 s
    50k <BOM>* Heading with some words lines 0.063 s 0.249 s
    50k <BOM>2024-01-01 open Assets:A lines 0.073 s 0.075 s
  • The heading lines are slower because each now reports beancount's 5 errors instead of main's 1: 250k errors built and printed against 50k. Lexing their rests is linear.

Known list: every differing line has a real cause.

  • no-worse-than-main is gone, and so are the round-3 to round-5 names.

  • I classified each differing line of each row with a local rule set, one rule per cause, applied line by line, and checked the like-main-without-bom rule against a main build. The classifier is not committed; the rules are described in the TSV header and in CAUSES. A row names the causes of all its lines.

  • Unclosed pushtag / pushmeta errors are now line 0 on rledger's side too, as in the parity harness (RLEDGER_EOF_CODES). That removed "pushtag reported at line 0".

  • Rows per cause (a row with several causes counts under each):

    Cause Rows
    indented-line-after-error (Parse-error recovery differences from bean-check around invalid dates and column-0 markers #2872) 2,290
    mid-line-hash-bang (part 2 of compat(parser): an invalid run should swallow a following quote, #! or #+ mid-line, as beancount's lexer does #2928) 603
    bom-glued-to-account 216
    inner-bom-under-line-error 196
    line-after-error-line (Parse-error recovery differences from bean-check around invalid dates and column-0 markers #2872) 139
    like-main-without-bom 109
    invalid-account-after-invalid-token 38
    one-diagnostic-per-line 20
    extra-construct-error 19
    failed-push-still-pushed 7
    eol-reported-on-next-line 1
  • In total 3,083 rows differ from bean-check, 0 unclassified. eol-reported-on-next-line is back.

  • Further than main: 286 rows have at least one line further from bean-check than main. Each such line has one of these causes:

    Cause Lines
    like-main-without-bom 112
    indented-line-after-error 163
    line-after-error-line 26
    bom-glued-to-account 4
    • For like-main-without-bom, the same line in the input with each BOM replaced by an ordinary character counts the same way on main. Per your nit, a BOM run glued to an account maps to Ü (<BOM>Assets to ÜAssets), and everything else to $. All of these lines hold strictly.
    • For indented-line-after-error and line-after-error-line, the line matches beancount when it stands alone. In context, main matched only because its BOM count offset the recovery difference.
    • For bom-glued-to-account, the P0026 you asked for here is one error more than beancount's parse errors, and main swallowed the BOM in a ; comment.

Parity in round 6

  • 78,460 of 111,323, one fewer than round 5.
  • The one change: fuzz_green_eq_red/329c733d matched in round 5 only because A read its BOM into an account. It now counts as on main, with the same 12 errors.
  • --check passes after an --update. STRICT baselines pass.

Nits

  • The like-main-without-bom description now states the Ü mapping.
  • The round-5 table's 24 standalone account-after-line-start-bom rows are superseded by the per-line causes above.

Review round 7

This push also carries the plain merge of origin/main (#2930). Both sides of CHANGELOG.md are kept, and both cache notes: loader v69 (#2925) and v70 (#2928), WASM v92 and v93. The caches stay at 70/93.

1 and 2: one predicate, and beancount's account rule.

  • logos_lexer::bom_led_account decides with the lexer's own account rule. It lexes the word with a non-ASCII stand-in (Ü) in the BOMs' place, so the lexer's first-character rule applies.
    • <BOM>Assets:A, <BOM>assets:A, <BOM>1:A, <BOM>:A and <BOM>-:A are all accounts, as in beancount.
    • It reads no further than the next blank.
  • In the lexer:
    • When an account of rledger's follows the BOMs (account_follows_bom_run), the run keeps its own extent, so the BOM gets its P0026 and the account stays an account.
    • Otherwise (<BOM>assets:A), the token ends where beancount's account ends, so a glued tail is one more token.
  • All four counting sites now call one predicate, cst::convert::is_bom_account_token:
    • report_invalid_tokens_of_error_line;
    • the heading-rest invalid_runs, which was missing it;
    • quiet_after_invalid_tokens;
    • holds_an_invalid_token.
  • Each of these now matches bean-check: <BOM>* <BOM>Assets:A (1), <BOM>* x\t<BOM>Assets:A (2), and $x followed by <BOM>assets:A, <BOM>1:A, <BOM>:A or <BOM>-:A (1 each).

3: line-start bookkeeping before an account.

  • A line-start BOM now always spends the BOM diagnostic. When an account of its own follows the run, nothing after the account is glued to the run, because beancount's token ends at the account's end.
  • <BOM><BOM>Assets:A$x is now 2, and <BOM>Assets:A x<BOM>y and <BOM><BOM>Assets:A x<BOM>y are both 2. All three match bean-check.
  • Test: test_parse_bom_led_account_shapes_count_as_beancount.
  • The matrix gains:
    • kind k (<BOM>assets:A{i}, an account only with its BOM);
    • kind T (<BOM>Assets:A{i}$x, a glued tail after K);
    • prefix bom-bom, two line-start BOMs before every token. It replaces glued-currency.

4: the known list is reproducible.

  • The classifier is now in the test: cause() in tests/bom_combination_matrix.rs, one rule per cause, each commented. For every input that differs from beancount, the test:

    • assigns each differing line a cause;
    • fails on a line no rule explains;
    • checks that the known list holds exactly those causes and rledger's current counts.
    • BOM_MATRIX_UPDATE=1 rewrites the list.
  • The fixture now records, per input:

    • beancount's counts;
    • main's counts;
    • beancount's and main's counts for the analog input (<BOM> replaced by $, a BOM run glued to an account replaced by Ü).
    • So like-main-without-bom is checkable without a main build. scripts/bom-combination-matrix.py --main-binary writes these columns.
  • New or refined rules for the mislabels the review found:

  • Table: 7,429 rows. Known list: 3,995 rows. Lines per cause (a row with several causes counts under each):

    Cause Lines
    indented-line-after-error 2,998
    mid-line-hash-bang 606
    bom-glued-to-account 450
    inner-bom-under-line-error 173
    like-main-without-bom 160
    line-after-error-line 136
    indented-line-after-heading 40
    invalid-account-after-invalid-token 34
    one-diagnostic-per-line 16
    failed-push-still-pushed 7
    extra-construct-error 7
    lone-capital-glued-to-tokens 6
    line-start-bom-before-comment 6
    eol-reported-on-next-line 1

Nits

  • The linearity guard now also has a wall-clock bound on the 20,000-BOM case: 5 s, against well under one when linear. A lookahead written as trim_start_matches on the rest of the run, which the byte counters do not see, fails it in 7 s. Every BOM-run trim in the lexer and the recovery goes through the counted leading_bom_run.
  • The LSP action title is now "Remove N BOMs (U+FEFF)".

Parity in round 7

  • Unchanged at 78,460: the --check run shows no row changed from round 6.
  • STRICT baselines pass. Green equals red on the pinned fuzz corpus.

Timings against main are unchanged from round 6:

Input main PR
1 MB of BOMs + a 0.032 s 0.033 s
1 MB mid-line run + account 0.031 s 0.006 s
50k heading lines 0.073 s 0.245 s
50k BOM-led open lines 0.073 s 0.074 s

Review round 8

1. A line-start BOM before an account beancount reads only with its BOM: fixed.

  • When a line-start BOM run is followed by an account in beancount's sense only (bom_led_account: <BOM>assets:A, <BOM>1:A, <BOM>-:A, <BOM>a-b:C), the tokens up to that account's end are part of it.

  • The part of a token past that end is beancount's next token. It counts as invalid only when it lexes so: $x, .b, 'b and <BOM>$x count; "x", #t, ^l, !, @ and ;c do not.

  • Errors that start inside an rledger error token now survive quiet_after_invalid_tokens. That one rule covers both this tail and the <BOM>* heading rest.

  • All of these now match bean-check:

    Input bean-check
    <BOM>assets:A$x, <BOM><BOM>assets:A$x, <BOM>1:A$x, <BOM>1:A:B$c, <BOM>-:A$x, <BOM>a-b:C$x, <BOM>assets:A.b, <BOM>assets:A'b, <BOM>assets:A<BOM>$x 2
    <BOM>assets:A followed by "x", #t, ^l, !, @ or ;c 1
  • These shapes are EXTRA rows now, and the matrix gains kind t (<BOM>assets:A{i}$x) with every line-start prefix.

2. The guard can no longer absorb a regression.

  • New hand-kept file: tests/data/bom_combination_matrix_worse_than_main.tsv. Each row gives the input, the line, the cause, beancount's count for the line alone, and a one-line reason.

  • The test fails, before any update, on any line further from bean-check than the recorded main count that is not in that file. BOM_MATRIX_UPDATE never writes the file, and it refuses to refresh the known list while such a line is unlisted.

  • The file is authoritative for these lines, and the test checks that each listed cause holds:

    • like-main-without-bom: the analog columns equal beancount's and rledger's counts on the line.
    • Recovery causes: the line alone counts as beancount counts it alone.
    • The line's own causes (bom-glued-to-account, invalid-account-after-invalid-token, line-error-beside-bom-diagnostic): alone, rledger is off in the same direction and at least as far as in context.
  • Seeded with today's 414 lines: 399 like-main-without-bom, each checked against the analog, and 15 bom-glued-to-account. The 15 are the <BOM>; c <BOM>Assets:A rows, where main hid the BOM in a comment.

  • Rule order is tightened. invalid-account-after-invalid-token is asked before bom-glued-to-account, and both before the recovery rules. Each rule's comment now says what it requires.

  • The six mutations, each run with BOM_MATRIX_UPDATE=1, which never wrote the known list:

    Mutation Result
    1. drop the predicate in invalid_runs fails: 4 lines further than main
    2. drop it in quiet_after_invalid_tokens fails: 4 lines
    3. revert the glue to line_start_boms_end = Some(range.end) fails: 33 lines
    4. drop it in holds_an_invalid_token (either branch) fails: 1 line, from the new EXTRA row open ... "BAD" with kk: <BOM>Assets:D; also test_parse_bom_account_in_metadata_keeps_booking_method_check
    5. force account_follows_bom_run false the counts do not change, so the matrix passes; test_parse_bom_glued_to_account_keeps_the_account fails because the account is lost
    6. drop it at the main site fails: 813 lines

Nits

Counts in round 8

  • Table: 8,486 rows. Known list: 4,602 rows. Accepted further-than-main lines: 414.

  • Parity unchanged at 78,460.

  • STRICT baselines pass, and green equals red on all 44,589 pinned fuzz inputs.

  • Timings unchanged:

    Input main PR
    1 MB of BOMs + a 0.029 s 0.029 s
    1 MB mid-line run + account 0.026 s 0.005 s
    50k heading lines 0.064 s 0.232 s
    50k BOM-led open lines 0.063 s 0.072 s

Review round 9

1. The new quadratic: fixed, and guarded.

  • bom_led_account scanned the word after a BOM run to the next blank, then lexed it, once per BOM run on the line. A long line of ~<BOM>1:A repeats made that quadratic.
  • It now takes only the characters an account can hold (ASCII alphanumerics, -, :, non-ASCII), so the word ends at the first other character, and the scan is bounded by the account it reads. The doc comment says so.
  • test_tokenize_long_bom_runs_are_linear gains three shapes: x\n<BOM>assets:A + ~<BOM>1:A repeated, the same after x $x , and x\n<BOM>Assets:A + the repeats. It counts scanned bytes (at most 8 times the input) and keeps the 30 s backstop. On the round-8 lookahead it fails, with about 1 GB scanned.

2. Matrix tails and the heading context.

  • New single tail tokens after an account kind: s (<BOM>"s"), u (~<BOM>1:A) and x (<BOM>x). New context: a <BOM>* heading.
  • The table is now 11,155 rows.

3. The accepted list must name the cause the classifier finds.

  • check_worse_than_main requires a.cause == w.cause as well as the cause's own check. An entry with a different cause fails, and so does an entry that is no longer worse than main ("remove it").

4. Seed-909931 probe lines: resolved.

  • The account probe (seed 909931, 2,000 inputs) is now part of scripts/bom-combination-matrix.py, next to the round-5 probe (seed 2931).
  • mid-line-hash-bang now has a real check. The table has a sixth column: beancount's count on the input with each mid-line #! / #+ replaced by a plain invalid token. rledger must count that analog exactly as beancount does.
  • <BOM>* Heading<BOM>a-b:C{ 1<BOM>2: 2 errors, as in bean-check.
  • <BOM><BOM>kk:<BOM>;c\t<BOM>1.5: 1 error, as in bean-check. In a tail split, a ; now ends the line, so the comment is not lexed for invalid tokens.
  • <BOM>* Heading,Ü:A: 2 errors, as in bean-check, where it was 3.
    • On a line that starts with a BOM, the classifier now looks for a Unicode account only outside the line's invalid tokens. Inside one, the account is part of that token, whose own error already reports it.
    • The invalid tokens are masked byte for byte with _, not blanked. A blank would split a word, so the Fݾ:Ü glued to the BOM in x\n<BOM>Fݾ:Ü would become an account of its own. That doubled the count and turned up as one changed fuzz row while the parity run was being checked. A word only partly inside an invalid token is still reported as written (Invalid account 'G:Ψ@3O+.1'), read back from the line.
    • The masking is limited to lines that start with a BOM. Masking every line regressed 63 parity rows.
  • $x Heading,Ü:A is not fixed. It is main's mechanism and is older than this PR, and fixing it means the broad masking that regressed those 63 rows.
  • About 89 cause mismatches: re-run with cause equality. Each is now accepted under the cause the classifier finds, or is no longer worse than main.

Nits

  • <BOM>:A$x: not fixed. After a line-start BOM, rledger's lexer reads a : in column 0 as an ignored line, exactly as main does. The miscount comes from that rule, not from the BOM run.
  • The 15th bom-glued-to-account row now gives its own reason, not the query row's.

Mutations

Each was run with BOM_MATRIX_UPDATE=1, and none of them wrote the known list. The first nine were measured before the final masking change. That change only removed accepted rows, so the list is stricter now.

Mutation Result
R8-1 to R8-6 (round 8's six) fail: 122, 20, 57, 1, 26 and 805 lines
M7b fails: panic, plus failing unit tests
M8 fails: 47 lines
M9 fails: 45 lines
drop the ; break in the tail split fails: 1 line
no masking in the classifier fails: 98 unexplained lines
mask with blanks, not _ (final code) fails: 174 lines further than main

Counts in round 9

  • Table: 11,155 rows. Known list: 5,248 rows.

  • Accepted further-than-main lines: 441, made up of:

    • 415 like-main-without-bom
    • 21 bom-glued-to-account
    • 4 inner-bom-under-line-error
    • 1 mid-line-hash-bang
  • The byte-for-byte masking took 173 lines off the accepted list: 148 invalid-account-after-invalid-token and 25 bom-glued-to-account. Each was an extra P0006 on a BOM-glued account. One line was added, <BOM>A<BOM>b \t<BOM>Ü:A #+x A<BOM>b x<BOM>y: it is like-main-without-bom, and the cause is the mid-line #+x (part 2).

  • Parity: 78,461, up from 78,460. One fuzz row now matches: the inner invalid account in a BOM-led invalid token is no longer counted. The manifest was updated for that one explained row, and no row regressed.

  • STRICT baselines pass, and green equals red on all 44,589 pinned fuzz inputs.

  • Timings:

    Input main PR
    1 MB of BOMs + a 0.028 s 0.028 s
    1 MB mid-line run + account 0.028 s 0.007 s
    50k heading lines 0.060 s 0.228 s
    50k BOM-led open lines 0.064 s 0.069 s
    1 MB <BOM>assets:A + ~<BOM>1:A repeats 0.045 s 0.024 s
    1 MB $x <BOM>assets:A + repeats 0.045 s 0.040 s
    1 MB <BOM>Assets:A + repeats 0.048 s 0.042 s

Review round 10

This push also carries a plain merge of origin/main at d728311 (#2920), with no rebase and no force-push.

  • CHANGELOG.md keeps both entries.
  • WASM cache: main holds v94, so this branch moves to v95, pinned at loader v70. There is one note per version, and the v95 note records that v93 was never released.
  • Loader cache: stays at v70, one above main's v69.

S1. A comment inside a BOM-led tail: fixed.

  • invalid_runs now also says whether a comment ended the text. The tail split breaks on that, wherever the ; falls: right after the account, or after a later BOM-led account in the tail. The special case for a leading ; is gone.
  • These now match bean-check:
    • <BOM>assets:A~<BOM>1:A;c $x: 1 error
    • <BOM>assets:A,<BOM>a-b:C;c $x: 1 error
    • ...;c $x $y: 1 error
  • New matrix tails: v (~<BOM>1:A;c $x) and w (,<BOM>a-b:C;c $x).
  • Accepted row <BOM><BOM><BOM>assets:A"x"<BOM>a-b:C;c\t<BOM>1.5, which carried the false reason, now matches bean-check (1) and is gone from the list.

S2. Cause checks name the error kinds.

  • The test now has each line's P0026 and P0006 counts.

  • The cause() rules ask for the kinds as well as the counts:

    • invalid-account-after-invalid-token needs a P0006 for each error beyond beancount's.
    • bom-glued-to-account needs a P0026 for each.
    • inner-bom-under-line-error needs the line's P0026.
  • holds() checks the same through a new kinds_hold. For bom-glued-to-account it also checks the rest of the line: with each account beancount reads with its BOMs written as Assets:X (ordinary_accounts, an ACCOUNT to beancount either way), rledger must count the line exactly as beancount does.

  • The dead line-error-beside-bom-diagnostic cause is removed.

  • Every accepted row passes the stricter check.

  • 2024-01-02 price USD 1 <BOM>assets:A1 1 is now an EXTRA row, accepted as bom-glued-to-account and checked as above. This is not main's 1 $x 1 overcount:

    Input bean-check main PR
    price USD 1 $x 1 1 2 non-BOM errors (malformed amount, unexpected input) same as main
    price USD 1 Assets:A1 1 1 (unexpected ACCOUNT) 1 (malformed amount) 1
    price USD 1 <BOM>Assets:A1 1 1 2 (malformed amount + P0026) 2
    price USD 1 <BOM>assets:A1 1 1 1 (its BOM token took the account and the amount after it) 2, the same pair as for <BOM>Assets:A1

    So the malformed amount stands for beancount's unexpected ACCOUNT, and the extra error is the glued P0026 (compat(parser): an invalid run should swallow a following quote, #! or #+ mid-line, as beancount's lexer does #2928's design). The ordinary_accounts check verifies exactly this.

  • A new cause, brace-hash-before-tag, covers a {# glued to a tag character outside a heading rest (foo {#t). rledger's lexer has a {# total-cost token there, on main too. It came up on the <BOM>g <BOM>* H {#t ... rows of the new heading context, which are not headings.

S3. {# in a <BOM>* heading rest: fixed.

  • invalid_runs reads a {# as beancount does: a {, then whatever the # starts.
  • It resumes the lexer right after the brace, mid-line, with the new TokenIter::new_mid_line. There is no re-scan, so the cost stays linear.
  • <BOM>* H {#t is 1 error, as in bean-check, and <BOM>* H {#t{#$x {#"a b" is 2.
  • New matrix context: heading-brace-hash (<BOM>* H {#t {T}).

S4. The linearity guard fails instead of hanging.

  • Each shape runs once short (20k BOMs), then at 1 MB (350k) on its own thread. The long run gets a budget of 4 times the linear ratio times the short time, plus 2 s, and the guard waits on it with recv_timeout.
  • The byte counters are still checked on both runs.
  • On the uncounted trim mutation (from[text.len()..].trim_start_matches(BOM).len() == from[text.len()..].len() in is_bom_account_token), the guard now fails:
    • short run: 2.2 s
    • long run: over its 154 s budget, reported as "quadratic"
    • whole test: 157 s
  • New guard shape: a <BOM>* heading rest of {#t{#$x repeats.

Nits

  • Masking is pinned to BOM-led lines. New test: test_parse_invalid_account_on_bom_free_line_keeps_its_p0006. Heading,Ü:A alone is still main's one P0006, so the N1 mutation (mask every line) now fails it.
  • Renamed test. It is now test_parse_partly_invalid_account_word_keeps_mains_message. It says it pins main's message, not beancount's behavior (beancount's account there is G:Ψ).
  • Composite lines. The accepted file's header and the test's doc now state the limit:
    • an accepted line names one cause and must pass that cause's check alone;
    • there are no composite entries.
  • Token text. A heading rest's or a tail's invalid run is now reported from where beancount's invalid token starts, past the valid tokens before it:
    • {#t{#$x reports $x;
    • in the fuzz corpus, %\0\003100 now reports \0\003100, as bean-check does.
    • The tail split now reports the runs from invalid_runs, not the whole tail.
  • Cache wording. The caches line says main holds loader v69 and WASM v94, and the PR goes to v70 and v95.

Mutations

Each was run with BOM_MATRIX_UPDATE=1, and none wrote the known list. They used the round-9 runner, with its targets updated to the new code.

Mutation Result
R8-1 fails: 33 unexplained inputs; 2 unit tests
R8-2 fails: 20 lines
R8-3 fails: 58 lines; a unit test
R8-4 fails: 1 line; test_parse_bom_account_in_metadata_keeps_booking_method_check
R8-5 matrix passes; test_parse_bom_glued_to_account_keeps_the_account fails
R8-6 fails: 236 unexplained inputs
M7b fails: the matrix test panics; 2 unit tests
M8 fails: 3 unexplained inputs; a unit test
M9 fails: 47 lines; a unit test
N1 (mask every line) matrix passes; the new test_parse_invalid_account_on_bom_free_line_keeps_its_p0006 fails
S1: drop the comment break in the tail fails: 2 lines; a unit test
S3: no resume after {# fails: 36 lines; a unit test
S4: uncounted trim fails: the linearity guard, after 157 s, on its time budget

I don't have the definitions of N2 to N5 or Q6c, so I couldn't re-run them. Please apply them to this push.

Counts in round 10

  • Table: 11,821 rows (665 new). Known list: 5,538 rows.

  • Accepted further-than-main lines: 505, made up of:

    • 477 like-main-without-bom
    • 23 bom-glued-to-account
    • 4 inner-bom-under-line-error
    • 1 mid-line-hash-bang
  • The new accepted lines come from the new tails and heading context:

    • 62 like-main-without-bom. Main came closer on these only by miscounting a BOM; on 54 of them, the BOM offset main's {#t overcount.
    • 3 bom-glued-to-account: two <BOM>; c rows and the price row.
  • Parity: unchanged at 78,461, and --check passes. Six fuzz rows changed only their token text, to bean-check's.

  • STRICT baselines pass, and green equals red on all 44,589 pinned fuzz inputs.

  • Tests: parser, lsp, loader and wasm pass (1,918 passed, 0 failed), and so does wasm-pack test --node.

  • Timings:

    Input main PR
    1 MB of BOMs + a 0.034 s 0.027 s
    1 MB mid-line run + account 0.026 s 0.005 s
    50k heading lines 0.060 s 0.228 s
    50k BOM-led open lines 0.063 s 0.068 s
    1 MB <BOM>assets:A + ~<BOM>1:A repeats 0.046 s 0.024 s
    1 MB $x <BOM>assets:A + repeats 0.044 s 0.041 s
    1 MB <BOM>Assets:A + repeats 0.045 s 0.042 s
    1 MB <BOM>* H + {#t{#$x repeats 0.003 s (main skips the heading rest) 0.084 s

Review round 11

The parser's counts are unchanged this round. Parity --check passes with no row changed from round 10, still 78,461. The fixes are in the guard, plus one parser cleanup and two pins.

1. Recovery causes come first.

  • The table has a seventh column: beancount's count for each line alone. That is the line after the head, under a bare 2024-01-02 * when indented, computed by alone_cells in the script.
  • cause() now asks a recovery cause first, before like-main-without-bom and before any cause of the line's own, whenever rledger counts the line alone exactly as beancount does alone. Otherwise the recovery rules are asked where they were.
  • An accepted recovery row's <alone> must also agree with the table's column.
  • 224 accepted rows moved from like-main-without-bom to their recovery cause, each now checked by its alone count:
    • 109 indented-line-after-error
    • 107 line-after-error-line
    • 8 indented-line-after-heading
  • New matrix context after-error (foo and then <BOM>assets:A {T}), and an EXTRA row for foo\n<BOM>assets:A <BOM>, now line-after-error-line.

2. Composite causes, each part verified.

  • An entry may name two parts joined by &: bom-glued-to-account&mid-line-hash-bang or bom-glued-to-account&extra-construct-error.
  • parts_hold takes the parts out in turn and measures each share on what is left:
    • Glued: the errors that go when each account beancount reads with its BOMs is written Assets:X. This must be more than none and no more than the line's P0026s.
    • Hash-bang: what goes when each mid-line #! / #+ is made an ordinary invalid run, against beancount's own count for that input.
    • Construct: main's overcount of the BOM-free analog.
  • Every share must be non-zero, and together they must be exactly the line's difference. The single bom-glued-to-account and mid-line-hash-bang checks are the same function with one part.
  • ordinary_accounts now follows beancount's ACCOUNT rule. A BOM counts as a name character, and a run after a number starts an account (-2.5<BOM>a-b:C).
  • bom-glued-to-account-in-error-line (43 known rows, none worse than main) covers a glued BOM whose rewrite turns the line into one rledger reads with a construct error of its own, a posting's trailing tokens. There, the line's P0026s drop by exactly the difference, and one non-BOM error takes their place.
  • New contexts: glued-hash-bang ( <BOM>1:A:B #+x {T}) and glued-price (price USD 1 <BOM>:A\t{1 USD} {T}).
  • New EXTRA rows for the review's two examples:
    • <BOM>1:A:B #+x#t\t{#t$x is bom-glued-to-account&mid-line-hash-bang.
    • price USD 1 <BOM>:A\t{1 USD}#t is bom-glued-to-account&extra-construct-error.
  • 94 accepted rows are the first composite and 1 is the second.
  • The five uncovered price USD 1 ... inputs: the review didn't list them, so I couldn't check them one by one. Every price USD 1 <BOM>... input that the new glued-price context and the EXTRA rows generate now has a cause, and nothing in the matrix is left unexplained.

3. Token text is pinned.

  • New test test_parse_bom_line_reports_beancounts_invalid_token_text. It checks that {#t{#$x gives $x, 1A$x gives A$x, "s"$x gives $x, A{#t gives A{#t, A{# gives A{#, and two BOM-led tails give $x.
  • New list data/bom_combination_matrix_texts.tsv (8,942 rows): the invalid tokens rledger names, line by line, for every input with a BOM. A change fails the test.
  • Update guard: an update that keeps a row's counts but changes its causes or token texts now also needs BOM_MATRIX_RELABEL=1, so a plain BOM_MATRIX_UPDATE=1 cannot take in a weakened rule or a changed text.

4. Linearity guard.

  • The short run must take under 1 s. The uncounted trim mutation now fails there, in 2.5 s for the whole test.
  • The long run's budget is 10 times the linear ratio times the short time, plus 5 s, up from 4 times plus 2 s.
  • If the worker thread panics, its own panic is re-raised (resume_unwind), not reported as "took over ... quadratic".

Nits

  • The heading rest's if comment { break; } is removed: the rest runs to the end of the line.
  • invalid_runs now handles a {# through the same code as every other token. There is no separate lone-capital reset any more: A{# gives A{#, as in bean-check. That is the one shape where the lexer reads the capital and the {# apart, and it is pinned in the token-text test.
  • new_mid_line's at_line_start = false is pinned by test_token_iter_new_mid_line_applies_no_line_start_rule. Without it, the word and blanks before the resume point are read as an Indent.
  • The accepted file's header now says "at least as far off alone", as holds() checks, and describes every cause's check, composites included.

Mutations

Each was run with BOM_MATRIX_UPDATE=1, and no list was written by any of them. N2 to N5 were never defined for me; I named and ran my own versions of the S, T and Q mutations.

Mutation Result
R8-1 fails: 33 unexplained inputs; 2 unit tests
R8-2 fails: 119 lines
R8-3 fails: 58 lines; 2 unit tests
R8-4 fails: 1 line; a unit test
R8-5 matrix passes; test_parse_bom_glued_to_account_keeps_the_account fails
R8-6 fails: 325 unexplained inputs
M7b fails: the matrix test and unit tests
M8 fails: 3 unexplained inputs; unit tests
M9 fails: 47 lines; unit tests
N1 matrix passes; test_parse_invalid_account_on_bom_free_line_keeps_its_p0006 fails
S1 (tail comment break) fails: 2 lines; a unit test
S2a (no P0006 check in cause) fails: the update refuses the relabel
S2b (glued share unbounded by P0026s) fails: the update refuses the relabel
S2k (no P0006 check in holds) unobservable: no accepted row has that cause
S3a (no resume after {#) fails: 36 lines; unit tests
S3b (new_mid_line at line start) fails: the new lexer test
S3c (lone-capital reset at {#) fails: the token-text test (A{#)
T1 (token start) fails: the texts list and the token-text test
Q6c (uncounted trim) fails: the linearity guard's 1 s cap on the short run

Counts in round 11

  • Table: 13,399 rows. Known list: 6,684 rows. Texts list: 8,942 rows.
  • Accepted further-than-main lines: 1,082, made up of:
    • 676 like-main-without-bom
    • 109 indented-line-after-error
    • 108 line-after-error-line
    • 8 indented-line-after-heading
    • 94 bom-glued-to-account&mid-line-hash-bang
    • 75 bom-glued-to-account
    • 6 inner-bom-under-line-error
    • 5 mid-line-hash-bang
    • 1 bom-glued-to-account&extra-construct-error
  • Parity: 78,461, and --check passes with no rledger output changed from round 10.
  • STRICT baselines pass, and green equals red on all 44,589 pinned fuzz inputs.
  • Tests: parser, lsp, loader and wasm pass (1,921 passed, 0 failed), and so does wasm-pack test --node (35).
  • Caches: main is still d728311, so they stay at loader 70 and WASM 95.

Review round 12

The parser is unchanged this round: parity --check passes at 78,461, with no rledger output changed. All the changes are in the guard and the generator.

1. inner-bom-under-line-error is verified, not applied by shape.

  • The generator now reads beancount 3.2.3's own lexer (lexer.lex_iter_string) for every input, and the table carries two new columns, as byte offsets:

    • the ACCOUNT tokens that start with a BOM;
    • the BOMs inside an invalid token, past its leading BOMs.
  • The cause now needs two things:

    • a BOM on the line inside one of beancount's invalid tokens, so a BOM beancount reads into an ACCOUNT (which admits UTF-8) no longer counts;
    • with each such BOM made a $ (still one invalid token to beancount), rledger counts the line exactly as beancount does (inner_boms_are_the_difference).
  • The 6 accepted rows were not that. For example, in <BOM>g 2024-01-02 * "n" <BOM>assets:A0<BOM>"s" the BOM after A0 is inside beancount's ACCOUNT. Writing those accounts Assets:X leaves rledger at 1, so the account is not the mechanism either. The rows are now one-diagnostic-per-line, which an accepted row must now verify:

    • the table has a new column, beancount's grammar errors on each line after the line's first error;
    • rledger must count beancount's count less exactly those (later_grammar_is_the_difference).

    Here that is the line diagnostic standing for the <BOM>g invalid token, and the unexpected ACCOUNT after it as the whole difference. Main's 2 came from reporting g as a token of its own.

  • New verified cause bom-account-under-line-diagnostic (33 known rows, none worse than main): one P0026 stands for the grammar error at a BOM-led account, and with those accounts written Assets:X rledger counts the line as beancount does.

  • The known list's inner-bom-under-line-error label went from 278 rows to 153. The rest are now one-diagnostic-per-line or bom-account-under-line-diagnostic, each by its own check.

2. ordinary_accounts uses beancount's token boundaries.

  • It now rewrites exactly the BOM-led ACCOUNT tokens beancount's lexer reports, so the heuristic is gone. That covers:
    • $<BOM>a:B, AB_<BOM>a:B and 1.5.<BOM>a:B, where the BOM is in an invalid token;
    • ab:<BOM>a:B, x 2024-01-01<BOM>a:B, -<BOM>a:B and #t<BOM>a-b:C, where an account starts.
  • The glued-account rules ask the same columns.
  • All of these shapes, and the probe's 2024-01-02 custom "b" 1 <BOM>-:A\t#t<BOM>a-b:C@, are now EXTRA rows.

3. Negative shares are documented. The doc of parts_hold and the accepted file's header now say that the glued and construct shares are positive, while the #! / #+ share is often negative (-2 to -3 on every glued&hash-bang row).

4. kinds_hold is gone.

  • It only re-checked conditions cause() already guarantees, and the cause equality requires them.
  • invalid-account-after-invalid-token keeps its alone check.
  • inner-bom-under-line-error and one-diagnostic-per-line now have checks of their own.

5. Updates refuse regressions.

  • A plain BOM_MATRIX_UPDATE=1 now refuses a line counted further from beancount than the known list recorded, or than beancount's own count for a row that matched at the last update. This applies even when main is no closer.
  • It knows which rows matched from a new list, data/bom_combination_matrix_matching.tsv: 64-bit FNV-1a hashes of the sources, 6,718 rows, seeded from the last commit's 6,715. A row in neither list is new to the table and has nothing to regress from.
  • The matching list is excluded from typos in .typos.toml, like the parity manifest: its hex hashes read as misspellings.
  • Accepting a regression needs BOM_MATRIX_RELABEL=1 and a reason written by hand in the known row's new optional fourth column. Updates keep that reason.
  • How I confirmed it:
    • I edited one known row so its recorded count was beancount's 0, against rledger's 1 and main's 4 ( <BOM><BOM>kk:<BOM>\t-2.5\t-2.5).
    • UPDATE fails. UPDATE with RELABEL also fails ("1 row(s) count a line further from beancount than the known list recorded"). With a reason in the fourth column it passes and keeps the reason.
    • I could not find a parser mutation that worsens only lines main is further off on. The three I tried (X5: report inner-BOM runs; X6: drop the heading rest; X7: report BOM-led account tokens) each also push lines past main, and fail that check first.

Linearity guard

  • Under the mutation runs' load the round-11 1 s cap was close: one linear shape alone takes 0.64 s.
  • The short run now gets 4 times a BOM-free reference of the same size, timed just before it, plus 1 s. The slowest linear shape takes about 0.6 of the reference. The short run also runs on its own thread with that budget.
  • Q6c fails in 10 s ("the short run took over 4.3s: quadratic").

Mutations

Each was run with BOM_MATRIX_UPDATE=1, and none wrote a list.

Mutation Result
R8-1 fails
R8-2 fails: 1 unexplained input
R8-3 fails
R8-4 fails
R8-5 fails: unit test
R8-6 fails
M7b fails
M8 fails
M9 fails
N1 fails: 1 line past main; unit test
S1 fails
S2a fails
S2b fails
S2i (inner-bom by shape only, new) fails
S3a fails
S3b fails
S3c fails
T1 fails
Q6c fails: guard
X5 fails: 45 lines past main
X6 fails: 133 lines past main
X7 fails: 324 unexplained inputs

S2k is gone with kinds_hold.

Counts in round 12

  • Table: 13,406 rows, 10 columns. Known list: 6,688 rows. Texts list: 8,942 rows. Matching list: 6,718 rows.
  • Accepted further-than-main lines: 1,082, made up of:
    • 676 like-main-without-bom
    • 109 indented-line-after-error
    • 108 line-after-error-line
    • 8 indented-line-after-heading
    • 94 bom-glued-to-account&mid-line-hash-bang
    • 75 bom-glued-to-account
    • 6 one-diagnostic-per-line
    • 5 mid-line-hash-bang
    • 1 bom-glued-to-account&extra-construct-error
  • Gates: STRICT baselines pass. Tests: parser, lsp, loader and wasm pass (1,921 passed, 0 failed), and so does wasm-pack test --node (35). Caches stay at 70/95, as main is still d728311.

Review round 13

The parser is unchanged again: parity --check passes at 78,461. Every change is in the test harness and the generator.

1. A stale or cut matching list now fails.

  • The non-update path checks that the hashes of the table rows not in computed are exactly the matching list. It reports the missing and extra hashes, as the known and texts checks do.
  • The list is also sealed. Its last line, # total <n> <digest>, holds the row count and a hash of the rows, and both modes check it before the list is used. So a list cut down to its header fails even under BOM_MATRIX_UPDATE=1 ("the matching list has no # total line").
  • The review's repro now goes red:
    • With the list cut to its header, the plain test fails.
    • With line 12874's bc changed to 3:2, the update fails too.
  • I also checked the guard on a row it actually reaches. I edited $n0 so beancount counts 0 where rledger and main count 1, a regression from matching that is no worse than main:
    • BOM_MATRIX_UPDATE=1 fails, and so does adding BOM_MATRIX_RELABEL=1.
    • A hand-added known row with the new counts and no reason still fails.
    • A reason written for other counts fails.
    • A reason written for exactly the new counts passes and is kept.
    • With the matching list cut down, the update fails on the seal.

2. one-diagnostic-per-line is gated.

  • The fallback now needs later_grammar_is_the_difference(): rledger counts beancount's count less exactly beancount's grammar errors after the line's first error.
  • pop-without-push is asked first. It covers 6 known rows that were mislabelled before.
  • line-start-bom-before-comment covers every line start rledger's lexer, like beancount, skips (skipped_line_start, as in beancount_ignores_line): ;, %, !, *, :, &, ?, and a # not before a tag character. It now has 45 known rows, up from 7 (corrected in round 14: this said 46, and round 14 moves 32 of them back to bom-account-under-line-diagnostic).
  • New causes:
    • eof-error-on-last-line (3 rows): beancount reports an end-of-file error on the line after the last, and rledger reports the same number on the last line. Example: 2024-01-02 *\n <BOM>1:A{.
    • bom-free-line-as-on-main (5 rows): a line with no BOM that rledger counts exactly as main does.
  • New hand-kept file data/bom_combination_matrix_exceptions.tsv with 16 lines that no rule explains. Each lists rledger's, beancount's and main's counts, beancount's later grammar errors, and rledger's count with the line's inner BOMs made $. A listed line that a rule explains or that now matches fails the test as stale.
    • These are the inner-BOM lines the $ rewrite does not fix, mostly indented probe lines. One is $x <BOM>Ü:A\t* A.
    • An unexplained line's failure message now prints those same facts.
  • Known list: one-diagnostic-per-line went from 133 rows to 99.
  • Mutation H (the later-grammar check weakened to rl >= 1) now fails: 15 listed exceptions become stale.

Docs

  • The doc of parts_hold and the accepted file's header give the measured hash-bang shares: usually -2 to -4, -1 on one row, and positive (+1) on one row.
  • The fallback's comment says what it now checks.

Nits

  • scripts/bom-combination-matrix.py exits unless beancount.__version__ == "3.2.3".
  • Regression reasons are tied to their counts. A known row carries <for counts> <reason> as its fourth and fifth columns.
    • An update accepts a regression only with BOM_MATRIX_RELABEL=1 and a reason written for exactly the new counts.
    • It keeps a reason only while the counts are those, so a later change needs a new reason.
  • The route for a row that matched is spelled out in the refusal message and the known list's header: add its known line by hand, with the new counts in both count columns.
  • The bypass is closed. A row whose hash is in the matching list regresses from beancount's counts, whatever known row was added by hand since.
  • inner_boms_are_the_difference no longer calls inner_in, which is removed.

Mutations

Each was run with BOM_MATRIX_UPDATE=1, and none wrote a list.

Mutation Result
R8-1 fails: 33 unexplained inputs
R8-2 fails: 1 unexplained input
R8-3 fails: 3 unexplained inputs
R8-4 fails: 1 unexplained input
R8-5 fails: unit test
R8-6 fails: 324 unexplained inputs
M7b, M8, M9 fail
N1 fails
S1, S2a, S2b, S3a, S3b, S3c, T1 fail
Q6c fails: guard
S2i (inner-bom check always true) fails
H (later-grammar check weakened) fails

Counts in round 13

Review round 14

This round merges origin/main and moves the WASM cache. The parser is unchanged: parity --check passes at 78,461, and the only source change is a comment in the lexer. Everything else is tests and the matrix guard.

1. A BOM before a posting's price or cost (known change vs main, tracked in #2954).

2. The trailing-pending rule of holds_an_invalid_token is tested.

  • test_parse_bom_alone_at_eof_after_directive_is_one_error: 2024-01-03 open Assets:C USD "BAD" <BOM> at the end of the file, with no final newline, is one error (P0026) and the open is kept. bean-check 3.2.3 reports one error too (Invalid token: '').
  • Mutation: pending_boms.is_some() made false fails this test.

3. The line-start test in the lexer's Err arm is tested.

  • test_tokenize_indented_bom_runs_to_next_blank: through the public tokenize() (whitespace dropped), x\n <BOM>"y" z\n gives Error("<BOM>\"y\""), Error("z").
  • Mutation: dropping span.start == self.last_newline_end fails it.
  • Dropping at_line_start instead passes every parser test (cargo test -p rustledger-parser --all-features, lib and integration). I agree it is equivalent today: last_newline_end moves only where at_line_start is set, and new_mid_line always starts past offset 0. I kept the flag and wrote this in a comment there: it keeps new_mid_line's promise (no line-start rule for its first token) without relying on that offset.

4. line-start-bom-before-comment no longer takes BOM-led account lines.

  • The rule now also requires that beancount's lexer does not read the line's start as an ACCOUNT (BomRoles::account_at). For <BOM>:A$x! it does, so no invalid token runs through the line, and the rule's comment did not hold.
  • The 32 rows go back to bom-account-under-line-diagnostic, which verifies them (account_grammar_error_is_the_difference). Known rows: line-start-bom-before-comment 45 to 13, bom-account-under-line-diagnostic 1 to 33. The round-13 text said 46; it was 45, and I corrected it there.
  • Mutation: dropping the new conjunct fails the known-list check (the 32 rows relabel).

5. Exceptions.

  • The six exceptions with a mechanism (file order 0, 4, 6, 9, 11 and 14) now have a verified cause. like-main-without-bom is also asked last, on a line no further from beancount than main: the analog columns must show beancount counting the BOM-free line as it counts this one, and main counting it as rledger does here. Asked last, it takes no line from another cause. The six lines are removed from the exceptions file, which keeps 10.
  • Each reason's counts are now checked. reason_counts reads rledger counts X where beancount counts Y (main Z) from every reason (a reason without it panics), and listed-exception applies only when those are the line's counts now. Otherwise the line is unexplained, and the message names the counts the listed reason was written for. The file's header says so.
  • Mutations:
    • The late like-main-without-bom branch disabled: fails, 6 inputs unexplained.
    • One reason's rledger count edited (1 to 2): fails, "a listed exception written for rledger 2 / beancount 2 / main 1, not these counts".
    • The same edit with the count check disabled: passes, so the check is what catches it.

6. Merge and caches.

Counts in round 14

  • Table: 13,406 rows. Matching list: 6,718 rows, unchanged. Texts list unchanged. Exceptions: 10, down from 16. Accepted further-than-main lines: 1,082, unchanged.
  • Known-list labels that moved: line-start-bom-before-comment 45 to 13, bom-account-under-line-diagnostic 1 to 33, listed-exception 16 to 10, like-main-without-bom 671 to 677.

Gates

  • cargo fmt --all --check, clippy --all-features --all-targets -D warnings, and RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps pass.
  • cargo test --all-features: parser 938, loader 427, lsp 404 and wasm 175 passed, 0 failed. wasm-pack test --node passes (38).
  • Both STRICT baselines pass.
  • Parity: --self-test passes. --check with beancount 3.2.3 at the pinned fuzz commit 9bc79f4f reports no regressions, at 78,461 of 111,323 inputs.

Review round 15

The parser's output does not change in this round: parity --check still matches 78,461 of 111,323 inputs, and a 420,000-input differential run against the round-14 head shows no difference. The round removes two line-start checks that never changed any output, and adds tests to the matrix classifier.

1. Two of the three line-start BOM checks were no-ops (F1).

  • holds_an_invalid_token: removed. The check can never fire. This function walks only an open or a transaction. The node's header starts with its date, and every later line the parser takes into the node starts with indentation (is_indented_directive_continuation, is_indented_transaction_body_line). So a line that a BOM starts becomes an ERROR_NODE of its own, and its BOM token is never inside the node. The before tracking was only there for this check, so it goes too, and bom_token_starts_its_line folds back into is_line_start_bom_token. A comment at the function says why it needs no line-start test.

  • quiet_after_invalid_tokens: removed. This check is reached, but it changes nothing. Without it, a line-start BOM counts as its line's first invalid token, which is how beancount reads it. That line is always an ERROR_NODE line:

    • Its line error (and the secondary BOM error) starts at the BOM, not after it.
    • Every other error on the line is a kind this pass keeps anyway: an invalid token's error (at or inside an ERROR_TOKEN) or an invalid date.

    Removing the check makes this pass agree with report_invalid_tokens_of_error_line, which already treats that BOM as the line's first invalid token. The doc comment says it changes no output today, and why.

  • I looked for an input where either check changes the output and found none:

    • 420,000 seeded random inputs (line-start BOM runs, BOMs before indentation, metadata and postings, BOM-led accounts, invalid dates, strings, comments, braces).
    • Each check was dropped on its own and the output compared with the round-14 head: 0 inputs differ.
    • The final build (both checks dropped) also matches the round-14 head on all 420,000 inputs.
  • So the "What" section no longer says that all three places go through one rule. Only report_invalid_tokens_of_error_line asks is_line_start_bom_token, because only an ERROR_NODE line can hold such a BOM. Its doc now says so.

2. The late like-main-without-bom rule is tested directly (F2).

  • test_cause_like_main_without_bom_needs_beancounts_analog_count calls cause() with made-up counts for one line: rledger 1, beancount 2, main 1, and main 1 on the BOM-free analog.
    • When beancount counts the analog 2 (the same as here), the line is like-main-without-bom.
    • When beancount counts the analog 3, the BOM changed beancount's count. The line then stays unexplained (None), even though main counts the analog as rledger counts the line.
  • Mutation: dropping get(&counts.analog_bc, l) == b from the late branch fails this test (Some("like-main-without-bom") where None is expected). As the review found, the matrix test alone still passes under that mutation.

3. The "BOM in indentation" row of the Before / after table was stale (F3).

  • The input is the two open lines, then 2024-01-02 * "x" / <BOM>Assets:A 1 USD / Assets:B -1 USD. I checked each tool:
    • bean-check 3.2.3: 1 parse error, 4: Invalid account name: <BOM>Assets:A (a ParserError from parse_file, not a load-time check as the row said). It also reports the validation error 3: Invalid reference to unknown account '<BOM>Assets:A'.
    • main: P0012 + P0026, then E3004 and E3001.
    • this PR: P0026 only, then E3004 and E3001.
  • So this PR fixes this row: its one parse error matches beancount's count and line. The row now says so.

4. reason_counts reads the counts only from the start of a reason (nit).

  • It used to find the first rledger counts anywhere in a reason. It now strips that prefix, reads X where beancount counts Y (main Z) in order, and panics with the expected form when a reason does not start that way.
  • All 10 exceptions already start that way.
  • Tests: test_reason_counts_reads_the_leading_counts, and test_reason_counts_rejects_counts_not_at_the_start (should_panic).
  • Mutation: reading from anywhere again (split_once instead of strip_prefix) fails the second test.

5. Pre-existing BOM recovery gaps: new issue #2956.

Caches. No change. The parser's output is unchanged, so WASM stays at 100 and the loader at 70 (origin/main was 4bc5bd8 at this round; see round 16).

Gates

  • cargo fmt --all --check, clippy --all-features --all-targets -D warnings, and RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps pass.
  • cargo test --all-features: 941 parser tests (938 + 3 new), 427 loader, 404 lsp and 175 wasm passed, 0 failed. wasm-pack test --node passes (38).
  • Both STRICT baselines pass.
  • Parity: --self-test passes. --check with beancount 3.2.3 at the pinned fuzz commit 9bc79f4f reports no regressions, at 78,461 of 111,323 inputs.

Review round 16

The round found the parser's behavior clean and one test gap.

Fixed: half of the late like-main-without-bom condition was untested. Dropping && get(&counts.analog_main, l) == r passed every test, because the round-15 test fixed main's analog count at rledger's. late_analog_counts now takes main's analog count, and the test (renamed test_cause_like_main_without_bom_needs_both_analog_counts) adds a case where main counts the analog differently from rledger's count here: the line stays unexplained. With that half dropped the test fails.

Merged origin/main (e6c8054, #2950, loader options and tests only): clean, no conflict. Caches: unchanged at WASM 100 and loader 70, still above main (97 and 69) and claimed by no other open PR (WASM 98 #2944, 99 #2945 and #2946, 101 #2952; loader 71 #2945, 73 #2944).

Gates: cargo fmt --all --check, clippy on the parser --all-features --all-targets -D warnings, the matrix test file (4 passed) and a warm cargo check --workspace --all-features --all-targets pass on the new head. The review ran the full gate set on 2c9b736 (fmt, clippy, doc, parser 941, loader 427, lsp 404, wasm 175, STRICT baselines, wasm-pack test --node 38); this round changes only the matrix test file.

Review round 17

The round found the parser's behavior, the merge, this body and every gate clean. Its only findings were untested guards in the matrix test's classifier, cause(): a 69-mutant sweep (each conjunct or disjunct forced true or false, or a branch removed) left 12 survivors. This round pins every one that can change a result at once, rather than one per round.

New direct cause() tests (matrix test file), on made-up counts for line 3 (line3_counts, line3_cause, with_account_role), each with a case where the rule holds and one where the guard alone turns it away:

  • test_cause_bom_free_line_as_on_main_needs_main_count: bom-free-line-as-on-main needs r == m, so a BOM-free line counted differently from main (a real regression) stays unexplained.
  • test_cause_listed_exception_needs_its_reason_counts: the first entry of the exceptions file, on its own table row's counts (row_counts, split out of check_row), is listed-exception, and stops being one when main's count moves.
  • test_cause_bom_glued_to_account_needs_an_account_on_the_line and test_cause_glued_in_error_line_needs_an_account_on_the_line: both glued-BOM causes need a BOM-led account on the line.
  • test_cause_glued_in_error_line_needs_more_errors_than_beancount: bom-glued-to-account-in-error-line never explains a line short of beancount's count.
  • test_cause_inner_bom_under_line_error_needs_fewer_errors_and_a_bom_diagnostic: inner-bom-under-line-error needs r < b and a P0026 on the line (boms > 0, which the reviewer thought probably equivalent: it is not, as the test shows).
  • test_cause_brace_hash_before_tag_needs_more_errors, test_cause_line_start_bom_before_comment_needs_fewer_errors, test_cause_pop_without_push_needs_fewer_errors: the direction guard of each.

The reviewer's other probably-equivalent guard, r > b in bom-glued-to-account-in-error-line, is pinned by the test above: with a made-up P0026 count, the rewrite can gain one and keep a non-BOM error, which the rule would otherwise take for the mirror image.

Equivalent guards, verified and commented at their sites:

  • The glued gate (now the named glued_asked): r != b (the only caller, check_row, skips a line with b == r) and boms > 0 (GLUED, the first part of each glued cause, needs 0 < share <= f.boms; the check only spares a parse).
  • line-start-bom-before-comment's text.starts_with(BOM): without a BOM before it, beancount ignores a skipped line start, so b == 0 and r < b already fails. (Wrong: corrected in round 18, the guard is needed.)
  • one-diagnostic-per-line's r < b: later_grammar_is_the_difference's checked_sub needs b >= r, and b == r never reaches cause.
  • Removed: l > 0 in the first recovery filter. recovery() is already None on line 0, so the filter reads recovery().filter(|_| facts.alone_matches()), with a comment.

Full sweep, re-run on ad6bcff (one scratch copy with its own target dir, mutants run one after another; the only later change, 2a02bd6, is a clippy fix outside cause()). 72 mutants, built afresh over the current cause() (every atom forced true or false where that can change a path, and every branch removed): 68 killed, 4 survive, each one of the equivalent guards above.

Site Mutant Result
recovery closure (r <= b, l == 0, heading, after-error, line-after-error) 11 all killed
recovery-first filter 2 killed
early like-main-without-bom 4 killed
failed-push-still-pushed, eol-reported-on-next-line 3 killed
invalid-account-after-invalid-token 4 killed
glued gate: account_in true, branch removed 2 killed
glued gate: r != b true 1 survives (equivalent: caller skips b == r)
glued gate: boms > 0 true 1 survives (equivalent: GLUED needs share <= boms)
bom-glued-to-account-in-error-line (r > b, account_in, rewrite, branch) 4 killed
second recovery, mid-line-hash-bang, lone-capital-glued-to-tokens 3 killed
brace-hash-before-tag 3 killed
line-start-bom-before-comment: r < b, skipped start, account, branch 4 killed
line-start-bom-before-comment: starts_with(BOM) true 1 survives (equivalent: no BOM means b == 0)
inner-bom-under-line-error 4 killed
bom-account-under-line-diagnostic 3 killed
pop-without-push 3 killed
one-diagnostic-per-line: check true, branch removed 2 killed
one-diagnostic-per-line: r < b true 1 survives (equivalent: checked_sub needs b >= r)
eof-error-on-last-line 2 killed
bom-free-line-as-on-main 3 killed
listed-exception 2 killed
extra-construct-error 6 killed
late like-main-without-bom 3 killed

Merged origin/main (526f833, #2945). Conflicts in CHANGELOG.md and an LSP test module: both sides kept. Caches: main took loader v71 and WASM v99, so the loader cache moves to v72 (LOADER_CACHE_VERSION_PIN and both FIXTURE_VERSIONs too), with one v72 note naming #2931 and what a stale blob would serve; the v70 note is gone and main's v71 note now says v70 was held here and never released. WASM stays at v100, above main's v99, its note now saying loader v72. Allocated to open PRs: loader 73 (#2944); WASM 101 (#2952), 102 (#2944). (Corrected in round 18: #2946 holds no cache version.)

Gates (on 2a02bd6, the cache constants moved, so the full set): cargo fmt --all --check, clippy --all-features --all-targets -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, tests for parser (950 passed), loader (442), lsp (408) and wasm (178), both STRICT baselines, wasm-pack test --node (38), parity --check (no regressions, 78,461 of 111,323) and a warm cargo check --workspace --all-features --all-targets.

Review round 18

The round found the parser's behavior and every gate clean. Its findings were in the cache notes, this body and the matrix test's classifier, cause().

Cache allocations corrected. #2946 holds no cache version (its diff changes no cache constant). Checked against each open PR's diff: loader 73 is held by #2944; WASM 101 by #2952 and 102 by #2944. The loader v72 note now says "(v73 is held by #2944.)", the WASM v100 note "v101 is held by #2952 and v102 by #2944", and the Caches bullets and the round-17 merge paragraph above say the same. Main's own v99 note ("v98 is held by #2944") is outside this PR's hunks and is left alone.

line-start-bom-before-comment's BOM guard is needed (round 17 called it equivalent: wrong). beancount's error for the line before can land on a skipped line start: 2024-01-02 open then ;c gets unexpected EOL, expecting ACCOUNT on the ;c line (bean-check 3.2.3), so r < b holds on a BOM-free skipped start. The guard stays, its comment says why, and test_cause_line_start_bom_before_comment_needs_a_bom pins it on real counts (bean-check and parse_error_lines): ;c on line 4 is beancount 1, rledger 0, so bom-free-line-as-on-main; <BOM>;c is beancount 2, rledger 1 (its P0026), so line-start-bom-before-comment. Without the guard the first becomes line-start-bom-before-comment, and the test fails.

inner-bom-under-line-error, on a real row. inner_boms_are_the_difference now checks that the line has a BOM inside an invalid token, as its doc says; the matrix test still passes, so every real row it explained has one. On counts rledger produced the check is equivalent (with no inner BOM the rewrite changes nothing, so the line counts rl, and the cause asks with rl < bc), which a comment at the site says; it keeps made-up counts from passing on an empty rewrite. The test now reads its own table row ($n0 x1<BOM>y: beancount 2, rledger 1 with one P0026, main 1, the BOM inside x1<BOM>y) and checks it is turned away with no inner BOM, with no P0026, or with rledger counting more than beancount, plus the made-up case (rledger 0 on 2024-01-02 * "x" <BOM>q, which rledger counts 1) that only the new check turns away. The glued tests' docs now say their counts and account role are made up to reach the rule.

Older cause() guards:

  • pop-without-push no longer strips BOMs before poptag / popmeta: <BOM>poptag #t is one invalid token to beancount (Invalid token: '<BOM>poptag', no pop error), so the strip was unreachable. Removed, with a comment.
  • block_err's look past the indentation (trim_start_matches(is_blank).starts_with(BOM)) is pinned by test_cause_indented_line_after_error_sees_an_indented_bom (made-up counts: an indented <BOM>Assets:A line beancount counts nothing on, then an indented line rledger counts 1 and main 0).
  • Commented as equivalent at their sites: the recovery closure's r <= b (the only caller skips b == r, so it is r < b), and the order of GLUED and GLUED_HASH_BANG (both cannot hold: GLUED alone takes the whole difference, and a hash-bang share is never zero).

Full sweep, re-run on the final cause() (one scratch copy with its own target dir, mutants run one after another): 82 mutants (every atom forced true or false where that can change a path, every branch removed, each glued entry removed, the glued order swapped, and the new in-span check forced true): 78 killed, 4 survive, each commented as equivalent at its site.

Site Mutants Result
recovery closure (l == 0, heading, after-error, line-after-error) 10 all killed
recovery closure: r <= b as r < b 1 survives (equivalent: caller skips b == r)
block_err (bc > 0, BOM after indentation, BOM at column 0 only) 3 all killed
recovery-first filter 2 killed
early like-main-without-bom 4 killed
failed-push-still-pushed, eol-reported-on-next-line 4 killed
invalid-account-after-invalid-token 4 killed
glued gate: account_in true, gate false 2 killed
glued gate: r != b true 1 survives (equivalent: caller skips b == r)
glued gate: boms > 0 true 1 survives (equivalent: GLUED needs share <= boms)
glued list: each entry removed 3 killed
glued list: GLUED and GLUED_HASH_BANG swapped 1 survives (equivalent: both cannot hold)
bom-glued-to-account-in-error-line 4 killed
second recovery, mid-line-hash-bang, lone-capital-glued-to-tokens 3 killed
brace-hash-before-tag 3 killed
line-start-bom-before-comment (now with starts_with(BOM) true) 5 all killed
inner-bom-under-line-error, and the new in-span check 5 all killed
bom-account-under-line-diagnostic 3 killed
pop-without-push 3 killed
one-diagnostic-per-line: check true, branch removed 2 killed
one-diagnostic-per-line: r < b true 1 survives (equivalent: checked_sub needs b >= r)
eof-error-on-last-line 2 killed
bom-free-line-as-on-main 3 killed
listed-exception 2 killed
extra-construct-error 6 killed
late like-main-without-bom 3 killed

origin/main had not moved (still 526f833), so no merge.

Gates: cargo fmt --all --check, clippy --all-features --all-targets -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, tests for parser, loader and wasm (1572 passed, 0 failed) and a warm cargo check --workspace --all-features --all-targets.

Review round 19

The round found the parser and the merge clean. Its findings were in the matrix test's classifier, cause(), and its helpers: 123 mutants, 34 surviving, 27 of them undocumented. This round kills every one that can change a result and comments the rest at their sites.

New cause() tests (matrix test file; every count not said to be real is made up to reach the rule, and each test doc says so):

  • test_cause_indented_line_after_error_sees_an_indented_bom gains a third case: the BOM inside the header's string (2024-01-02 * "x<BOM>"; bean-check 3.2.3 and rledger both report nothing for the input) is not a line that starts with a BOM, so block_err stays false. Kills starts_with as contains.
  • test_cause_pop_without_push_needs_fewer_errors gains 2024-01-02 * "poptag": a poptag that does not start the line is no pop, so the line stays bom-free-line-as-on-main.
  • test_cause_glued_construct_needs_a_positive_construct_share: a glued share of 2 with a construct share of -1 adds up, but is not bom-glued-to-account&extra-construct-error; +1 is.
  • test_cause_glued_in_error_line_needs_a_non_bom_error_in_place: the P0026s go by exactly the difference, but no non-BOM error comes in their place (2024-01-02 open Assets:X counts 0), so bom-glued-to-account-in-error-line does not hold.
  • test_cause_line_start_bom_before_comment_needs_a_skipped_start: <BOM># c is the cause; <BOM>#t and <BOM>#- (a tag after the #) are not.
  • test_cause_line_start_bom_before_comment_needs_no_account_at_its_start: an account on line 1 does not turn the rule away; one at the line's own start does (account_at's ==).
  • test_cause_brace_hash_before_tag_needs_more_errors gains {#$: no tag character after the {#.
  • test_cause_eof_error_on_last_line_needs_each_condition: each of the line check, rl[eof] == 0 and the sum, dropped alone, turns a case into eof-error-on-last-line.
  • test_cause_eol_reported_on_next_line_needs_a_date_alone: <BOM>2024-01-02 is a date alone (the BOM strip), 2024-01-021 is not (exactly ten characters).
  • test_cause_lone_capital_glued_to_tokens_skips_a_leading_bom: <BOM>A$.
  • test_cause_invalid_account_after_invalid_token_needs_an_account: <BOM>q Üx:A is the cause, <BOM>q Üx (no :) is not.
  • Both "needs an account on the line" tests gain an account role on line 1 only, which the sweep found unpinned (account_in forced to "any account").

Equivalent, commented at the site with the reason:

  • eof_error_on_last_line's bc[eof] > 0: with the other three holding and bc[eof] 0, the line has b == r, which check_row skips.
  • ordinary_inner_boms's span filter (the reviewer's item 12): rewriting another line's inner BOM to $ keeps that line an error line with the same start, indentation and strings, so the asked line's count does not move. I tried to break it with line-start, glued, header, push and pop lines before the line, each with its BOM rewritten; none moved the count. So I documented it rather than adding a test.
  • glued_boms_replace_construct's > as >=: equality means all_after == bc, so GLUED holds and is asked first.
  • The header range 3..l vs 4..l (unwrap_or(3) gives line 3 anyway); later_grammar_is_the_difference's rl >= 1 (only bc 0 passes without it, a line with bc == rl); the hash-bang check in parts_hold (with no mid-line #! / #+ the share is 0 on the table's rows, turned away); the dead (r, b) update after HASH_BANG (always the last part); line_span's end (no account or inner BOM starts at a \n).

Simplified: skipped_line_start no longer checks for a \n after the first character (s is one line). An unknown part in parts_hold is unreachable! (every caller passes the three parts). GLUED's share <= 0 is now share < 0, leaving zero to the shared zero check. That check is therefore no longer redundant: the matrix test fails without it. Its comment and the GLUED / GLUED_HASH_BANG order comment now point at each other, since the order changes no result only because of the check.

Sweep, re-run on the final file (each mutant applied, the matrix test binary run, the file restored, one after another): 51 mutants, covering every one listed in the review, the previously documented ones, and 17 more across the helpers. 36 killed, 15 survive, each commented as equivalent at its site:

Mutants Result
Review items A1 to A11 (block_err contains, pop contains, construct share < 0, in-error-line non-BOM conjunct, # tag exclusion and its -_/., brace tag check, eof line / rl[eof] / sum, date >= 10 and BOM strip, lone-capital strip, account :, account_at <=) 15, all killed
Previously killed (block_err column 0 only, inner in-span check, line-start BOM check) 3, all killed
Extra (GLUED share < 0 / > boms dropped, parts sum, construct sign, in-error-line gone, indented strip, hash-bang position and BOM filter, skipped ; and * arms, eof alternatives, heading strip, block_err bc > 0, date dash, account_in, lone-capital \r) 17, all killed
share == 0 dropped killed (now needed, see above)
eof bc[eof] > 0, inner span filter, in-error-line >= 3, survive (equivalent, commented)
Review items B and C (header range, rl >= 1, hash-bang check, dead update, GLUED <= 0, unknown part, line_span end) 7, survive (equivalent, commented)
Previously documented (glued order, recovery r < b, glued gate r != b and boms > 0, one-diagnostic r < b) 5, survive (equivalent, commented)

(share == 0 is counted among the 36 killed.)

Merged origin/main (8773d67, #2944). Conflicts in CHANGELOG.md (both entries kept) and the two cache.rs files. Caches: loader 74 (LOADER_CACHE_VERSION_PIN and both FIXTURE_VERSIONs too) and WASM 104, above main's 73 / 102 and #2952's WASM 103. One note per version: the v74 and v104 notes replace this PR's v72 and v100 notes; main's v71 note now says v70 and v72 were held here and never released, and the v104 note says v100 (here) and v101 (#2952) were never released. #2944's v98 and v102 notes are unchanged. The matrix test passes unchanged after the merge.

Gates (on 2b82468): cargo fmt --all --check, clippy --all-features --all-targets -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, tests for parser (973 passed), loader (442), lsp (409) and wasm (178), 0 failed, both STRICT baselines, wasm-pack test --node (42), parity --self-test, parity --check (no regressions, 78,461 of 111,323) and a warm cargo check --workspace --all-features --all-targets.

Review round 20

The round's findings were all in the matrix test's classifier, cause(), and its helpers, plus one cache note. This round's sweep is wider than the review's: 451 mutants over cause() and every helper it calls (and holds), run one after another on the final file, which was checked byte-identical after the sweep. 2 of them do not compile, 409 are killed, and 40 survive, each commented as equivalent at its site. No survivor is undocumented.

Classifier changes:

  • date_alone now asks the parser's own parse_date (beancount's DATE, [0-9]{4,}[-/][0-9]+[-/][0-9]+, that is a real calendar date) of the line with trailing blanks and a CRLF's \r trimmed. So 2024/01/02 and 2024-01-021 (January 21 to beancount) are dates alone, as bean-check 3.2.3 reports them (its unexpected EOL on the next line). It no longer strips leading BOMs: beancount reads <BOM>2024-01-02 as one invalid token and reports nothing on the next line (bean-check and rledger both count it 1 on its own line), so the round-19 test that called it a date alone was wrong and now says the opposite. An invalid date (2024-13-45) is reported on its own line on both sides, so it is no date alone either. The matrix test's known list is unchanged by this.
  • holds is one match on the cause; its two standalone checks share alone_counts. parts_hold checks the construct sign in the construct arm. Same behavior; the string == chains were the source of meaningless lexicographic mutants.
  • The parts_hold hash-bang comment (item 16) was wrong and is rewritten: the analog rewrites every #! / #+ of the input past a line's first character, including one after a line-start BOM (<BOM>#!x $y: rledger 1, the analog 2), so the check is needed. A new made-up-count test pins it.
  • ordinary_inner_boms's $ (item 17) is not a true equivalent: an x turns $n0 t<BOM>n into $n0 txn, which rledger counts 1, not 2. A new real-count test pins it, and the comment says why it is a $.

Per finding (real counts are bean-check 3.2.3 and main's parse_error_lines, recorded by hand in the tests through recorded_row; made-up counts are labeled in each test's doc):

Item Outcome
1 date_alone trim killed: real 2024-01-02 , 2024-01-02 , 2024-01-02 \r, 2024-01-02\t, 2024-01-02\r (bc 4:1, rl 3:1), both lines
2 line-start contains killed: real 2024-01-02 open then ;c <BOM> (line 4 stays like-main-without-bom)
3 : & ? arms killed: real <BOM>:x $y, <BOM>&x $y, <BOM>?x $y, plus !, %, # (bc 2 or 3, rl 1)
4 strip one BOM killed: real <BOM><BOM>;c $y
5 BOM-led poptag killed: real 2024-01-02 open then <BOM>poptag #t (line 4 stays like-main-without-bom); the comment at the rule cites the test
6 brace tag chars killed: real "x" {#_, {#., {#a (bc 1, rl 2); made-up {#-, {#/, {#1 (rledger counts those as beancount does)
7, 8 eof sum killed on made-up counts (bc {3:1,4:1} / rl {3:2}; bc {4:1} / rl {} / main {4:1})
9 later-grammar == killed on made-up counts (later 0 and 2 against a difference of 1)
10 in-error-line gone == killed on made-up counts (one P0026 going against 2, two against 1)
11 lone-capital list every member pinned: real A%y, 2024-01-02 A| "x", 2024-01-02 * "x" A|, 2024-01-02 A" "x" (bc 1, rl 2), the \r on table rows; the other 16 made up, since rledger counts them as beancount does in every context tried (header, posting amount, price, flag, line start, open)
12 date dash/digit, slash dates the rule is now parse_date; slash dates and 2024-01-021 added and tested on real counts
13 alone_matches on None killed: test_cause_recovery_first_needs_a_matching_count_alone (made-up)
14 arms needing a next char killed: <BOM>*, <BOM># are not the cause, <BOM>; and <BOM>*x are (made-up; rledger counts each 1, as beancount does)
15 hash_bang_analog mid_line killed: test_hash_bang_analog_rewrites_only_past_a_lines_start
16 hash-bang comment rewritten with a true argument, and pinned by a made-up test
17 four equivalents words filter, ordinary_accounts name, b vs f.bc: commented; $ vs x: not equivalent, killed (above)
18 WASM notes v102's note says v100 and v101 were never released; v104's no longer repeats v93, v95, v100 or v101

Sweep, by function (killed / survive; survivors all commented as equivalent):

Function Mutants Killed Survive
cause (plus 1 not compiling) 182 162 19
holds, alone_counts 44 43 1
parts_hold 28 22 6
eof_error_on_last_line 28 23 5
LineFacts checks 27 26 1
lone_capital_glued 27 27 0
skipped_line_start 21 21 0
brace_hash_before_tag 11 11 0
hash_bang_analog 11 11 0
glued_boms_replace_construct 9 8 1
is_blank 9 9 0
date_alone 8 8 0
mid_line_hash_bang 8 8 0
BomRoles 6 5 1
line_span 6 4 2
ordinary_accounts, ordinary_inner_boms 8 5 3
account_after_bom, rledger_lines 8 8 0
exceptions, reason_counts (1 not compiling), strip_boms, indented, words, standalone_count 10 8 1
Total 451 409 40

The mutants: every comparison and && / || in those functions swapped (214, generated), and 237 by hand: every conjunct and disjunct dropped, every branch removed, every match arm removed or forced, every list and set member removed, starts_with and contains swapped, every trim removed, stripping one BOM for all, boundary moves, the glued list's entries removed and reordered, and each check in holds forced.

The 40 survivors, by argument (each commented at its site): in cause (19), nine r > b / r < b as >= / <= and two l == 0 as l <= 0 (the only caller skips b == r; a line number), the recovery r <= b as r < b (twice, as an operator and by hand), the glued gate's r != b and boms > 0 (boms >= 0, and each dropped), the header range, the glued order and the one-diagnostic r < b; in eof_error_on_last_line (5), both == of the line test as >= and rl[eof] <= 0 (no line past eof has a count; a count), and bc[eof] > 0 as >= and dropped; in line_span (2), k + 1 >= l (only line 0's span changes, which nothing reads) and the end taking the \n; in parts_hold (6), GLUED's and the construct arm's share <= 0 (three: a zero share is turned away below), b vs f.bc, the dead (r, b) update and the unknown part; glued_boms_replace_construct's >=; later_grammar's rl >= 1; account_in by an account's end (an account holds no \n); the two other account names and the span filter of the rewrites; the words filter; and holds's w.bc <= bc_alone (with alone == rl and bc == bc_alone the first test already holds).

New tests (matrix test file): test_cause_recovery_first_needs_a_matching_count_alone, test_cause_line_start_bom_before_comment_takes_each_skipped_start, test_cause_brace_hash_before_tag_takes_each_tag_character, test_cause_one_diagnostic_per_line_needs_exactly_the_later_errors, test_cause_glued_in_error_line_needs_exactly_the_difference, test_cause_inner_bom_under_line_error_rewrites_to_no_token, test_cause_lone_capital_glued_to_tokens_takes_each_listed_character, test_hash_bang_analog_rewrites_only_past_a_lines_start, test_is_blank_takes_a_space_or_a_tab, test_rledger_lines_puts_an_unclosed_push_on_line_zero, test_cause_glued_hash_bang_needs_a_hash_bang_on_the_line, test_cause_mid_line_hash_bang_sees_one_after_a_line_start_one, test_cause_early_like_main_without_bom_needs_both_analog_counts, test_cause_extra_construct_error_needs_mains_count, test_holds_checks_each_kind_of_cause; and new cases in the eol, line-start (BOM), pop, eof, listed-exception, inner-BOM and invalid-account tests.

Merged origin/main (ab337cd, with #2952 and #2962). Conflicts in CHANGELOG.md (both entries kept) and the WASM cache.rs. Caches: loader 74 and WASM 104, above main's 73 / 103. One note per version: v102 says v100 (here) was never released, #2952's v103 note keeps "v101 was never released" and drops "v104 is held by #2931", and the v104 note holds no claim about other versions.

Gates (on b89980f): cargo fmt --all --check, clippy --all-features --all-targets -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, tests for parser (988 passed), loader (445), lsp (430) and wasm (178), 0 failed, both STRICT baselines, wasm-pack test --node (42), parity --self-test, parity --check (no regressions, 78,461 of 111,323) and a warm cargo check --workspace --all-features --all-targets.

Review round 21

F1, a BOM glued before a price, cost or tolerance (parser, both paths). 1 HOOL<BOM>@ 2 USD (and <BOM>@@, <BOM>{2 USD}, <BOM>{{4 USD}} @@ 5 USD, <BOM>~, LF and CRLF) counted 2 here where bean-check 3.2.3 and main count 1. The cause was in quiet_after_invalid_tokens, not in drop_errors_inside_a_line_error: a posting's unexpected trailing tokens error starts where the amount ends, which for a glued token is the token's own first byte, and only an error starting before the token was dropped as a construct check the token sits in (the spaced 1 HOOL <BOM>@ already was). Now a construct check's error (a SyntaxError that is not an unexpected input one) that starts at the token and runs past it is treated the same. The balance shapes (1.00<BOM>~ 0.01 USD, 1.00 <BOM>~ 0.01 USD: 2 here, 1 on main and bean-check) were a header-line case the rule kept on purpose (price /6"E_X, where the grammar fails before the token). A header line's construct check around the token is now dropped too when the header grammar reads up to the token: the new header_grammar_reaches runs the header's tokens up to the token through first_header_defect, the rule directive_header_check applies. This also fixes the BOM-free analogs, so balance Assets:A 1.00 $~ 0.01 USD is 1, as in bean-check (main 2), and 17 matrix inputs of the parity run newly match (balance-tol 1.00 X~ and txn-expr (1 + 2)X * / 3X USD for X in ^ $ " _ ' .). Green and red agree on every new test, the matrix rows and the parity run.

The glued shape drops the price or cost the token stands in front of, as the spaced one does (a price after a dropped cost, {{4 USD}} @@ 5 USD, is kept). #2954's body and the CHANGELOG now say so.

New matrix rows (in EXTRA, regenerated against main's parse_error_lines): a BOM glued, and spaced, before @, @@, {, {{, {{..}} @@, ~ in a posting and before ~ in a balance, LF and CRLF (28), plus the F2/F3 shapes below (4). All 28 F1 rows match bean-check.

Differential (~/.cache/rl-tmp/r21/diff.py): a BOM inserted at, and substituted for, every position of 14 templates (open with currencies and booking, transaction header with tags and links, posting with cost and price, total cost and price, flag and expression, balance with tolerance, pad, note, price, custom, option, include, pushtag / note / poptag, metadata), LF and CRLF: 2,460 inputs, bean-check raised on none.

matches bean-check further from bean-check than main (total) on some line
main 1,425
this PR at b89980f 2,059 12 12
this PR now 2,092 4 4

The fix moved 34 inputs closer to bean-check and none further. The 12 before it were the F1 shapes: balance tolerance (4), cost and price (2), total cost and price (2), and 4 CRLF metadata lines. The 4 that remain are those: k: "v"\r<BOM>\n and n: 1 USD\r<BOM>\n under a note, inserted and substituted (bean-check 2, main 2, here 3). They are not new to this PR's logic: a \r with a token glued after it counts one more than bean-check on main too (\r$: main 3, bean-check 2), and main counted the BOM shape right only because it read the BOM as layout. Each is like-main-without-bom by the matrix's own rule. Opened as #2966; not fixed here. No input is error-free on one side only.

F2, classifier survivors. Each named mutant is killed or commented:

Item Outcome
strip_boms trim_matches killed: real 2024-01-02 open then <BOM>*<BOM> and <BOM>#<BOM> (line 4 stays line-start-bom-before-comment)
brace_hash_before_tag is_none_or killed: "x" {# (made-up counts) is no cause
account_after_bom is_none_or killed: "x" $y Üx:A with a P0006 (made-up) is no cause
holds invalid-account is_none_or killed: no standalone count does not hold
stale-accepted check forced false killed: check_worse_than_main(&[]) reports every accepted line
c == "listed-exception" the stale check is now stale_exceptions; killed by $n0 x1<BOM>y line 3 listed (stale) and by a row of every other single cause excepting nothing
L266, L323, L735, L461, L746, L748 commented with the argument at each site
L413 / L431 at = 1 killed: direct tests of ordinary_accounts / ordinary_inner_boms
L569 / L588 unwrap_or(1) killed: a rewrite that leaves the line clean counts 0 (made-up roles)
L660 hash-bang share the share is now hash_bang_share, pinned by its own test
L1247 unwrap_or(1) killed: standalone_count of a clean line is 0
L1119 / L1126 commented: read only for the failure message
L278, L1182 (filters) one data_lines for every list, pinned by its own test
L282, L1187, L1189, L1196 parse_exceptions / parse_accepted read from text, with tests for each field, a blank reason and a TODO

F3, date_alone. It no longer asks the parser: beancount_date matches beancount 3.2.3's DATE regex ([0-9]{4,}[-/][0-9]+[-/][0-9]+, either separator in either place) and its date rule (a Python date: year 1 to 9999, month 1 to 12, a day of that month, leap years; each field read into a wrapping 32-bit integer, as its C code does, so 4294967297-01-01 is year 1 there). After the date, blanks, \r and a ; comment are allowed (2024-01-02 ;c, \t;c, ;c glued). Every case in test_beancount_date_reads_dates_as_beancount_does (31 dates, 20 non-dates, 11 lines) was checked with bean-check 3.2.3. The rule now needs exactly one error moved: the date's line counts one more than bean-check, the next line one fewer (test_cause_eol_reported_on_next_line_needs_one_error_moved). The two rows the reviewer found are now eol-reported-on-next-line (2024-01-02 ;c<BOM> then an open, and 2024-01-02 ;<BOM> on the last line), real counts, in the table and in the test. The recovery-first test now uses a date line after an error line (its old made-up counts moved the error the wrong way).

F4, cache. The loader caches only an error-free load (result.errors.is_empty() in loadcache.rs), and every input this PR changes has a parse error on main and here (the differential finds no input error-free on one side only; every mid-line BOM outside a string or comment is an error on both). So no loader blob can hold a changed output, and the loader bump is dropped: CACHE_VERSION stays 73, both FIXTURE_VERSIONs are back to 73, and the v74 note is gone. The v71 note says v70 and v72 were held here and never released, and why no loader version is needed. WASM moves to 106: #2946 merged during this round with WASM 105, so this PR's change takes 106 (one note; it says loader v73, unchanged, and that v104, held here, was never released; #2946's v105 note is kept as it merged, and v103's note now says v104 was never released). The WASM payloads archive sources with parse errors, so a WASM bump is needed. LOADER_CACHE_VERSION_PIN is 73. The eof_error_on_last_line comment no longer assumes a final \n.

Sweep (on the final file, one mutant after another, the file checked byte-identical after): 834 mutants over every helper and the checker (every non-test function from fnv to regressed_rows, RECOVERY_CAUSES, and the matrix test's body outside its BOM_MATRIX_UPDATE=1 block, which only writes the data files; its decisions live in the helpers swept here, relabeled_rows, regressed_rows, reason_holds, known_rows). Generated (~/.cache/rl-tmp/r21/sweep/gen.py): every comparison, && / ||, + / - / * swapped; every ! dropped; method swaps (is_some_and / is_none_or, any / all, the three trims, find / rfind, starts_with / ends_with, saturating_sub / checked_sub to wrapping_sub, split_once / rsplit_once, min / max, first / last, abs_diff, trim); every integer literal plus and minus one; every strip_boms and .filter dropped; every if condition forced true and false; every conjunct and disjunct forced neutral; every member of a character set, list and pattern alternative dropped; every match arm forced true and false; every bool function forced true and false. 731 killed, 47 do not compile, 56 survived. Of the 56, 3 are now killed by new tests (each rerun on the final file: reason_holds with greater counts, regressed_rows both ways), and the 53 left are each commented as equivalent at its site: the r > b / r < b / l == 0 family in cause (18; the only caller skips b == r), eof_error_on_last_line (6), the parts_hold zero shares (4), later_grammar's rl >= 1 (2), beancount_date's % n <= 0 (2), the one-separator split_onces (3), the blank-reason trims (3), the rows guard of the matrix test (5), the failure-message-only reads in check_row (3), and words, lone_capital_glued, account_after_bom, line_span, glued_boms_replace_construct's >=, holds's <= and the seal's rfind (1 each). A first pass of 849 mutants on the file before this round's last tests (702 killed, 44 not compiling, 103 surviving) is what the new tests and comments answer; the 834 are on the file after them. No survivor is undocumented.

Merged origin/main twice: a4d53b6 (#2965, CI only, no conflicts), then d38898f (#2946), with one conflict in the WASM cache.rs notes, resolved as above.

Gates: (on 41d0c28) cargo fmt --all --check; cargo clippy --workspace --all-features --all-targets -- -D warnings; RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --all-features --no-deps; tests for parser (1,019 passed, with both STRICT baselines on the copied compat corpus), loader (450), lsp (430) and wasm (181), 0 failed; wasm-pack test --node (45) after the #2946 merge; the fuzz_green_eq_red corpus test (parse_green_eq_red_corpus) in the parser run; parity --self-test, and --check with no regressions, 78,478 of 111,323 (the manifest drops the 17 matrix pins that now match); the pre-push cargo check --workspace --all-features --all-targets.

Review round 22

WASM cache. v105's note ended "(v104 is held by #2931.)", against the v103 and v106 notes; it now says v104 was held here and never released. Then origin/main was merged (2124386, #2969), which took WASM 107. #2970 holds 108 and #2971 holds 109, so this PR now takes 110. One note per version: the v110 note replaces this PR's v106 note and says v104 and v106 were held here and never released, and that 108 and 109 are held by #2970 and #2971; #2969's v107 note now says v106 was held here and never released. Loader stays 73 (LOADER_CACHE_VERSION_PIN 73). The CHANGELOG entry says v110.

quiet_after_invalid_tokens and header_grammar_reaches survivors. Each named mutant is now either killed by a test, or gone because the code was simplified, with the argument at its site:

Mutant Outcome
'\t' dropped from the indentation trim killed. New tab-indented postings in test_parse_invalid_token_is_one_error (\tAssets:A 1 HOOL$@ 2 USD, $~, {{2 .USD}}, {{2 .USD}} @@ 3 USD), and a tab indent in test_parse_bom_glued_before_price_cost_or_tolerance_is_one_error (every tail, LF and CRLF). bean-check 3.2.3 counts 1 on each.
e.span.start - off to + off (the inside_unread lookup) killed by test_parse_bom_run_after_the_leading_bom_counts_the_rest (<BOM><BOM><BOM><BOM>*7 Z# and two shorter forms: 2 errors each, as in bean-check)
the SyntaxError conjunct, and the (content > line_start || construct_check) conjunct (>=, <, swap, forced true) simplified to construct_check alone. The forced-true mutant is not equivalent after all: on 781,065 inputs (below) it changes 4,619 outputs, all with two BOMs at the start of the file. There the header's line error starts past the line's start, and dropping it loses the error that names the invalid token. Killed by the new test_parse_header_after_two_leading_boms_names_its_invalid_token. The construct_check-only form changes none of the 781,065 outputs; the comment says why.
construct_check on an error that starts at the token (start-eq-at-no-construct, a survivor of this round's first sweep) removed: the branch it guards asks the same thing
e.span.start > at in the other branch (>=) removed: an error at the token starts at an invalid token, and the binary_search keeps it
header_grammar_reaches: the four early return false flipped, right_biased to left_biased, .find to .next(), the token-start check (is_some_and, forced false, removed), the final is_none_or killed by three unit tests in cst::convert::tests. One covers a header token the rule reads up to, including the first token of a second directive. One covers a token the rule fails before, a metadata key, a posting account, an empty source and an offset past u32::MAX. One covers a comment line that is leading trivia of the next directive's node.
.last() to .first(), and end = first, for the rule's end simplified: the rule reads end only when it consumes no token, and it always consumes a header's first token. So first is passed, with that argument at the site.
first < line_end to <=; e.span.start > to to >= commented. The first differs only for a token at offset 0, whose line is an ERROR_NODE line with only kept errors. For the second, no error starts at a line's \n. Each changes none of the 781,065 outputs.
e.span.end > at to >= left as it is, as asked. The >= mutant moves outputs closer to bean-check and never further. Opened as #2967: a posting's sign check that ends at an invalid token, e.g. Assets:A -$x (bean-check 1, main 2, here 2). The site points to it.

The 781,065 inputs are the review's 153,634, each also with the head removed, with one and two BOMs before it, with no final newline, with tab indentation and with CRLF. The branch's final parse_error_lines gives the same output as before this round on every one of them.

Matrix helpers.

  • regressed_rows' continue to break: killed by test_regressed_rows_goes_on_past_a_new_row (a new row u, then t known at 3:2 with bean-check 3:1 and now 3:3: one regression).
  • .lines() to .split('\n'): killed in data_lines by a CRLF case in test_data_lines_skips_only_headers_and_blanks. matching_hashes reads the checked-in list, so there the mutant is commented, and test_data_files_hold_no_carriage_return pins that no data file holds a \r.
  • eol-reported-on-next-line now needs both halves at once, as its docstring says: one more on the date's line AND one fewer on the next (moved_to_next_line). test_cause_eol_reported_on_next_line_needs_one_error_moved checks both lines for each case, each half alone included. The recovery-first test's made-up counts now put beancount's error on the line after the date. The three real rows still classify.

#2966 now lists the wider \r shapes the review found. Each was checked with bean-check 3.2.3, main and this branch (counts as bean-check / main / here):

  • a \r<BOM> line after any directive: 1 / 1 / 2 (\r$ is 2 on main);
  • \r<BOM>~, \r<BOM>@ and \r <BOM>~ on header lines: 1 / 2 / 2; on metadata lines: 2 / 2 / 3;
  • \r, a blank, then a token (close Assets:A\r $~): 1 / 2 / 2.

Other rows from the review. The pushmeta row (pushmeta k: "v" then 2<BOM>024-01-02 close Assets:A: 1 / 1 / 2) is #2872's recovery, not this PR's BOM handling. beancount cannot read line 3 (k: is an invalid token there), and its recovery swallows the 2. The BOM-free 2$024 is 2 on main, and after an open the same line is 2 in bean-check, as here. Two rows that no matrix rule explains are #2968: Assets:A $@ <BOM>xAssets:A.00 (2 / 2 / 3) and close Assets:A TRUE <BOM>x (k: #t Assets:A<BOM>~ (3 / 3 / 2). Main matches bean-check's count on both.

Sweep. Mutations ran one after another, each file checked byte-identical after. The kill test for convert.rs was the whole parser suite with STRICT_BASELINE=1, and for the helpers the matrix test. The scope was quiet_after_invalid_tokens from its invalid.is_empty() check through the line loop, all of header_grammar_reaches, and the matrix helpers from fnv through regressed_rows, except the BOM_MATRIX_UPDATE=1 block. The generator was the review's, plus 25 hand-written mutants.

File (final) Mutants Killed Killed by timeout Do not compile Survive, each commented at its site
convert.rs 123 103 3 6 11
bom_combination_matrix.rs 787 685 0 59 43
total 910 788 3 65 54
  • The 3 timeouts are loops that stop advancing: break to continue, and i += 1 removed or made += 0.

  • The 11 convert.rs survivors are all commented:

    Each comparison among them was also run on the 781,065 inputs: no output changes.

  • The 43 matrix survivors are the round-21 families, already commented. Two new comments cover if b == r with its operands swapped and the rows counter of the table guard.

  • A first convert.rs pass, before the start == at simplification, had 126 mutants and 12 survivors.

  • The matrix pass's 43 survivors were run again on the final file, with nothing else building, and all survive. (During part of that pass, another test build had shared the target directory, and that could only have produced false survivors.)

Gates (on d7dfa6c): cargo fmt --all --check; cargo clippy --workspace --all-features --all-targets -- -D warnings; RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --all-features --no-deps; tests for parser (1,024 passed, with both STRICT baselines on the copied compat corpus, the fuzz_green_eq_red corpus test parse_green_eq_red_corpus among them), loader (451), lsp (434) and wasm (181), 0 failed; parity --self-test; the pre-push cargo check --workspace --all-features --all-targets. The final parse_error_lines (built clean) gives the same output as before this round on all 781,065 inputs above, so the parity manifest is unchanged.

How to test

cargo test -p rustledger-parser --test bom_mid_line_run
cargo test -p rustledger-parser --lib logos_lexer::tests::test_tokenize_
cargo test -p rustledger-lsp --all-features bom_removal
STRICT_BASELINE=1 cargo test -p rustledger-parser --test corpus_baseline parser_output_matches_baseline
STRICT_BASELINE=1 cargo test -p rustledger-parser --test cst_baseline cst_output_matches_baseline
python3 -I scripts/compat-parse-error-parity.py --rledger target/release/examples/parse_error_lines \
  --fuzz-dir DIR --fuzz-commit 9bc79f4f35f52c50813164f43307e7d151d70d8c \
  --compat-dir tests/compatibility/files --check

Local gates that passed:

  • cargo fmt --check
  • clippy --all-features --all-targets -D warnings
  • RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps
  • tests for parser, lsp, loader and wasm
  • wasm-pack test --node
  • both STRICT baselines
  • parity --check

New tests:

  • logos_lexer:
    • test_tokenize_mid_line_bom_runs_to_next_blank
    • test_tokenize_bom_after_lone_capital_runs_to_next_blank
    • test_tokenize_line_start_bom_keeps_own_extent
  • tests/bom_mid_line_run.rs:
    • test_parse_mid_line_bom_run_is_one_error
    • test_parse_mid_line_bom_before_quote_opens_no_string
    • test_parse_line_start_bom_is_one_error
    • test_parse_bom_in_string_stays_content
    • test_parse_bom_led_token_on_error_line_is_reported
    • test_parse_bom_led_token_after_invalid_account_counts_once
    • test_parse_open_with_mid_line_bom_run_reports_only_the_token
    • test_is_stray_bom_at_finds_bom_inside_longer_error_token
  • LSP: test_bom_removal_actions_find_bom_inside_longer_error_token
  • Round 22: test_header_grammar_reaches_a_header_token_the_rule_reads_up_to, test_header_grammar_reaches_is_false_off_the_header_rule, test_header_grammar_reaches_is_false_before_the_first_header_token (cst::convert::tests), test_parse_bom_run_after_the_leading_bom_counts_the_rest, test_parse_header_after_two_leading_boms_names_its_invalid_token, tab indents in test_parse_bom_glued_before_price_cost_or_tolerance_is_one_error and test_parse_invalid_token_is_one_error, test_regressed_rows_goes_on_past_a_new_row, test_data_files_hold_no_carriage_return, and new cases in test_data_lines_skips_only_headers_and_blanks and test_cause_eol_reported_on_next_line_needs_one_error_moved (matrix test file)
  • Round 20: test_cause_recovery_first_needs_a_matching_count_alone, test_cause_line_start_bom_before_comment_takes_each_skipped_start, test_cause_brace_hash_before_tag_takes_each_tag_character, test_cause_one_diagnostic_per_line_needs_exactly_the_later_errors, test_cause_glued_in_error_line_needs_exactly_the_difference, test_cause_inner_bom_under_line_error_rewrites_to_no_token, test_cause_lone_capital_glued_to_tokens_takes_each_listed_character, test_hash_bang_analog_rewrites_only_past_a_lines_start, test_is_blank_takes_a_space_or_a_tab, test_rledger_lines_puts_an_unclosed_push_on_line_zero, test_cause_glued_hash_bang_needs_a_hash_bang_on_the_line, test_cause_mid_line_hash_bang_sees_one_after_a_line_start_one, test_cause_early_like_main_without_bom_needs_both_analog_counts, test_cause_extra_construct_error_needs_mains_count, test_holds_checks_each_kind_of_cause, and new cases in seven older tests (matrix test file)
  • Round 19: test_cause_glued_construct_needs_a_positive_construct_share, test_cause_glued_in_error_line_needs_a_non_bom_error_in_place, test_cause_line_start_bom_before_comment_needs_a_skipped_start, test_cause_line_start_bom_before_comment_needs_no_account_at_its_start, test_cause_eof_error_on_last_line_needs_each_condition, test_cause_eol_reported_on_next_line_needs_a_date_alone, test_cause_lone_capital_glued_to_tokens_skips_a_leading_bom, test_cause_invalid_account_after_invalid_token_needs_an_account, and new cases in five round-17 and round-18 tests (matrix test file)
  • Round 18: test_cause_line_start_bom_before_comment_needs_a_bom, test_cause_indented_line_after_error_sees_an_indented_bom, and test_cause_inner_bom_under_line_error_needs_fewer_errors_and_a_bom_diagnostic rebuilt on its table row (matrix test file)
  • Round 17: test_cause_bom_free_line_as_on_main_needs_main_count, test_cause_listed_exception_needs_its_reason_counts, test_cause_bom_glued_to_account_needs_an_account_on_the_line, test_cause_glued_in_error_line_needs_an_account_on_the_line, test_cause_glued_in_error_line_needs_more_errors_than_beancount, test_cause_inner_bom_under_line_error_needs_fewer_errors_and_a_bom_diagnostic, test_cause_brace_hash_before_tag_needs_more_errors, test_cause_line_start_bom_before_comment_needs_fewer_errors, test_cause_pop_without_push_needs_fewer_errors (matrix test file)
  • Round 16: test_cause_like_main_without_bom_needs_both_analog_counts (round 15's test_cause_like_main_without_bom_needs_beancounts_analog_count, renamed and given a main-analog case)
  • Round 15: the classifier test above, test_reason_counts_reads_the_leading_counts, test_reason_counts_rejects_counts_not_at_the_start (matrix test file)
  • Round 14: test_parse_bom_before_price_or_cost_drops_it_issue_2954 (pins Recovery drops a posting's price or cost after an invalid token, then reports a spurious imbalance #2954's gap), test_parse_bom_alone_at_eof_after_directive_is_one_error, test_tokenize_indented_bom_runs_to_next_blank, the account check on line-start-bom-before-comment, the late like-main-without-bom rule and the reason-count check on exceptions in the matrix test
  • Round 11: test_parse_bom_line_reports_beancounts_invalid_token_text, test_parse_heading_rest_hash_after_brace_is_not_a_comment, test_token_iter_new_mid_line_applies_no_line_start_rule, the texts list, composite causes and the relabel guard in the matrix test
  • Round 10: test_parse_invalid_account_on_bom_free_line_keeps_its_p0006, the renamed test_parse_partly_invalid_account_word_keeps_mains_message, new rows in test_parse_bom_led_line_tails_count_as_beancount, the timed test_tokenize_long_bom_runs_are_linear, and the kind checks in the matrix test
  • Round 9: test_parse_bom_led_line_tails_count_as_beancount, test_parse_bom_glued_unicode_account_after_error_line_is_not_counted_twice, test_parse_partly_invalid_account_word_is_reported_as_written (renamed in round 10), the new shapes in test_tokenize_long_bom_runs_are_linear, and cause equality in the matrix test
  • Round 8: test_parse_bom_account_in_metadata_keeps_booking_method_check, the accepted further-than-main list in the matrix test
  • Round 7: test_parse_bom_led_account_shapes_count_as_beancount, and the classifier in test_parse_bom_combination_matrix_matches_beancount
  • Round 6: test_parse_bom_glued_to_account_keeps_the_account, test_tokenize_long_bom_runs_are_linear
  • Round 5: test_parse_lone_capital_glued_to_bom_is_counted, test_parse_line_start_bom_heading_counts_the_rest, and the extended matrix with the random probe
  • Round 4: test_parse_bom_led_first_token_spends_the_bom_diagnostic, test_parse_line_start_bom_run_through_valid_tokens_is_one_token, test_parse_line_start_bom_heading_rest_is_not_glued, and the extended matrix
  • Round 3: test_parse_bom_combination_matrix_matches_beancount (the guard), test_parse_line_start_glued_bom_then_inner_bom_token_counts_both, test_parse_bom_before_metadata_indentation_counts_the_key
  • Round 2: test_parse_bom_led_argument_error_is_at_the_token, test_format_source_keeps_directive_with_bom_led_argument, test_parse_secondary_bom_error_with_several_bom_tokens, test_parse_line_start_bom_glued_to_invalid_run_is_one_error, and in LSP test_parse_errors_to_diagnostics_bom_led_argument_ranges_over_the_token
  • Round 1: test_parse_bom_led_argument_of_directive_is_one_error, test_parse_secondary_bom_error_stands_for_first_bom_token_of_either_kind, test_parse_bom_led_run_stops_at_blank_inside_quotes, and in loader test_load_included_file_with_mid_line_bom_reports_one_error

Out of scope: part 2, emitting beancount's tokens for a mid-line #! / #+.

Refs #2928

🤖 Generated with Claude Code

… beancount does

A BOM-led lexer error kept its own extent wherever it stood, so a `"`,
`#!` or `#+` right after a mid-line BOM started a token of its own:
`<BOM>"x"` opened a string (kept as the narration), and `<BOM>#!d`,
`<BOM>#+x`, `<BOM><BOM>"x"` and `<BOM>abc` were two errors. beancount's
`<INVALID>[^ \t\n\r]+` reads each as one invalid token. The own extent
only matters at the start of a line, where it keeps a concatenated
file's next directive lexing, so the lexer now keeps it only there
(`at_line_start && span.start == last_newline_end`, in the `Err` arm),
and `error_later_in_run` no longer stops at a BOM after a lone capital.

The CST recovery treated every BOM-led error token as layout. Now only
one that starts its line is (`is_line_start_bom_token`, one look back at
the character before the token): `report_invalid_tokens_of_error_line`,
`quiet_after_invalid_tokens` and `holds_an_invalid_token` count a mid-line
BOM-led run as the invalid token it is, so `313<BOM>x` is two errors as in
bean-check. When the line's error is another one (an invalid account),
the secondary `BomInDirectiveBody` stands for the line's first BOM-led
token, which is not counted twice.

Parse-error parity: 78,306 of 111,323 inputs match beancount, from
78,225 (85 newly match, 4 regress on pre-existing causes: a stray
mid-line `\r` and an end-of-file grammar error, both of which the old
split BOM token happened to offset). Green and red agree on the whole
pinned fuzz corpus. Loader cache v70, WASM cache v93.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner November 10, 2026 16:18
@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.71324% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-parser/src/logos_lexer.rs 96.93% 5 Missing ⚠️
crates/rustledger-parser/src/cst/convert.rs 99.36% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 40.9ms ± 0.8ms 596.2ms ± 10.1ms 14.6x 45.1 MB / 51.0 MB
investment 63.2ms ± 0.9ms 2158.0ms ± 16.1ms 34.1x 47.1 MB / 59.0 MB
fifo 61.0ms ± 1.0ms 11864.7ms ± 152.7ms 194.6x 49.2 MB / 58.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 40.5ms ± 0.4ms 40.9ms ± 0.8ms +0.9% ✅ within noise 45.1 MB → 45.1 MB (-0.0%)
investment 64.1ms ± 1.5ms 63.2ms ± 0.9ms -1.5% ✅ within noise 46.9 MB → 47.1 MB (+0.4%)
fifo 60.6ms ± 1.1ms 61.0ms ± 1.0ms +0.6% ✅ within noise 49.1 MB → 49.2 MB (+0.1%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.4ms, investment 0.8ms, fifo 0.7ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 179 masked)
Full AST Match 100%
Total Files 826
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

…condary BOM error stand for either kind of BOM token

Review round 1 of #2931.

A BOM-led invalid token where a directive's argument or account belongs
(`price USD 1 <BOM>EUR`, `commodity <BOM>EUR`, `note Assets:A <BOM>"x"`,
`open <BOM>Assets:C`) gave the dropped directive's generic line error and
the token's inline `BomInDirectiveBody`: two errors, where main and
bean-check report one. `drop_errors_inside_a_line_error` now takes an
inline BOM error as an inner error too: when the header grammar first
fails at that token, the inner error is dropped and the line error takes
the BOM kind and hint, as an invalid token's generic error is merged
there already.

The secondary BOM error after another line error (an invalid account)
stands for the line's first token with a stray BOM, whether the BOM leads
it or sits inside it, so a later BOM-led token keeps its own error
(`Ü:A x<BOM>y <BOM>z` is three errors, as in bean-check).

Parse-error parity: 78,367 of 111,323 inputs match beancount (61 more
than round 0, no new regressions).

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen and others added 8 commits November 10, 2026 12:39
…unt every other stray-BOM token after an invalid account

Review round 2 of #2931.

When the header grammar first fails at a BOM-led token, the token's own
`BomInDirectiveBody` is now the error kept, and the generic whole-node
error is dropped for it, so the error has the token's span (main reported
the BOM there too) rather than the directive's. The formatter still copies
the directive verbatim: the token lies inside its node.

After an invalid account, the secondary BOM error stands for one token
with a stray BOM in it; every other such token, BOM-led or with the BOM
inside it, has its own error, as in bean-check (`Ü:A <BOM>z x<BOM>y` is
three errors). A BOM that starts its line is skipped when finding the
line's first invalid token, so `<BOM>tApo` at the start of a line is the
one token the line error stands for, as in beancount.

Parse-error parity: 78,399 of 111,323 inputs match beancount (32 more
than round 1; the 2 inputs that no longer match have pre-existing causes).

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…or stands for a line-start BOM, and pin every BOM combination against beancount

Review round 3 of #2931.

A BOM that starts its line keeps its own extent here, where beancount's
invalid token runs on through whatever is glued to it, so it is always the
line's first invalid token, the one the line error stands for. An invalid
run glued to it (`<BOM>foo`) is part of that token. A run that only
follows it (`<BOM>  k:`) is one more token, where round 2 took it as the
first: `<BOM>  k: Ü:A x<BOM>y0` lost the `k:` (bean-check 3, main 3,
round 2: 2). And once the line's BOM diagnostic stands for that BOM, a run
with a BOM inside it later on the line has its own error (`<BOM>foo x<BOM>y`
is two errors, as in bean-check and on main; round 2 gave one).

Each review round found another combination that drifted, so this adds a
guard. `scripts/bom-combination-matrix.py` records beancount 3.2.3's
per-line counts for every combination of up to three BOM-led, inner-BOM
and plain invalid tokens, with no prefix, a line-start BOM, or a
line-start BOM glued to a run, in nine line contexts (1,078 inputs), and
`tests/bom_combination_matrix.rs` checks rledger against it on both parse
paths. The 386 inputs that still differ are listed with their cause and
rledger's counts. All three causes predate #2928, and none of those
inputs is further from beancount than on main.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keeps both CHANGELOG Fixed entries (#2928 and #2927).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`e8844718a38e` stays a mismatch: its `<BOM>   Ra` line now matches
beancount (two invalid tokens), so its first differing line is a
pre-existing posting-line difference and its category changes.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a line-start BOM's whole blank-free run as one token, and widen the BOM matrix

Review round 4 of #2931.

A BOM-led first token after a date or an indentation is the one the
line's error stands for, and that error is the BOM diagnostic, so a later
run with a BOM inside it has its own error (`2024-01-02 <BOM>a x<BOM>y`
is two errors, as in bean-check). On an indented line whose start
beancount reads, the token's own `BomInDirectiveBody` now stands for the
line's first error as the generic one does, so `  <BOM>a` and
`  <BOM>; c` are one and two errors, not two and three.

A BOM that starts its line is one beancount token with its whole
blank-free run, through tokens that lex here (`<BOM>12$`), so an invalid
token in that run is not counted again. The unread rest of a `<BOM>*`
heading line holds a blank and is still reported.

The BOM-combination matrix gains a date-alone context, a metadata line
under a header with no narration, a BOM after the indentation (glued to
a run and to a `;`), and two prefixes that glue a BOM through a valid
token to an invalid one: 2,598 inputs. Reverting each round-3 and
round-4 fix fails it. The known list names its four causes, with the
account cause corrected: it appears only after a line-start BOM.

Parse-error parity: 78,461 of 111,323 inputs match beancount (62 more,
no regressions).

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… a `<BOM>*` heading's rest as beancount does, and add a seeded probe to the BOM matrix

Review round 5 of #2931.

Beancount's account type is `([A-Z]|{UTF-8-ONLY})...`, so a BOM glued to
an account shape (`<BOM>Assets:A`, `<BOM>Ü:A`, `<BOM>1:A`) is one ACCOUNT
there, and only its name is rejected, when the file loads. The account
token regex no longer excludes U+FEFF from the first character, so it is
one account here too, which the account-name check (`E1005`) rejects. A
line-start BOM's own extent is capped at the BOM, as logos may now scan
it into a failed account.

A lone capital glued to a BOM (`A<BOM>b`) counts as BOM-led, so it is
never left to the line's BOM diagnostic. After a `<BOM>*` heading start,
the part up to the first blank is the BOM's token, and each blank-free run
after it that beancount cannot read is one more error.

The BOM matrix gains a BOM-led account kind and a lone-capital kind, the
shapes the reviews found, and a seeded random probe of 2,000 inputs,
5,727 rows in all. Every row further from beancount than main is checked
against the same input without its BOMs on main and named as such.

Parse-error parity stays at 78,461 of 111,323.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o an account as its own token, and keep BOM runs linear

Review round 6 of #2931.

Letting U+FEFF start `Token::Account` made a line of BOMs quadratic and
hid the BOM from the user (no `P0026`, no "Remove BOM" quick fix, a
BOM-led account offered for completion and `open`). The account token is
as on main again. Instead, a mid-line run of BOMs followed by an
account-shaped word (`logos_lexer::starts_with_account`, the lexer's own
account rule, read up to the next blank) keeps its own extent as a
line-start BOM does: it is the `P0026` the quick fix acts on, the account
lexes as one, and the error recovery counts the run as no invalid token,
as beancount reads it into the account.

Line-start BOMs stay one logos error each, a mid-line run is taken whole,
and the recovery's account lookahead stops at the next BOM, so long BOM
runs are linear end to end. `test_tokenize_long_bom_runs_are_linear`
counts the bytes scanned while lexing and parsing 1 MB of BOMs, and fails
on the quadratic versions.

The known list now names a cause for every differing line, from a rule
per cause, and unclosed `pushtag` / `pushmeta` errors are line 0 on both
sides, as in the parity harness.

Parse-error parity: 78,460 of 111,323 inputs match beancount.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keeps both sides of CHANGELOG.md and both cache-version notes: loader
v69 (#2925) and v70 (#2928), WASM v92 (#2925) and v93 (#2928).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen and others added 6 commits November 10, 2026 18:37
… every count site, keep line-start bookkeeping before an account, and commit the BOM matrix classifier

Review round 7 of #2931.

`logos_lexer::bom_led_account` decides whether a run of BOMs starts an
account as beancount does (a BOM may be an account's first character),
with the lexer's own account rule on the word with a non-ASCII stand-in
for the BOMs: `<BOM>assets:A`, `<BOM>1:A`, `<BOM>:A` are accounts too.
When an account of rledger's follows, the BOMs keep their own token
(P0026 and its quick fix, the account kept); otherwise the token ends
where beancount's account does. One predicate,
`is_bom_account_token`, now serves all four counting sites, the
heading-rest `invalid_runs` included. A line-start BOM run before an
account spends the BOM diagnostic and glues nothing after the account.

The matrix gains a BOM-led account beancount reads only with its BOM, a
glued tail after an account, and two line-start BOMs before every token,
and records main's counts and the BOM-free analog's, so the test itself
classifies each differing line (`cause`, one rule per cause) and checks
the known list against it; `BOM_MATRIX_UPDATE=1` rewrites the list.

The linearity guard gains a wall-clock bound that a lookahead the byte
counters miss fails, and the LSP's grouped quick fix says "BOMs", not
"BOM bytes".

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ount does, and refuse any BOM-matrix line further from beancount than main unless accepted by hand

Review round 8 of #2931.

A line-start BOM run followed by an account beancount reads only with
its BOM (`<BOM>assets:A$x`, `<BOM>1:A$x`) glued nothing after the
account, so its tail's error was lost. The run's account now ends at
`bom_led_account`'s end: tokens before it are part of it, and the part
of a token past it is beancount's next token, counted when it lexes as
an invalid one (`$x`, `.b`), not when it lexes (`"x"`, `#t`, `;c`).
Errors that start inside an error token are the lexer's own in
`quiet_after_invalid_tokens`.

The BOM matrix test now fails on any line rledger counts further from
beancount than main unless `bom_combination_matrix_worse_than_main.tsv`,
kept by hand and never written by `BOM_MATRIX_UPDATE`, lists it with a
cause the test checks: the BOM-free analog for `like-main-without-bom`,
a standalone match for a recovery cause, and the same difference alone
for a line's own cause. All six of the reviewer's mutations of the
BOM-account predicate now fail, the lexer one through a unit test that
pins the kept account, and the metadata site through a new booking
method test. The linearity guard's wall-clock backstop is 30 s.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ails as beancount does

Review round 9 of the mid-line BOM run fix.

- bom_led_account reads only the characters an account can hold, so a
  line of BOM-led runs is linear again; the linearity guard covers the
  three new run shapes.
- A comment ends the tail of a BOM-led account; on a line that starts
  with a BOM, an account inside an invalid token is no extra error. The
  token is masked byte for byte, so a BOM-glued account is not split
  off and a partly masked account is reported as written.
- The BOM combination matrix gains account tails and a heading context,
  checks the mid-line hash-bang cause against its analog, folds in the
  account probe, and requires an accepted line's cause to be the cause
  the classifier finds.
- Parse-error parity 78,461 (one explained manifest row).

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Take #2920 (WASM cache v94). This branch moves its WASM cache to v95,
pinned at loader v70; v93 was never released.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… as beancount does

Review round 10 of the mid-line BOM run fix.

- A `;` after any BOM-led account of a tail starts beancount's comment,
  so nothing after it is counted.
- After a `<BOM>*` heading, `{#` is a brace and whatever the `#` starts;
  the rest's lexer resumes mid-line after the brace (new
  `TokenIter::new_mid_line`), so the cost stays linear. Invalid runs are
  reported from where beancount's invalid token starts.
- The BOM matrix checks the error kinds each cause names (`P0026`,
  `P0006`), and verifies a glued-account line with its accounts written
  as ordinary ones; it gains the comment tails, a `{#t` heading context,
  the price shape and a `brace-hash-before-tag` cause.
- The linearity guard runs the 1 MB pass under a time budget from the
  short pass, so a quadratic version fails instead of hanging.
- Tests pin masking to BOM-led lines and name the partly-invalid
  account test as preserving main's message.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…token text

Review round 11 of the mid-line BOM run fix.

- The matrix table records beancount's count for each line alone, and a
  recovery cause is asked first when the line alone counts as beancount
  does alone.
- A line may have two causes (`&`): a glued BOM with a mid-line `#!` /
  `#+`, or with a construct error main also makes. Each part's share is
  measured in turn and the shares must be the whole difference.
- The invalid-token texts rledger reports for BOM inputs are recorded and
  checked; an update that keeps counts but changes causes or texts needs
  BOM_MATRIX_RELABEL=1.
- The linearity guard caps the short run at 1 s, gives the long run 10x
  the linear ratio plus 5 s, and re-raises a worker's own panic.
- `invalid_runs` reads a `{#` through the common token path (a lone
  capital glued to it starts beancount's invalid token, `A{#`), and the
  dead heading-rest comment break is gone; `new_mid_line` is pinned.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sions on update

Review round 12 of the mid-line BOM run fix.

- The matrix generator records where beancount's own lexer puts each
  input's BOMs (BOM-led ACCOUNT tokens, BOMs inside invalid tokens) and
  each line's grammar errors after its first; the test reads these
  instead of guessing token boundaries.
- inner-bom-under-line-error now requires a BOM inside beancount's
  invalid token whose replacement by `$` makes rledger count the line as
  beancount does; one-diagnostic-per-line and the new
  bom-account-under-line-diagnostic are verified from the table.
- kinds_hold is gone; composite share signs are documented.
- An update refuses a line counted further from beancount than recorded
  (a new matching list tells rows that matched from new ones) unless
  BOM_MATRIX_RELABEL=1 and the known row carries a reason.
- The linearity guard bounds the short run by a load-scaled reference.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 11, 2026
- Rewrite the comments that still said run_validation gates on load.errors
  or skips on has_fatal (helpers.rs, api.rs, parsed_ledger.rs).
- run_validation: drop the span-length-mismatch branch, which set refused
  transactions aside without noting them; load_and_book always keeps one
  span per directive, now a debug_assert.
- CHANGELOG: Ledger::booking_refused listed under Breaking, as
  PluginError::failed was.
- Cache notes: v93 and v96 were never released; #2931 holds v95.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…agnostic fallback

Review round 13 of the mid-line BOM run fix.

- The plain test checks the matching list is exactly the rows that
  match, and a `# total` seal line catches a cut or edited list in
  either mode, so a stale list cannot switch off the update guard.
- one-diagnostic-per-line now needs beancount's later grammar errors
  to be the whole difference; pop-without-push is asked first;
  line-start-bom-before-comment covers every skipped line start; new
  eof-error-on-last-line and bom-free-line-as-on-main causes; the lines
  no rule explains are listed by hand with their facts.
- A regression reason is written for exact counts and expires with
  them; a row that matched regresses from beancount's counts even with
  a hand-added known row.
- The generator requires beancount 3.2.3.

Refs #2928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 11, 2026
… and escape query's option messages

Review round 3 of #2945.

- Loader CACHE_VERSION 69 -> 71 (WASM pin 71). Ignoring an included
  `documents` option (E7009) changes loader output: a v69 blob of a ledger
  whose include sets an existing `documents` root kept serving the
  `document` entries with no E7009. v70 is held by #2931 and v73 by #2944.
  The CostNumber and MetaValue fixture tripwires move to 71; no archived
  layout moved.
- rledger query escapes an option diagnostic's message on the terminal
  path, as Diagnostic::to_line does (#2538), with a test.
- CHANGELOG: ag-rledger query warnings carry optional file and line keys;
  rledger merge refuses a tree whose include sets documents.

Refs #2925

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rs change nothing

Round 19 of the review mutated cause()'s helpers. New made-up-count tests
kill each mutant that can change a result: the BOM inside a header string
for block_err, a poptag that does not start its line, a negative construct
share, the in-error-line rule's non-BOM error, a tag after a line-start
BOM, the brace rule's tag character, each eof_error_on_last_line
condition, date_alone's length and BOM strip, lone_capital_glued's BOM
strip, account_after_bom's colon, account_at at an earlier account, and an
account role on another line for both glued causes.

The rest are commented as changing no result where they stand, each with
the reason: the header range, later_grammar's rl >= 1, the hash-bang check
and the dead (r, b) update in parts_hold, eof's bc[eof] > 0, the inner-BOM
rewrite's span filter, line_span's end, and the in-error-line rule's `>`.
skipped_line_start no longer checks for a `\n` a single line cannot hold,
an unknown part is unreachable!, and GLUED's own zero check is left to the
shared one, which the matrix test now needs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 12, 2026
…does (#2952)

* fix(wasm): restore cached ledgers holding custom directives or metadata

ParsedLedger.fromCache and Ledger.fromCache threw "Deserialization
failed: unaligned pointer ... alignment 8" on any ledger with a custom
directive or a metadata entry.

Root cause: rkyv::from_bytes reads the archive in place, so every
archived value must sit at its own alignment in memory. ArchivedMetaValue
needs 8 bytes (its Int(i64) variant, added in #1513), and every custom
value and metadata entry archives one. The WASM cache blob puts its
archive 12 bytes in, after the magic and version header, so even in a
16-aligned blob those values sat 4 bytes off. The blob itself is not
aligned either: wasm-bindgen copies a JS Uint8Array into wasm memory with
alignment 1.

Fix: decoding copies the payload into an rkyv AlignedVec before reading
it, which does not depend on where the caller's bytes lie. The cache
format is unchanged, so CACHE_VERSION stays at 94 and blobs already
written restore as they are.

The loader's on-disk cache reads its header separately, so it does not
have the offset bug, but it read the archive into a plain Vec<u8>, whose
alignment is 1 by contract and 16 only because the system allocator
happens to give it. It now reads straight into an AlignedVec. Its format
is unchanged too.

Tests: a round trip over one ledger per directive type, per metadata
value type and per custom value type, plus error cases, comparing
directives, errors and options on both ParsedLedger and Ledger, natively
and under wasm-pack test --node; a native round trip over every
.beancount file in the repository's test corpora; a decode of each
payload at every offset from a 16-byte boundary; and a loader save/load
of custom values and metadata. All but the loader test fail without the
fix.

Closes #2934

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: make check, WASM, FFI and LSP agree on close-with-balance and after a booking error

Two cases where the diagnostic surfaces disagreed (#2937), settled by
bean-check 3.2.3:

- Closing an account that still holds a balance (E1004). bean-check does
  not flag it, with or without auto_accounts / currency_accounts, and
  `rledger check` stays silent to match (`lint closed-nonempty` reports
  it). WASM, the FFI component and the LSP reported it. They now leave
  it out through the one predicate, `ErrorCode::is_advisory_only`.
- Validation after a booking error. bean-check and `check` report an
  ambiguous STRICT reduction and the `Balance failed` that follows it,
  the refused transaction left out of the balance. WASM `validateSource`
  and `ParsedLedger` skipped validation on any load error, and the FFI
  counted the refused transaction into the balance (-1600 USD where
  bean-check says -2100 USD). The loader now records which transactions
  booking refused (`Ledger::booking_refused`), and both surfaces set them
  aside as the validating loader does: Early sees them, Late does not,
  and the session reports the account errors Early held for them.

A shared case file (`rustledger-loader/tests/surface_agreement/cases.rs`)
drives one drift-guard test per surface: the loader, `rledger check`,
WASM (`validateSource`, `validateMultiFile`, `ParsedLedger`, `Ledger`,
fresh and from cache), the FFI component (`validate`, `load`) and the
LSP, each comparing codes (the FFI wire error has none: line and
message), lines and messages.

The WASM cache moves to v97: both payloads' archived errors change.
WASM `fromCache` now reads the archive from an aligned copy: it starts 12
bytes into the blob, and the new cache round trip hit an "unaligned
pointer" refusal on it. The format is unchanged.

Closes #2937

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(wasm): drop the duplicate cache alignment fix in favor of #2942

The AlignedVec copy in deserialize_parsed / deserialize_ledger duplicates
the fix in #2942 (#2934), which also covers the loader cache and has its
own tests. #2942's branch is merged in next, so this PR's WASM cache round
trip still decodes; #2947 depends on #2942 landing first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(wasm): address #2947 review round 1

- Rewrite the comments that still said run_validation gates on load.errors
  or skips on has_fatal (helpers.rs, api.rs, parsed_ledger.rs).
- run_validation: drop the span-length-mismatch branch, which set refused
  transactions aside without noting them; load_and_book always keeps one
  span per directive, now a debug_assert.
- CHANGELOG: Ledger::booking_refused listed under Breaking, as
  PluginError::failed was.
- Cache notes: v93 and v96 were never released; #2931 holds v95.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: validate after a parse error on every surface, as rledger check does

`rledger check` and bean-check 3.2.3 report a syntax error and still
validate the entries that did parse. WASM (`validateSource`,
`ParsedLedger`, `validateMultiFile`, `validateWithHost`), the FFI
component (`validate`, `load`) and the LSP validated nothing once a file
failed to parse, so one bad line hid every other finding.

Each surface now follows the validating loader's rule, under which no
load error stops validation:

- WASM `load_and_book` no longer returns early on a parse error; the
  loader keeps what parsed and `process` books it, and `run_validation`
  validates it. `validateMultiFile` / `validateWithHost` report every
  load error, then run `process` with them cleared, as `check` does.
- `LoadResult::take_parse_errors` (new) takes the parse errors out of a
  load so a surface reports them one by one with code and line, rather
  than `process` folding them into one line-less `parse errors in
  <path>`. WASM's single-source load, `Ledger.fromFiles` and the FFI
  string load use it.
- The FFI's `semantic_validation_errors` drops its parse-phase gate.
- The LSP's `validation_would_run` keeps only the size cap, and an open
  buffer with a parse error is overlaid in a multi-file ledger.

The shared surface_agreement cases gain one parse error plus an
unbalanced transaction and a failing balance (P0012 line 8, E3001 line
4, E2001 line 10, bean-check's three findings on the same lines),
asserted on the CLI, the loader, WASM, the FFI and the LSP.

WASM cache v101.

Closes #2949

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: address #2952 review round 1

- LSP: restore the #1813 guard in `ledger_diagnostics_multi`, so a buffer
  broken mid-edit no longer replaces the stored plugins the unopened files
  are validated with, and re-add
  `broken_current_parse_keeps_stored_plugins_for_cross_file_validation`.
- LSP: keep overlaying a broken current buffer (its own diagnostics come
  from its text, as in `rledger check`), but hold the unopened files'
  diagnostics while it has a parse error, so a half-typed string that
  swallows an `open` cannot make them flap. Keep overlaying other broken
  open buffers. Pin both through `MainLoopState`.
- WASM: `validateMultiFile` / `validateWithHost` take only the parse errors
  and leave the other load errors to `process`, as `Ledger.fromFiles` does,
  so they keep the code `LOAD`; drift guard
  `validate_and_ledger_report_load_errors_alike`.
- WASM cache comment: v100 is not held by an open PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(lsp): validate other files against a clean view, not a held one

Review round 2 of #2952. Round 1 held the unopened files' diagnostics
while the edited buffer had a parse error. That hold never published
the includes of a main file saved with a syntax error, let a clean
buffer's edit recompute them against another broken buffer, and the
restored plugin guard made a broken buffer's own diagnostics differ
from rledger check on its text.

Replace it with a stateless rule. Every file other than the one being
published is validated against the clean view: the ledger as loaded
with each open buffer that parses cleanly overlaid, a broken one left
as on disk. The published buffer's own diagnostics come from the clean
view plus its own text and plugins, as check reports them. For a clean
buffer the two views coincide, so the all-clean path still runs one
validation. didClose republishes the unopened files from disk.

Removed: the hold flag, multi_file_diagnostics' with_unopened, and the
parse-error plugin guard in ledger_diagnostics_multi. The changelog now
names the surfaces that report parse errors one by one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(lsp): keep a broken buffer's last clean text and every buffer's plugins in the clean view

Review round 3 of #2952.

- The clean view used the stored load for a broken buffer, so breaking a
  buffer with unsaved clean edits undid them for every other file. Each
  open buffer now keeps its last clean parse (dropped on close) and
  contributes it while its current text is broken.
- The clean view applied only the published buffer's plugin lines, so
  one revalidation could publish a file twice with different content.
  ledger_diagnostics_multi now takes the view as parses: every file in
  it contributes its directives and its plugin lines, replaced in place.
- didClose republishes every other open ledger buffer, not only the
  unopened files.
- Docs: the own view's file set is the stored load's (an include edit
  takes effect on the next load); the WIT balance diff and the ffi-wasi
  error-phase docs no longer describe the removed parse gate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(lsp): run a view's plugins in the loader's order, and record a clean parse only in diagnostics passes

Review round 4 of #2952.

- view_plugins appended the plugins of a view file that had none stored
  at the end, in the order the view listed its files (the published
  buffer first, then VFS HashMap order), so two chained rename_accounts
  ran in a different order than rledger check runs them and the clean
  view depended on which buffer was published. It now stable-sorts by
  file_id, the loader's order (pinned by a new loader test).
- last_clean_parse was recorded by every parse_result() call, request
  handlers included; it is now recorded only by clean_view_parse, which
  only diagnostics passes call.
- The wasm cache comment no longer calls v100 unreleased.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(lsp): validate a buffer saved broken as loaded, and pin the loader's plugin order on disk

Review round 5 of #2952 (issue #2949).

- After every successful load of the ledger (watched-file reload, root
  adoption), an open buffer whose current text equals the text that load
  read for its file drops its last clean parse: it was saved, so until it
  next parses cleanly its file is validated as `rledger check` validates
  the saved text. A buffer edited past what was saved keeps it. Before,
  a buffer saved broken kept validating its includes against its old
  clean text, hiding the E1001 `check` reports on disk.
- Docs: the set AND ORDER of the files come from the last load (plugin
  order and same-day tie-breaks follow it), on `publish_diagnostics`,
  `view_plugins` and in the CHANGELOG.
- Loader test: the plugin `file_id` order on disk, through the parallel
  pre-parse branch (a glob include matching several files).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(lsp): forget a saved-broken buffer's clean parse when its file has a BOM

The loader keeps a file's leading BOM, while editors send the buffer
without it, so the round-5 "saved broken" check never matched a
BOM-prefixed file and kept validating other files against its last
clean text. Compare both texts with the parser's canonical
`bom::strip_leading`, and pin the BOM and CRLF cases with tests.

Review round 6 of #2952.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
robcohen and others added 6 commits November 12, 2026 08:23
…n or document each survivor

Round-20 review of the matrix test's classifier. `date_alone` now asks the
parser's own `parse_date` (beancount's `DATE`, slash dates and
`2024-01-021` included, and a real calendar date) and no longer strips
leading BOMs: beancount reads `<BOM>2024-01-02` as one invalid token and
reports nothing on the next line. `holds` is one match, with its two
standalone checks sharing `alone_counts`, and `parts_hold` checks the
construct sign in the construct arm.

New tests pin, on real counts where beancount and rledger differ (the
rows recorded by hand from bean-check 3.2.3, `recorded_row`) and on
made-up counts otherwise: the date shapes, each skipped line start, a
BOM-led `poptag`, each tag character after `{#`, each character after a
lone capital, the eof sum, the later-grammar difference, the glued
in-error-line difference, the `$` of the inner-BOM rewrite, the
hash-bang analog, `is_blank`, line 0 for an unclosed push, the
recovery-first `alone_matches`, both analog counts of the early
`like-main-without-bom`, main's count for `extra-construct-error`, and
every kind of cause `holds` checks.

Sweep on the final file: 451 mutants, 2 do not compile, 409 killed, 40
survive, each commented as equivalent at its site.

The WASM v102 note now says v100 and v101 were never released, and the
v104 note no longer repeats v93, v95, v100 and v101.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nce, and pin the matrix classifier's survivors

A posting's trailing-tokens check starts its error where the amount ends,
so a token glued to the currency (`1 HOOL<BOM>@ 2 USD`, `<BOM>{2 USD}`,
`<BOM>{{4 USD}} @@ 5 USD`) put it right at the token, where
`quiet_after_invalid_tokens` kept it: two errors where bean-check 3.2.3 and
main report one. A construct check's error that starts at the token and
runs past it is now treated like one that starts before it. On a header
line, a construct check around the token (a balance's malformed amount,
`1.00 <BOM>~ 0.01 USD`, `1.00 $~ 0.01 USD`) is dropped too when the
header's grammar reads up to the token (`header_grammar_reaches`, the rule
`directive_header_check` applies). 17 parity inputs now match beancount.

The matrix table gains the round-21 shapes (a BOM glued or spaced before
`@`, `@@`, `{`, `{{`, `~`, LF and CRLF; a date alone with a comment; a
line-start BOM before `*` / `#` and a BOM). `date_alone` reads beancount's
DATE token by hand (regex, Python date range, 32-bit field wrap, a `;`
comment after it) instead of asking the parser, and the
`eol-reported-on-next-line` rule needs exactly one error moved. The
classifier survivors of the round-21 review are killed by tests or
commented as equivalent; the stale-exception check and the hash-bang share
are functions with tests of their own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every input #2931 changes has a parse error on main and here, and the
loader saves a cache blob only for an error-free load, so no loader blob
can hold a changed output: the v74 bump is dropped. The WASM payloads
archive sources with parse errors, so WASM v104 stays, pinned to loader
v73.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The glued-BOM test asserted every price gone; `{{4 USD}} @@ 5 USD` drops
only the cost the BOM stands in front of.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen and others added 2 commits November 12, 2026 12:08
The known, texts and matching lists are compared through one list_diff,
the known list is parsed once (parse_known_rows), and the update-only
helpers (relabeled_rows, reason_holds, regressed_rows) get tests of their
own. beancount_date covers every month length, and
glued_boms_replace_construct the P0026s a rewrite leaves. Every other
survivor of the sweep is commented as equivalent at its site.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 13, 2026
v107 is claimed by #2969; v106 is held by #2931.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 13, 2026
… them, and validate a scratch buffer alone (#2969)

* fix(lsp): publish plugin and load errors where rledger check reports them, and validate a scratch buffer alone

- #2955: a buffer outside the loaded ledger is validated as a ledger of its
  own text, as `rledger check` on it does, whatever else is open. It used to
  get the ledger's errors mapped by byte offset onto its lines, and its
  `plugin` lines replaced the main file's.
- #2957: plugin errors keep their location and are published on the file
  and line `check` reports (cross-published to an unopened include); only
  one with no location stays at the top of the main file.
- #2959: load errors (`LOAD`) are published: a missing or unreadable
  include and an include cycle on the `include` line in the including file,
  the rest in the main file. `LoadError::IncludeCycle` gains `include_site`
  so the loader, `check --format json` and WASM locate a cycle on that line
  too. While the ledger has a load error, any watched change reloads it, so
  creating a missing include clears the error. WASM cache v107 (v106 held
  by #2931); loader cache unchanged at v73.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(lsp)!: assert LSP diagnostics on the wire, and mark the IncludeCycle field as breaking

- The new main_loop tests read diagnostics off the published
  notifications by URI instead of MainLoopState::diagnostics, whose keys
  differ on Windows (an open buffer's URI path `C:\..` against the
  loader's canonical `\\?\C:\..` for an unopened file).
- CHANGELOG: LoadError::IncludeCycle's new public include_site field
  moves under Breaking, with `rledger check --format json` placing E0002
  on the include line, and the FFI component and WASM locating the cycle.
- A buffer outside the ledger is validated on its own text without its
  includes; docs and CHANGELOG now say so instead of claiming it matches
  `rledger check` on that file in general.
- Comment on why plugin and load error lines drift in an edited buffer
  until the next reload.
- check.rs locates the JSON cycle diagnostic with SourceMap::locate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
robcohen and others added 2 commits November 13, 2026 01:43
…nvalid_tokens

- quiet_after_invalid_tokens: drop an error that spans the token only
  when it is a construct check (the SyntaxError and indented-line
  conjuncts, and the construct check on an error at the token, were
  that and nothing more), and drop the redundant `start > at` in the
  other branch. Each remaining equivalent mutant is argued at its
  site. A header's line error after two leading BOMs is kept, as a new
  test pins. The `end > at` boundary is #2967.
- header_grammar_reaches: pass `first` as the rule's `end`, which it
  never reads here; unit tests for each early return, the ancestor
  search, the right-biased token and the final defect check.
- Tests: tab-indented postings (a glued BOM or `$` before a price,
  cost or tolerance), extra BOMs at the start of a file.
- Matrix checker: `eol-reported-on-next-line` needs both halves at
  once; `regressed_rows` goes on past a new row; CRLF in data_lines;
  the data files hold no `\r`; two survivors commented.
- WASM cache v105 note: v104 was held by #2931 and never released.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
WASM cache: main holds v107 (#2969), #2970 holds 108 and #2971 holds
109, so this PR moves from 106 to 110. The v107 note now says v106 was
held here and never released; loader cache stays 73.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 13, 2026
… beside a same-cost short (#2970)

* fix(booking): read an AVERAGE sale's pool-average cost as a reduction beside a same-cost short

On an AVERAGE account holding a short at 101 beside longs averaging 101, a
sale `-1 X {}` reduced the longs and booked as `-1 X {101 USD}`. Asked again
of the inventory (any consumer realizing a posting with no recorded booking
decision), the #2384 own-side exception read that cost lot by lot: it matched
the short and neither long, so the booked reduction became a second short.

Under AVERAGE a cost is a claim about the pool, so the exception now also
treats the other side as named when its pool accepts the cost as a claim.
The claim rule moves from rustledger-booking's check_average_spec into
rustledger-core (average_claim_mismatch, with written_allowance and its
helpers), and both booking and Inventory::is_booking_reduction call it.
A written `-1 X {101 USD}` in that shape now books like `-1 X {}`.

Commits the proptest seed and adds regression tests at core and validate
level. WASM cache bumped to 107 (106 is held by #2931); loader cache
unchanged.

Closes #2958

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* chore(wasm): move the #2958 cache bump to v108

v107 is claimed by #2969; v106 is held by #2931.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(booking): name covers in the #2958 rule, and state its two consequences

The AVERAGE pool-claim rule applies to a buy that covers shorts as well as
to a sale. Say "a sale or a cover" in compatibility.md section 14 and the
v108 WASM cache note, and pin the cover with a test: holding a long at 101
beside shorts at 100 and 102, +1 X {101 USD} covers the shorts (1 long,
9 short left), where main opened a second long (2 long, 10 short).

The ADR 0007 amendment now states two consequences: a claim the pool
accepts only by rounding beats a lot at exactly that cost, and a ledger
that loaded can now fail with E4002 on an over-reduction of the pool.

Also update the adds_to_its_own_side doc comment to describe the AVERAGE
pool test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(changelog): note the AVERAGE reduction fix (#2958)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen merged commit f785188 into main Nov 13, 2026
67 of 68 checks passed
@robcohen
robcohen deleted the fix/bom-run-extent branch November 13, 2026 15:03
robcohen added a commit that referenced this pull request Nov 13, 2026
…#2973)

* fix(wasm)!: give a validation finding the hint rledger check gives it

validateSource and ParsedLedger mapped a ValidationError through their
own rule in validation_error_to_wasm: the hint fell back from the
finding's hint to its note to its context, and the note stayed out of
the message. So a failing balance (E2001) carried the hint
"difference: 1, tolerance: 0", which rledger check, the multi-file WASM
surfaces and the FFI do not give.

The loader's conversion, which check uses, is now public as
rustledger_loader::validation_error_to_ledger_error (process's
ledger_errors_extend calls it), and validation_error_to_wasm takes the
message, code, phase, hint and severity from it, placing the finding by
its own single-source rule as before. A finding's hint is its suggested
fix only, its note is folded into the message, its context is not
reported, and E1005 is phase "parse", as check reports them. rledger
check's output does not change.

test_validation_findings_match_the_loaders pins validateSource to the
loader field by field (message, code, phase, hint, file, line, column,
end, severity) on a failing balance and a ledger with several findings,
and one finding carrying a note, a context and a hint through both
conversions. WASM cache v111 (v110 is held by #2931), since a
ParsedLedger archives its findings; the loader cache stays at v73.

Closes #2972

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(wasm): pin E1005's phase, test the loader's finding conversion

Review of #2973:

- test_validation_findings_match_the_loaders gains an invalid-root
  ledger (E1005), so validateSource is compared with the loader on a
  parse-phase code, phase included. Forcing phase "validate" in
  validation_error_to_wasm now fails it.
- rustledger-loader tests validation_error_to_ledger_error directly:
  the note folded into the message, the context dropped, the hint kept,
  and a parse-phase code given phase "parse".
- The CHANGELOG breaking entry names every code whose context was a
  hint on validateSource: E2001, E2002, E2003, E8001 and E1005.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(changelog): name E2005, E4004 and both E8001 contexts among the hints validateSource drops

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant