diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 3c06fe1e8..31a949bc9 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -721,7 +721,7 @@ priceamountp = option NoPrice $ do priceConstructor <- char '@' *> pure TotalPrice <|> pure UnitPrice lift (skipMany spacenonewline) - priceAmount <- amountwithoutpricep "amount (as a price)" + priceAmount <- amountwithoutpricep "unpriced amount (specifying a price)" pure $ priceConstructor priceAmount @@ -731,14 +731,17 @@ balanceassertionp = do char '=' exact <- optional $ try $ char '=' lift (skipMany spacenonewline) - a <- amountp "amount (for a balance assertion or assignment)" -- XXX should restrict to a simple amount + a <- amountwithoutpricep "unpriced amount (for a balance assertion or assignment)" return BalanceAssertion { baamount = a , baexact = isJust exact , baposition = sourcepos } --- http://ledger-cli.org/3.0/doc/ledger3.html#Fixing-Lot-Prices +-- Parse a Ledger-style fixed lot price: {=PRICE} +-- https://www.ledger-cli.org/3.0/doc/ledger3.html#Fixing-Lot-Prices . +-- Currently we ignore these (hledger's @ PRICE is equivalent), +-- and we don't parse a Ledger-style {PRICE} (equivalent to Ledger's @ PRICE). fixedlotpricep :: JournalParser m (Maybe Amount) fixedlotpricep = optional $ do try $ do @@ -747,7 +750,7 @@ fixedlotpricep = optional $ do lift (skipMany spacenonewline) char '=' lift (skipMany spacenonewline) - a <- amountp -- XXX should restrict to a simple amount + a <- amountwithoutpricep "unpriced amount (for an ignored ledger-style fixed lot price)" lift (skipMany spacenonewline) char '}' return a diff --git a/hledger-lib/hledger_journal.m4.md b/hledger-lib/hledger_journal.m4.md index 1dc5297fa..7f63f0e65 100644 --- a/hledger-lib/hledger_journal.m4.md +++ b/hledger-lib/hledger_journal.m4.md @@ -436,6 +436,11 @@ One workaround is to isolate each commodity into its own subaccount: a:euro 0 == 1€ ``` +### Assertions and prices + +Balance assertion (or assignment) amounts should not have a [price](#transaction-prices), +as the meaning of that would be unclear. + ### Assertions and subaccounts Balance assertions do not count the balance from subaccounts; they check diff --git a/tests/journal/balance-assertions.test b/tests/journal/balance-assertions.test index fab8d357f..e247f668e 100755 --- a/tests/journal/balance-assertions.test +++ b/tests/journal/balance-assertions.test @@ -356,3 +356,12 @@ hledger -f - stats >>> /Transactions/ >>>2 >>>=0 + +# 20. Balance assertions may not have a price in them. +hledger -f- stats +<<< +2019/01/01 + (a) 1A = 1A @ 2B +>>> +>>>2 /unexpected '@'/ +>>>=1