Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: support arithmetic expressions in posting amounts
Fixes #2648.
What this does
Posting amounts can now contain simple arithmetic, so the parts stay visible
in the journal instead of being hand-added first:
Supported:
+ - * /with normal precedence, and parentheses.$21.60 + $27.68prints as$49.28.The issue's example works:
$-50.20 + $-209.00 + $-16.54 + $-438gives$-713.74.Tax-style scaling works too:
(1 + 0.05) * $47.97gives$50.3685.Rules
+and-need the same commodity on both sides. A bare number takes theother side's commodity, so
$5 + 3is$8.*and/need a plain number on the right.*also allows a bare number(or bracketed expression) on the left, so
(1 + 0.05) * $47.97is valid.at the bad region.
result (
$4.20 * 2stays$8.40). Division is computed with 6 extra places,then trailing zeroes are trimmed.
)is no longer accepted as an unquoted commodity character, so bracketedexpressions parse. Use
")"quoted if a symbol really needs it.Files
hledger-lib/Hledger/Read/Common.hs— expression parser (simpleamountpnow parses additive/multiplicative/primary levels),
applyArithOp, tests.hledger-lib/Hledger/Data/Amount.hs— one-char change to the commodity list.hledger/hledger.m4.md— short docs section.Testing
cabal run hledger-lib:unittest -- -p 'amountp': 14/14 pass (9 new cases).cabal run hledger-lib:unittest: 249/249 pass.hledgerbinary and ranprinton the examples above; outputmatches, and the balanced postings still balance.
(1 + 1)amount) out ofledger-compat/hledger-unsupported.test(it asserted failure, which thisfeature intentionally changes) into
journal/amounts-and-commodities.testas case 28, asserting the new
printoutput. Both files pass locally(32/32 via shelltest).
AI disclosure (required by hledger.org/AI.html rule 4)
AI assistance: yes. Provider/model: Muse Spark (Meta, agentic coding in
opencode). Rough output: on the order of tens of thousands of tokens across
debugging and test-fix iterations. I reviewed, tested, and take responsibility
for every line (rule 7). Note: this would be my first hledger PR — flagging
per rule 6; happy to rework or hand-rewrite anything the maintainer prefers.
No OpenAI models used (rule 5).