Skip to content

End an account header's name at a hard-separated comment - #7

Merged
jwiegley merged 2 commits into
mainfrom
johnw/account-header-comment
Nov 5, 2026
Merged

jwiegley merged 2 commits into
mainfrom
johnw/account-header-comment

Conversation

@jwiegley

@jwiegley jwiegley commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

  • An account header now names the account by the text before the first ; that follows a hard separator, a tab or two or more spaces (headerAccount). That ; begins a comment, as it does after the payee on a transaction's first line. The engine took the whole remainder of the line, so account Expenses:Food ; groceries declared Expenses:Food ; groceries. A ; after a single space, or after none, stays part of the name, as it does in a posting's account, so account foo ; bar still declares foo ; bar.
  • The rule applies to the plain header, to its deprecated @account and !account spellings, and to a nested account line inside an account block. The scan starts after the blanks before the name, as the C++ reader's does.
  • This follows the C++ fix for account directive parsing with ; ledger#3320, where account baz ; bar declared an account named baz ; bar. C++ now ends the name by the rule that ends a transaction's payee (split_inline_note in utils.h, called by account_directive_body). The two readings differed only when such a header's block held an alias, payee or default line, which then named a different account on each side.
  • Witness: test/regress/3320_3.test in ledger/ledger (plain, nested and !account headers with comments, binding an alias, a payee rule and the default account). Each rule's comment cites its test, and the helper's comment cites the C++ function it mirrors.

ledger/ledger#3324, which fixes C++, moves both pins (the flake input and the lean/ submodule) to this branch's commit, 7e7ac7c. It edits only the account-header lines, which are separated by unchanged lines from the commodity header lines that #6 edits, and git merge-tree of this branch with each of #3, #4, #5 and #6 is clean; whichever ledger pull request merges last re-pins to a main that holds all the rules. Please merge this with a merge commit, as #1 and #2 were, so that commit stays reachable from main.

Test plan

  • nix build .#oracle -L: the build completes, so every proof checks and no warning was raised
  • Bisimulation of the fixed C++ build against this oracle over the whole C++ suite (test/semantic/check_all.py): 3802 PASS, 0 FAIL, 0 out-of-scope, 0 cpp-parse (492 negative, 78 no-journal, 2 python) over 4374 test files
  • The same oracle against ledger main (d39fccd8b), which the pin bump alone produces: 3799 PASS, 0 FAIL, 0 out-of-scope, 0 cpp-parse (491 negative, 78 no-journal, 2 python)
  • With the pinned oracle f5d891e, the fixed C++ build fails on exactly 3320_3.test (only_oracle: $|15|Expenses:Food ; groceries and restaurants, only_cpp: $|17|Expenses:Food)

🤖 Generated with Claude Code

https://claude.ai/code/session_01FypysHp6zVrvs3VFThm468

jwiegley and others added 2 commits November 4, 2026 11:13
C++ Ledger now lets a commodity block's format sub-directive spell
the block's symbol bare, as the commodity header does, although an
amount must quote it (ledger/ledger#3312): `commodity N1` with
`format 1,000.00 N1` declares the display precision of N1.  This
reader took the bare N1 for a malformed commodity and skipped the
format line, so N1 kept the precision its postings had taught it.

Before parseAmount reads the sample, quote a bare occurrence of the
block's symbol at either end of it, under the C++ conditions: the
symbol needs quotes by the C++ table (commodity.cc invalid_chars,
which is not this reader's validCommodity), the sample quotes
nothing itself, and the symbol does not run into the number between
two characters of a number.  The witness is regress/3312, whose N1
balance rounds to the format's two places only under this rule.

Verified as follows.  `nix build .#oracle` exits 0, so every proof
checks.  test/semantic/check_all.py, run with the fixed C++ build
against this oracle over the whole C++ suite, reports 3800 PASS and
0 FAIL (491 negative, 77 without a journal, 2 with Python).  The
same run against f5d891e fails on exactly regress/3312, where the
oracle keeps 1234.567 N1 and C++ rounds to 1234.57.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CBCCbSZ9jNESexSR5iwBDC
The journal engine took the whole remainder of an `account` line as
the name it declares, so `account Expenses:Food  ; groceries` declared
`Expenses:Food  ; groceries`.  The fix for ledger/ledger#3320 has the
C++ reader end the name at the first `;` that follows a hard
separator, a tab or two or more spaces, which begins a comment there
as it does after the payee on a transaction's first line
(`split_inline_note` in utils.h, called by `account_directive_body`).
A `;` after a single space, or after none, stays part of the name, as
it does in a posting's account.  The two readings differed only when
such a header's block held an `alias`, `payee` or `default` line,
which then named a different account on each side.

`headerAccount` applies that rule to the `account` header, to its
deprecated `@account` and `!account` spellings, and to a nested
`account` line inside an account block, after skipping the blanks
before the name as C++ does, so `account  ; x` still names `; x`.

The witness is regress/3320_3 on the ledger branch johnw/fix-3320.
With this oracle and that branch, test/semantic/check_all.py reported
3802 PASS and 0 FAIL over 4374 test files, with both ratchet bins
empty, and with this oracle and ledger main at d39fccd8b it reported
3799 PASS and 0 FAIL over 4370.  With the oracle at f5d891e, the
branch failed exactly regress/3320_3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypysHp6zVrvs3VFThm468
@jwiegley
jwiegley force-pushed the johnw/account-header-comment branch from 7e7ac7c to 8342e12 Compare November 4, 2026 21:39
@jwiegley
jwiegley merged commit 8342e12 into main Nov 5, 2026
3 checks passed
@jwiegley
jwiegley deleted the johnw/account-header-comment branch November 5, 2026 06:32
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