Skip to content

compat(parser): a pushtag, poptag or popmeta with an invalid date changes no state, and a pop error is on the pop's own line #2995

Done

Description

@robcohen

Root causes, both in the push/pop state walk:

  1. header_has_invalid_token only looks for ERROR_TOKEN. An invalid date on the header also fails beancount's reduction (the lexer raises it), so beancount neither pushes nor pops; main does both.
  2. InvalidPoptag / InvalidPopmeta use node_span(node.syntax()), which starts at leading trivia (comment lines stored at the start of the node), so the error lands on the comment line.
Shape Input beancount main
Pop with a date error still pops P + "pushtag #a\npoptag #a 2024-02-30\n" 0 3 (unbalanced push + date) 3
P + 'pushmeta kk: "v"\npopmeta kk: 2024-02-30\n' 0 3 3
Push with a date error still pushes P + "pushtag #a 2024-02-30\npoptag #a\n" 2 3 (date + pop absent tag) 2
P + 'pushtag #a 2024-02-30\n2024-01-02 * "n"\n Assets:A 1 USD\n Assets:A -1 USD\n' 2 2x2 (also pushtag 'a' was never popped; the transaction is tagged #a in main only)
"pushtag #a 2024-02-30\n ; c\npoptag #a\n" 1 3 1
Pop error on the leading comment line (#2888 row) 'pushmeta kk: "v" $\n ; c\npopmeta kk:\n' 1 3 1 2
"pushtag #a $\n ; c\npoptag #a\n" 1 3 1 2
(with the one-letter key k: the popmeta is itself an invalid token, and it matches: 1x2 3)

Suspected location: crates/rustledger-parser/src/cst/convert.rs, the Pushtag / Poptag / Popmeta arms (~311-370) and header_has_invalid_token (~3916). pushmeta with a date error already matches because pushmeta_value fails on it.

Fix direction: treat an invalid DATE token on the header line like an ERROR_TOKEN in header_has_invalid_token (or a sibling predicate), and give the pop errors the header-line span (first content token to the line's end) instead of the node span. This also removes the line-2 never popped error in #2993's pushtag #a 2024-02-30 row.

Measurement

Measured 2026-11-15 on origin/main 11bc426ac36 (includes #2985, #2986, #2988, #2990, #2991; #2992 not merged yet).

  • beancount side: beancount 3.2.3 in localhost/rustledger-compat, beancount.parser.parser.parse_string for parse rows (the parity harness's ground truth), beancount.loader.load_string for validation rows. Errors are raw: none are filtered.
  • rledger side: parse_error_lines example (rustledger_parser::parse + LineIndex, as in the parity harness) for parse rows, rledger check --format json for validation rows.
  • Counts are per-line: 3x2 is two errors on line 3, 2 4 is one on line 2 and one on line 4, 0 is beancount's "line 0" (end of file), - is no error.

Shorthand used in the inputs:

  • P = 2024-01-01 open Assets:A\n (the prefix the original table used)
  • S = 2024-02-30 5\n (the indented invalid-date line the original table used)
  • T = 2024-01-02 * "n"\n
  • O2 = 2024-01-01 open Assets:A\n2024-01-01 open Assets:B\n
  • <BOM> = U+FEFF

Split from #2872 (re-measured there; see the comment that lists where each row went).

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions