Skip to content

feat(parser): #1262 phase 2.2a META_ENTRY sub-node wraps indented metadata sub-lines - #1275

Merged
robcohen merged 4 commits into
mainfrom
feat/cst-phase-2-2a-meta-entry
Jun 6, 2026
Merged

robcohen merged 4 commits into
mainfrom
feat/cst-phase-2-2a-meta-entry

Conversation

@robcohen

@robcohen robcohen commented Jun 6, 2026

Copy link
Copy Markdown
Member

Summary

Phase 2.2 of #1262 split into smaller PRs by sub-structure type (following the PR 2.1a/2.1b precedent):

Sub-PR Scope
PR 2.2a (this PR) META_ENTRY wrapping for indented WS META_KEY ... NEWLINE sub-lines
PR 2.2b (next) POSTING wrapping for WS ACCOUNT ... lines inside transactions
PR 2.2c (after) AMOUNT / COST_SPEC / PRICE_ANNOTATION inside POSTING

What this PR ships

  • META_ENTRY SyntaxKind variant added.
  • emit_body_sub_line helper called from both emit_directive_body and emit_transaction_body. When an indented sub-line is WS META_KEY ..., it gets wrapped in a META_ENTRY node; otherwise (indented ;-comments, and any future POSTING line) it flows through as flat children of the parent directive.
  • is_indented_meta_sub_line predicate centralizes the WS + META_KEY recognition (mirrors the existing is_indented_directive_continuation / is_indented_transaction_body_line predicates).
  • Parser module rustdoc updated: phase 2.2a now lands META_ENTRY; phase 2.2b/c flagged for POSTING / AMOUNT / COST_SPEC.

Tests

5 new tests pinning the META_ENTRY shape + 1 updated test:

Test Pins
meta_entry_wraps_metadata_sub_line_inside_open_directive Basic META_ENTRY shape on OPEN_DIRECTIVE
meta_entry_wraps_each_of_multiple_metadata_sub_lines One META_ENTRY per META_KEY line; exact internal token sequence
meta_entry_does_not_wrap_indented_comments Indented ;-comments stay flat between META_ENTRY siblings, not absorbed
meta_entry_inside_transaction_body META_ENTRY works the same inside TRANSACTION as inside dated directives
meta_entry_with_value_kinds_other_than_string META_ENTRY wraps regardless of value kind (NUMBER, DATE, ACCOUNT, ...)
commodity_with_metadata_wraps_full_multi_line_directive (updated) The PR's structural diff is now pinned

What this PR does NOT add

  • POSTING wrapping — PR 2.2b
  • AMOUNT / COST_SPEC / PRICE_ANNOTATION wrapping — PR 2.2c
  • Typed-AST Posting / MetaEntry accessors — phase 3
  • Polarmutex-style structural-comment-slot — still a phase 2.1 grammar option, unchanged

Why a separate META_ENTRY PR

  • Mechanically uniform across every directive kind that takes metadata; concentrated to one helper + predicate
  • Drives node_shape baseline churn in a controlled, single-purpose way
  • token_seq stays byte-identical (no token classification change) — phase-2 contract held
  • PR 2.2b (POSTING) and PR 2.2c (AMOUNT/COST_SPEC) build on top: POSTING's per-line dispatch reuses emit_body_sub_line's shape

Verified

  • 56 structured-directive tests (was 51) + 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.
  • cargo deny check bans 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 804-file manifest.

Refs #1262.

🤖 Generated with Claude Code

…adata sub-lines

Phase 2.2 of #1262 is split into smaller PRs by sub-structure
type (following the PR 2.1a/2.1b precedent for reviewable scope).
This is PR 2.2a — META_ENTRY wrapping; PR 2.2b will add POSTING;
PR 2.2c will add AMOUNT / COST_SPEC / PRICE_ANNOTATION.

## What this PR ships

- `META_ENTRY` SyntaxKind variant added.
- New `emit_body_sub_line` helper called from both
  `emit_directive_body` and `emit_transaction_body`. When an
  indented sub-line is `WS META_KEY ...`, it gets wrapped in a
  META_ENTRY node; otherwise (indented `;`-comments and any future
  POSTING line) it flows through as flat children of the parent
  directive — consistent with both the trivia.rs spec's "metadata
  block" terminology and PR 2.2b's planned POSTING wrapping.
- `is_indented_meta_sub_line` predicate centralizes the
  `WS + META_KEY` recognition.
- Parser module rustdoc updated: phase 2.2a now lands META_ENTRY;
  phase 2.2b/c are flagged for POSTING / AMOUNT / COST_SPEC.
- 5 new source-driven tests:
  - `meta_entry_wraps_metadata_sub_line_inside_open_directive`
  - `meta_entry_wraps_each_of_multiple_metadata_sub_lines`
  - `meta_entry_does_not_wrap_indented_comments`
  - `meta_entry_inside_transaction_body`
  - `meta_entry_with_value_kinds_other_than_string`
- `commodity_with_metadata_wraps_full_multi_line_directive`
  updated to assert the new META_ENTRY shape (the structural
  diff this PR introduces).
- Closed-form partition test + `nodes_are_not_tokens` test
  include META_ENTRY.

## What this PR does NOT add

- POSTING wrapping (PR 2.2b)
- AMOUNT / COST_SPEC / PRICE_ANNOTATION wrapping (PR 2.2c)
- Typed-AST `Posting`/`MetaEntry` accessors (phase 3)
- The "structural trailing-comment slot" pattern flagged in
  phase 2.0's rustdoc (polarmutex prior art) — still a phase 2.1
  grammar option that hasn't been picked up; PR 2.2a is purely
  the wrapper around the existing flat metadata content.

## Why a separate META_ENTRY PR

- Mechanically uniform across every directive kind that takes
  metadata; the change is concentrated to one new helper +
  predicate.
- Drives node_shape baseline churn in a controlled way: every
  corpus file containing indented metadata sees its node_shape
  hash change, but token_seq stays byte-identical (no token
  classification change).
- PR 2.2b (POSTING) and PR 2.2c (AMOUNT/COST_SPEC) build on
  top — POSTING's body parser will reuse `emit_body_sub_line`'s
  per-line dispatch shape.

## Verified

- 56 structured-directive tests (was 51) + 171 unit + 4+1+1+55+2
  doctest pass.
- cargo check workspace, clippy -D warnings, fmt check, deny
  check bans, RUSTDOCFLAGS=-Dwarnings cargo doc — all clean.
- STRICT_BASELINE=1 cargo test ... cst_baseline passes against
  the regenerated 804-file manifest. token_seq column unchanged
  vs main wherever source unchanged (phase-2 contract held);
  node_shape column churns on every corpus file that contains
  indented metadata.

Refs #1262.

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

codecov Bot commented Jun 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 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

This PR advances the CST “structured parse” migration (tracking #1262) by introducing a dedicated META_ENTRY node that wraps indented metadata sub-lines (WS META_KEY ...) inside both dated directives and transaction bodies, while keeping other indented sub-lines (e.g., indented comments, future postings) as flat children of the parent node.

Changes:

  • Added SyntaxKind::META_ENTRY and updated SyntaxKind node-kind tests accordingly.
  • Introduced emit_body_sub_line + is_indented_meta_sub_line in the CST parser and used it from both directive-body and transaction-body emission paths to wrap metadata lines.
  • Added/updated structured-parser tests to pin the new META_ENTRY node shape and ensure indented comments are not wrapped.

Reviewed changes

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

File Description
crates/rustledger-parser/src/cst/parser.rs Adds helper + predicate to wrap indented metadata sub-lines into META_ENTRY during structured CST emission.
crates/rustledger-parser/src/cst/syntax_kind.rs Introduces the META_ENTRY node kind and updates node/token classification tests.
crates/rustledger-parser/tests/structured_directives.rs Adds tests asserting META_ENTRY wrapping behavior across directives and transactions; updates an existing commodity+metadata shape test.

💡 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 34.3ms ± 0.8ms 25.4 MB
beancount 793.9ms ± 6.7ms 50.6 MB
Comparison 23.1x faster 2.0x less

vs main branch (2026-06-06)

Metric main this PR Change
Time 35.8ms 34.3ms -4.2% ✅
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 3 commits June 6, 2026 10:42
…b-line predicate

Round-1 review surfaced 2 low-severity findings:

1. Predicate-pair drift hazard: is_indented_meta_sub_line and the
   META_KEY arm of is_indented_directive_continuation independently
   encoded the same WS+META_KEY shape. A future PR widening one
   without the other could leave the directive body consuming
   sub-lines that arent wrapped, or wrapping sub-lines the body
   loop doesnt reach — no compile-time signal.

   Renamed is_indented_meta_sub_line to starts_meta_sub_line and
   routed is_indented_directive_continuations META_KEY arm through
   it. Single source of truth for the WS+META_KEY pattern.

2. PR 2.2b will need to relocate posting-attached metadata from
   TRANSACTIONs direct children to POSTINGs children. Added a
   forward-looking rustdoc note on emit_transaction_body explicitly
   calling this out so the future PR author knows that 2.2as
   meta_entry_inside_transaction_body assertion (counting direct
   children of TRANSACTION) is intentional for 2.2a but will need
   updating when 2.2b lands.

No behavior change. 56 structured-directive tests + 171 unit +
4+1+1+55+2 doctest pass. Clippy, fmt, doc, deny check, strict
baseline all clean.

Refs #1262.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…rminated EOF case

Copilot inline review flagged 3 places where the rustdoc claims
META_ENTRY contains a terminator NEWLINE, but per rule 5 of
cst::trivia (and emit_through_terminators NEWLINE-or-EOF stop
condition), an unterminated final metadata sub-line at EOF still
gets wrapped — its META_ENTRY just has no NEWLINE child. All three
docs updated:

- cst/parser.rs module rustdoc: WS META_KEY ... (NEWLINE OR EOF)
- emit_body_sub_line rustdoc: explicit note about the
  unterminated final sub-line case
- META_ENTRY SyntaxKind variant comment: same explicit note

Added meta_entry_at_eof_without_trailing_newline test that asserts
the META_ENTRY's exact element sequence is WHITESPACE META_KEY
WHITESPACE STRING with no NEWLINE for the source
`2024-01-01 open Assets:Cash\n  key: "v"` — pinning the rustdoc
claim with a concrete shape assertion.

57 tests (was 56) + 171 unit + 4+1+1+55+2 doctest pass. Clippy,
fmt, doc all clean.

Refs #1262.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…2.2b relocates

Round-2 deep-review finding: the forward-looking rustdoc on
`emit_transaction_body` miscited `meta_entry_inside_transaction_body`
as a test that PR 2.2b will need to update. That test's metadata is
2-space-indented BEFORE postings (transaction-level), which stays
at TRANSACTION level even after PR 2.2b. Only deeper-indented
metadata FOLLOWING a posting gets relocated to the posting.

Rewrote the rustdoc to explicitly distinguish:

- TRANSACTION-level metadata (standard indent, before or between
  postings at that same depth) stays a direct child of TRANSACTION
- POSTING-attached metadata (deeper indent following a posting)
  must be relocated by PR 2.2b

No existing PR 2.2a test pins the posting-attached shape; PR 2.2b
should add such tests alongside the relocation logic.

Refs #1262.

Co-Authored-By: Claude Opus 4.7 (1M context) <[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.

2 participants