Skip to content

feat(parser): #1262 phase 2.2b POSTING wraps posting sub-lines with indent-aware metadata attribution - #1276

Merged
robcohen merged 6 commits into
mainfrom
feat/cst-phase-2-2b-posting
Jun 6, 2026
Merged

robcohen merged 6 commits into
mainfrom
feat/cst-phase-2-2b-posting

Conversation

@robcohen

@robcohen robcohen commented Jun 6, 2026

Copy link
Copy Markdown
Member

Summary

Phase 2.2b of #1262 (following 2.2a META_ENTRY in #1275).

Sub-PR Scope
PR 2.2a META_ENTRY wrapping for indented WS META_KEY ... NEWLINE sub-lines (merged)
PR 2.2b (this PR) POSTING wrapping + indent-aware metadata attribution
PR 2.2c (next) AMOUNT / COST_SPEC / PRICE_ANNOTATION inside POSTING

What this PR ships

  • POSTING SyntaxKind added; both partition tests updated.
  • starts_posting_sub_line predicate: WS [(FLAG|STAR|PENDING_KW|single-char CURRENCY) WS] ACCOUNT .... The single-char-CURRENCY-as-flag arm mirrors identify_directive's same treatment for the transaction header (lexer priority 3 makes P/S/T/C/U/R/M tokenize as CURRENCY but they still function as posting flags by Beancount convention).
  • indent_width helper: byte length of the leading WHITESPACE token. Sufficient for the strictly-greater comparison the metadata-attribution rule needs.
  • emit_transaction_body rewritten as an indent-tracking state machine:
    • Posting line: close any open POSTING, open a new one.
    • Metadata sub-line: if a POSTING is open AND the indent is strictly greater, emit META_ENTRY inside the POSTING (mirrors the legacy AST parser's parse_posting_metadata DeepIndent loop). Otherwise close any open POSTING and emit META_ENTRY at TRANSACTION level.
    • Indented comment: close any open POSTING, emit flat at TRANSACTION level (matches AST parser's inter-posting-comment treatment).

Tests

14 new tests pinning the POSTING shape + 2 updated tests:

Test Pins
posting_wraps_account_only_line Auto posting (account only)
posting_wraps_account_with_amount_and_currency Full posting line
posting_wraps_each_of_multiple_postings_in_a_transaction One POSTING per line
posting_with_pending_flag_wraps_flag_inside_node ! flag wraps inside POSTING
posting_attached_meta_entry_lives_inside_posting Key 2.2b semantic: deeper indent → inside POSTING
posting_attached_meta_entry_at_same_indent_stays_at_transaction_level Same-indent metadata stays at TRANSACTION level
posting_attached_multiple_meta_entries_all_inside_posting Multiple posting-attached metadata lines
posting_attached_meta_entry_terminates_at_next_posting New POSTING starts clean
meta_entry_before_first_posting_stays_at_transaction_level No preceding POSTING → TRANSACTION level regardless of indent
posting_with_indented_comment_between_postings_terminates_posting Comment is inter-posting trivia
posting_at_eof_without_trailing_newline_still_wrapped Rule 5 unterminated case
star_flagged_posting_wraps_flag_inside_node * flag
flagged_posting_with_question_mark_wraps_flag_inside_node ? flag (one of the few that emits FLAG, not CURRENCY)
single_char_currency_flagged_posting_wraps_currency_as_flag Pins the lexer-priority-3 dual classification
transaction_blank_line_inside_body_terminates_and_orphans_subsequent_postings (updated) Counts POSTING nodes (not flat ACCOUNT tokens)
meta_entry_inside_transaction_body (updated) Adds POSTING-presence assertion; reworded

Manifest churn

cst-corpus.manifest regenerated against the 714-file corpus:

  • 518 of 714 entries changed node_shape_blake3.
  • token_seq_blake3 is byte-identical across all files — verified by diffing all removed token-seq hashes against added ones; every hash appears in pairs (1-to-1), no orphans. The phase-2 contract holds (no token-classification change).

What this PR does NOT add

  • AMOUNT / COST_SPEC / PRICE_ANNOTATION wrapping — PR 2.2c
  • Typed-AST Posting / MetaEntry accessors — phase 3

Why a separate POSTING PR

  • The indent-attribution state machine is the load-bearing complexity of phase 2.2; concentrating it in one PR lets reviewers focus on that one decision rule.
  • PR 2.2c (AMOUNT / COST_SPEC) becomes a pure sub-node refinement INSIDE the POSTING envelope this PR establishes.

Verified

  • 71 structured-directive tests (was 57) + 171 unit + 4 + 1 + 1 + 55 + 2 doctest pass.
  • cargo check --workspace --all-features --all-targets clean.
  • cargo clippy -p rustledger-parser --all-features --examples --tests -- -D warnings clean.
  • cargo fmt --all --check clean.
  • RUSTDOCFLAGS=-Dwarnings cargo doc -p rustledger-parser --no-deps clean.
  • STRICT_BASELINE=1 cargo test -p rustledger-parser --test cst_baseline passes against the regenerated manifest.

Refs #1262.

🤖 Generated with Claude Code

…butes metadata by indent

PR 2.2b of the parser-CST migration. Adds `POSTING` SyntaxKind and
wraps each posting sub-line inside `TRANSACTION` with indent-aware
metadata attribution.

Implementation:

- `POSTING` SyntaxKind variant added; both partition tests updated.
- `starts_posting_sub_line`: recognizes `WS [(FLAG|STAR|PENDING_KW|
  single-char CURRENCY) WS] ACCOUNT ...`. Single-char CURRENCY-as-
  flag arm mirrors `identify_directive`'s same treatment for the
  transaction header (lexer priority 3 makes single uppercase
  letters tokenize as CURRENCY, but they still function as flags
  by Beancount convention).
- `indent_width`: byte length of the leading WHITESPACE token.
  Sufficient for the strictly-greater comparison the metadata-
  attribution rule needs when the source uses uniform spaces.
- `emit_transaction_body` rewritten as a state machine tracking
  the most-recently-opened POSTING's indent depth:
  - Posting line: close any open POSTING, open a new one, consume
    through terminator.
  - Metadata sub-line: if a POSTING is open AND the indent is
    strictly greater, emit META_ENTRY INSIDE the POSTING (mirrors
    legacy AST parser's `parse_posting_metadata` DeepIndent loop).
    Otherwise close any open POSTING and emit META_ENTRY at
    TRANSACTION level.
  - Indented comment: close any open POSTING, emit flat at
    TRANSACTION level (matches the AST parser, which treats
    inter-posting comments as transaction-level).

Tests (14 new + 2 updated):

- `posting_wraps_account_only_line` — auto posting (account only)
- `posting_wraps_account_with_amount_and_currency` — full posting
- `posting_wraps_each_of_multiple_postings_in_a_transaction`
- `posting_with_pending_flag_wraps_flag_inside_node` — `!` flag
- `posting_attached_meta_entry_lives_inside_posting` — KEY: deeper
  indent → INSIDE POSTING (not TRANSACTION direct child)
- `posting_attached_meta_entry_at_same_indent_stays_at_transaction_level`
  — same-indent META_ENTRY is interspersed transaction-level
- `posting_attached_multiple_meta_entries_all_inside_posting`
- `posting_attached_meta_entry_terminates_at_next_posting` — new
  POSTING starts clean (no inherited metadata)
- `meta_entry_before_first_posting_stays_at_transaction_level` —
  no preceding POSTING to attach to, regardless of indent depth
- `posting_with_indented_comment_between_postings_terminates_posting`
- `posting_at_eof_without_trailing_newline_still_wrapped` — rule
  5 unterminated final case
- `star_flagged_posting_wraps_flag_inside_node` — `*` flag
- `flagged_posting_with_question_mark_wraps_flag_inside_node` — `?`
  flag (one of the few that actually emits FLAG, not CURRENCY)
- `single_char_currency_flagged_posting_wraps_currency_as_flag` —
  pins the lexer-priority-3 dual classification

Updated:

- `transaction_blank_line_inside_body_terminates_and_orphans_subsequent_postings`
  now counts POSTING nodes (not flat ACCOUNT tokens).
- `meta_entry_inside_transaction_body` adds POSTING-presence
  assertion; reworded to describe TRANSACTION-level shape.

Manifest: `cst-corpus.manifest` regenerated against the 714-file
corpus. The token_seq_blake3 column is byte-identical across all
files (phase-2 invariant: no token-classification change). Only
the node_shape_blake3 column churned — verified by diffing all
removed token_seq hashes against added ones (1-to-1 pairing).

Verified:

- 71 structured-directive tests (was 57) + 171 unit + 4+1+1+55+2
  doctest pass.
- `cargo check --workspace --all-features --all-targets` clean.
- `cargo clippy -p rustledger-parser --all-features --examples
  --tests -- -D warnings` clean.
- `cargo fmt --all --check` clean.
- `RUSTDOCFLAGS=-Dwarnings cargo doc -p rustledger-parser --no-deps`
  clean.
- `STRICT_BASELINE=1 cargo test -p rustledger-parser --test
  cst_baseline` passes against the regenerated manifest.

Refs #1262.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner June 6, 2026 10:13
Copilot AI review requested due to automatic review settings June 6, 2026 10:13
@codecov

codecov Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.60440% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-parser/src/cst/parser.rs 95.50% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds POSTING structure to the CST TRANSACTION body and attributes META_ENTRY sub-lines to either TRANSACTION or the preceding POSTING based on indent depth, continuing the phase-2 lossless CST migration for Beancount-style transactions.

Changes:

  • Introduces SyntaxKind::POSTING and updates SyntaxKind partition expectations.
  • Rewrites transaction-body emission into an indent-tracking state machine that wraps posting lines and attaches deeper-indented META_ENTRY lines under the open POSTING.
  • Expands/updates structured parser tests to pin POSTING wrapping and indent-aware metadata attribution semantics.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
crates/rustledger-parser/tests/structured_directives.rs Updates existing transaction tests and adds new cases pinning POSTING wrapping + indent-based metadata attribution.
crates/rustledger-parser/src/cst/syntax_kind.rs Adds POSTING SyntaxKind and updates node-kind partition lists/docs.
crates/rustledger-parser/src/cst/parser.rs Implements POSTING wrapping + indent-aware metadata attribution in emit_transaction_body and adds supporting helpers/docs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 35.3ms ± 0.6ms 25.3 MB
beancount 755.9ms ± 5.7ms 50.6 MB
Comparison 21.4x faster 2.0x less

vs main branch (2026-06-06)

Metric main this PR Change
Time 35.8ms 35.3ms -1.4% ✅
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@github-actions

github-actions Bot commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 792
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

robcohen and others added 5 commits June 6, 2026 12:29
…ings, doc-comments, manifest header)

Three CONFIRMED findings from the round-1 deep review of #1276 plus
one PLAUSIBLE doc improvement:

1. **HASH-flagged postings now wrapped in POSTING.** The legacy
   `parse_flag` (`parser.rs:436-439`) accepts `Token::Hash` and
   `identify_directive` already treats HASH as a transaction
   trigger, but `starts_posting_sub_line` omitted HASH from its
   flag alternation. Source `2024-01-15 * "x"\n  # Assets:Cash
   -5 USD\n` produced zero POSTING nodes. Added HASH to the arm,
   plus `hash_flagged_posting_wraps_hash_inside_node` regression.
   The rustdoc now explicitly names the flag set as needing to
   stay in sync with `parse_flag`.

2. **Deeper-indented comments stay inside open POSTING.** The
   `else` branch in `emit_transaction_body` previously closed the
   open POSTING on ANY non-posting / non-meta indented sub-line,
   including deeper-indented `;`/`%` comments. That broke the
   doc-comment-for-following-posting-metadata idiom: a deeper-
   indented comment followed by deeper-indented `key: value` would
   close the POSTING after the comment, then the META_ENTRY would
   land at TRANSACTION level instead of attaching to the now-
   closed POSTING. Asymmetric with `emit_directive_body`'s
   `block_has_meta` continuation policy. Fixed by adding a
   dedicated comment branch with the same indent-attribution rule
   as META_ENTRY: deeper than open POSTING -> stay inside;
   same/shallower -> close POSTING and emit at TRANSACTION level.
   Added `starts_indented_comment` predicate and two regression
   tests pinning both attached (with/without following meta) and
   inter-posting cases.

3. **Manifest header bumped to phase 2.2b.** Both
   `cst_baseline.rs:47` and the regenerated manifest's line-1
   header had been carrying "phase 2.1a" through 2.1b / 2.2a /
   2.2b regenerations. Header now matches reality.

4. **`indent_width` rustdoc strengthened.** Plausible-finding
   doc-improvement: the byte-length-vs-visual-column divergence
   from the legacy lexer's `Indent(N)` / `DeepIndent(N)` semantics
   (`logos_lexer.rs:615-616`, where `\t` counts as 4 spaces) is
   now explicitly documented as a known divergence on both
   `indent_width` and `emit_transaction_body`, with the rationale
   for not fixing yet (no corpus file triggers the divergence in
   posting-attached-metadata position, round-trip stays byte-
   identical regardless of classification) and the fix recipe if a
   file shows up. Defensive doc, not a behavior change.

Manifest churn: 1 line (the header only) — neither the HASH-flag
nor the deeper-comment fix moved any corpus file's node_shape
hash, confirming neither case appears in the corpus today. The
fixes are forward-looking guards.

Verified:

- 74 structured-directive tests (was 71) + 171 unit + 4 + 1 + 1 +
  55 + 2 doctest pass.
- `cargo check --workspace --all-features --all-targets` clean.
- `cargo clippy -p rustledger-parser --all-features --examples
  --tests -- -D warnings` clean.
- `cargo fmt --all --check` clean.
- `RUSTDOCFLAGS=-Dwarnings cargo doc -p rustledger-parser
  --no-deps` clean.
- `STRICT_BASELINE=1 cargo test -p rustledger-parser --test
  cst_baseline` passes against the regenerated manifest.

Refs #1262.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…oken helper, shared close-posting helper, 5 test additions)

Round-2 deep-review findings on #1276:

1. **SHEBANG / EMACS_DIRECTIVE now handled by the comment branch.**
   The Logos regexes `#![^\n\r]*` and `#\+[^\n\r]*` have no
   line-start anchor, so these tokens CAN appear at indent inside
   a transaction body. `is_trivia()` lists them as trivia, but
   `starts_indented_comment` only matched `COMMENT |
   PERCENT_COMMENT`, so a deeper-indented `#+STARTUP` etc. fell
   through to the catch-all `else` and closed the open POSTING —
   breaking the symmetry the comment branch was added to enforce.
   Fixed by factoring `is_comment_token(kind)` as the single
   source of truth for "is this a comment-class trivia token",
   covering all four comment-class kinds (COMMENT,
   PERCENT_COMMENT, SHEBANG, EMACS_DIRECTIVE), and routing the
   three existing call sites through it
   (`starts_indented_comment`, `upcoming_indented_block_has_meta`,
   `is_indented_directive_continuation`). Regression test
   `deeper_indented_shebang_or_emacs_directive_attaches_to_open_posting`.

2. **Extracted `close_open_posting_unless_attached` helper** so
   the META_ENTRY and indented-comment branches of
   `emit_transaction_body` no longer carry verbatim duplicates of
   the `attach_to_posting` / close-if-not-attached prelude. A
   future fix to the indent-attribution rule that updates one
   branch will auto-propagate to the other.

3. **Documented the catch-all `else` branch policy.** Added an
   inline comment naming PR 2.2c's relationship to this branch
   (AMOUNT continuations live INSIDE POSTING via
   `starts_posting_sub_line`, not via this branch) plus a
   regression test
   `catch_all_indented_unknown_content_closes_posting_and_emits_flat`
   pinning the current behavior on a stray indented STRING line.

4. **Five new tests pin previously-untested edges**:

   - `hash_flagged_posting_attached_meta_entry_lives_inside_posting`
     combines HASH-flagged posting with deeper-indented META so a
     future regression that drops HASH from
     `starts_posting_sub_line` fails AT ATTACHMENT, not just at
     basic shape.
   - `deeper_indented_trailing_comment_at_eof_stays_inside_posting`
     pins the EOF-without-newline case for the deeper-indent
     attachment rule.
   - `deeper_indented_shebang_or_emacs_directive_attaches_to_open_posting`
     pins the SHEBANG/EMACS_DIRECTIVE fix from (1).
   - `catch_all_indented_unknown_content_closes_posting_and_emits_flat`
     pins the catch-all `else` policy from (3).
   - `same_indent_comment_between_posting_and_deeper_meta_orphans_meta`
     pins Beancount's same-indent-break semantics: an explicit
     same-indent `;` comment between a posting and a deeper-
     indented META_KEY ends the posting-attached metadata block,
     and the META_ENTRY orphans to TRANSACTION level. Matches
     Python beancount's lex/yacc behavior; pinned so a future
     refactor can't silently flip the attribution.

Manifest churn: 0 lines — no corpus file exercises SHEBANG or
EMACS_DIRECTIVE indented inside a transaction body. The fixes are
forward-looking guards.

Verified:

- 79 structured-directive tests (was 74) + 171 unit + 4 + 1 + 1 +
  55 + 2 doctest pass.
- `cargo check --workspace --all-features --all-targets` clean.
- `cargo clippy -p rustledger-parser --all-features --examples
  --tests -- -D warnings` clean.
- `cargo fmt --all --check` clean.
- `RUSTDOCFLAGS=-Dwarnings cargo doc -p rustledger-parser
  --no-deps` clean.
- `STRICT_BASELINE=1 cargo test -p rustledger-parser --test
  cst_baseline` passes against the unchanged manifest.

Refs #1262.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…h predicate (Copilot review)

Three Copilot inline-review comments on #1276 flagged the same root
issue: the summary docstrings describing the POSTING-line
recognition shape omit `HASH` and single-char `CURRENCY` from the
flag set, even though `starts_posting_sub_line` accepts both.
`starts_posting_sub_line`'s own rustdoc was correct; three "higher-
level" summaries were stale.

Updated all three sites to list the full flag set
`FLAG | STAR | PENDING_KW | HASH | single-char CURRENCY`:

- `cst/parser.rs` module rustdoc phase 2.2b summary
- `cst/parser.rs` `emit_transaction_body` state-machine docstring,
  with a cross-reference to `starts_posting_sub_line` as the source
  of truth
- `cst/syntax_kind.rs` `POSTING` SyntaxKind variant comment, with a
  one-line note on HASH-as-flag and single-char CURRENCY-vs-Flag
  tie-break for self-contained enum-level grammar

No code changes. Tests, clippy, fmt, doc all clean (79 structured-
directive tests pass).

Refs #1262, #1276.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…rgence rustdoc, coverage gaps, drift guard, helper cleanup)

Round-3 deep-review findings on #1276:

1. **`is_comment_token` CST/AST divergence documented.** The
   round-2 widening (adding SHEBANG / EMACS_DIRECTIVE) put the
   CST in disagreement with the legacy AST parser, which only
   handles Comment/PercentComment in-body (`parser.rs:1225`).
   Phase-isolated (nothing downstream consumes `parse_structured`
   yet); reconciled in phase 5 when `parse_flat` and the AST
   converge. Documented as a known divergence on
   `is_comment_token`'s rustdoc so future readers don't read it as
   a bug.

2. **5 new tests pin previously-unverified branches**:

   - `deeper_indented_shebang_attaches_to_open_posting`: SHEBANG
     (`#!`) was claimed but not tested. Split from the previous
     `deeper_indented_shebang_or_emacs_directive_attaches_to_open_posting`
     (renamed to `deeper_indented_emacs_directive_attaches_to_open_posting`
     to drop the misleading "or shebang" claim) so each token kind
     has its own pin.
   - `deeper_indented_percent_comment_attaches_to_open_posting`:
     PERCENT_COMMENT (`%`) was in `is_comment_token` but every
     other attribution test used `;`. Adds coverage for the `%`
     path through all three predicates.
   - `directive_body_absorbs_indented_emacs_directive_when_block_has_meta`:
     pins the directive-body widening for OPEN_DIRECTIVE +
     EMACS_DIRECTIVE + META (a continuation when block_has_meta is
     true). The widening was a side effect of routing
     `upcoming_indented_block_has_meta` and
     `is_indented_directive_continuation` through `is_comment_token`;
     only the transaction-body case was previously pinned.
   - `directive_body_does_not_absorb_indented_emacs_directive_when_no_meta`:
     complementary case — header-only OPEN_DIRECTIVE followed by
     EMACS_DIRECTIVE then another OPEN_DIRECTIVE. The
     EMACS_DIRECTIVE is rule-2 inter-directive trivia leading the
     next directive, NOT absorbed by the header-only first one.

3. **Drift guard test `is_comment_token_covers_all_comment_class_trivia`**
   in `cst::parser::tests`. Iterates every valid SyntaxKind
   discriminant; for each one in `is_trivia()` that is not BOM /
   WHITESPACE / NEWLINE, asserts `is_comment_token` returns true.
   Forces an explicit decision when a future PR adds a new trivia
   variant (either add to `is_comment_token` or extend the allow-
   list in the test).

4. **`emit_directive_body` rustdoc updated** to reference
   `is_comment_token` instead of listing `COMMENT / PERCENT_COMMENT`
   (which was stale post-round-2 widening).

5. **`close_open_posting_unless_attached` return value removed.**
   Neither caller used it, AND `attach=false` conflated "no posting
   open" with "should close" — a footgun for a hypothetical third
   caller. Function is now `fn(...)` returning `()`.

6. **`same_indent_comment_between_posting_and_deeper_meta_orphans_meta`
   test comment softened.** The previous claim "Matches Beancount's
   lex/yacc semantics" was unverified (only the legacy AST parser
   was consulted). Updated to "Matches the legacy AST parser's
   `parse_posting_metadata` loop" (verified) with an explicit note
   that Python beancount parity is NOT verified and the test is
   the touch-point for a future compat audit.

Manifest churn: 0 lines — none of these fixes change parser
behavior on the corpus.

Verified:

- 83 structured-directive tests (was 79) + 172 unit (was 171, +1
  drift guard) + 4 + 1 + 1 + 55 + 2 doctest pass.
- `cargo check --workspace --all-features --all-targets` clean.
- `cargo clippy -p rustledger-parser --all-features --examples
  --tests -- -D warnings` clean.
- `cargo fmt --all --check` clean.
- `RUSTDOCFLAGS=-Dwarnings cargo doc -p rustledger-parser
  --no-deps` clean.
- `STRICT_BASELINE=1 cargo test -p rustledger-parser --test
  cst_baseline` passes against the unchanged manifest.

Refs #1262.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…tightening, increasing-indent pin, test walker symmetry, doc tweaks)

Round-4 deep-review findings on #1276:

1. **Drift guard tightened to bidirectional invariant.** The test
   previously asserted only `is_trivia() ⊆ is_comment_token` (modulo
   the BOM/WHITESPACE/NEWLINE allow-list). A future edit that
   adds a non-trivia kind to `is_comment_token`'s match arm (or
   moves a kind out of `is_trivia` without updating
   `is_comment_token`) would silently extend indent-attribution to
   real content tokens. Added the complementary check
   `is_comment_token ⊆ is_trivia()`. Failure messages also now
   explicitly name the THIRD option for a new trivia kind that's
   neither comment-class nor whitespace-class: revisit whether
   the body-continuation predicates need a separate abstraction.

2. **Increasing-indent sibling POSTINGs pinned by test + rustdoc.**
   `emit_transaction_body`'s POSTING-line branch unconditionally
   closes any open POSTING regardless of indent, then opens a new
   one at `sub_line_indent`. Postings at non-uniform indents
   therefore produce sibling POSTING nodes, and subsequent META
   attributes against the most-recently-opened POSTING's indent.
   Pinned by `postings_at_increasing_indents_produce_siblings_and_meta_attributes_to_latest`
   so any future monotonic-indent refactor is a visible,
   intentional break. Rustdoc on the POSTING-line branch now
   states this defensive shape.

3. **Test walker symmetry fixed for the directive-body tests.**
   `directive_body_absorbs_indented_emacs_directive_when_block_has_meta`
   previously used `descendants_with_tokens` for the inclusion
   check but `children_with_tokens` for the orphan check — a
   future refactor wrapping SOURCE_FILE-level trivia in any
   nested node would pass the orphan check vacuously. Both tests
   now use `descendants_with_tokens` symmetrically and add a
   total-count sanity assertion. Test #3 also gained a META_ENTRY
   assertion so a regression in the META_KEY arm of
   `is_indented_directive_continuation` fails here, not silently.

4. **CST/AST divergence rustdoc tightened.** Line anchors
   `parser.rs:1225` and `parser.rs:1756` replaced with symbol
   names (`parse_posting_metadata`,
   `parse_transaction_directive`, `parse_directive` dispatch) so
   the rustdoc doesn't drift on refactors of the AST parser. The
   "nothing downstream" framing now explicitly names this crate's
   corpus baseline test AND `examples/dump_top_level_directives.rs`
   as the only `parse_structured` consumers (instead of glossing
   over the example). The rustdoc also takes a position on phase
   5 reconciliation: adopt the CST behavior (consistent with
   `is_trivia()`'s classification) rather than the AST behavior.

Manifest churn: 0 lines.

Verified:

- 84 structured-directive tests (was 83) + 172 unit + 4 + 1 + 1 +
  55 + 2 doctest pass.
- `cargo check --workspace --all-features --all-targets` clean.
- `cargo clippy -p rustledger-parser --all-features --examples
  --tests -- -D warnings` clean.
- `cargo fmt --all --check` clean.
- `RUSTDOCFLAGS=-Dwarnings cargo doc -p rustledger-parser
  --no-deps` clean.
- `STRICT_BASELINE=1 cargo test -p rustledger-parser --test
  cst_baseline` passes against the unchanged manifest.

Refs #1262.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@robcohen
robcohen enabled auto-merge (squash) June 6, 2026 20:52
@robcohen
robcohen merged commit 6aaaa12 into main Jun 6, 2026
38 checks passed
@robcohen
robcohen deleted the feat/cst-phase-2-2b-posting branch June 6, 2026 20:56
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.

2 participants