diff --git a/MANUAL.md b/MANUAL.md index 0ec04c849..8ad2010e3 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -343,10 +343,16 @@ hledger currently ignores them. They look like this: ledger supports [balance assertions](http://ledger-cli.org/3.0/doc/ledger3.html#Balance-assertions): -following a posting's amount, an equals sign and another amount which -is the expected balance in this account at this point. hledger does -not support this feature, but will parse and ignore such assertions, -so you can put them in your journal and test with ledger if needed. +following a posting's amount, an equals sign and another amount which is +the expected balance in this account at this point. hledger does not +currently enforce these but will ignore them, so you can put them in your +journal and test with ledger if needed. + +### Fixed Lot Prices + +Similarly, we ignore ledger's +[fixed lot prices](http://ledger-cli.org/3.0/doc/ledger3.html#Fixing-lot-prices). +hledger's [prices](#transaction-prices) always work like ledger's fixed lot prices. ### Comments diff --git a/hledger-lib/Hledger/Data/Commodity.hs b/hledger-lib/Hledger/Data/Commodity.hs index a99f433bb..3f807557e 100644 --- a/hledger-lib/Hledger/Data/Commodity.hs +++ b/hledger-lib/Hledger/Data/Commodity.hs @@ -18,7 +18,8 @@ import Hledger.Data.Types import Hledger.Utils -nonsimplecommoditychars = "0123456789-.@;\n \"" :: String +-- characters than can't be in a non-quoted commodity symbol +nonsimplecommoditychars = "0123456789-.@;\n \"{}" :: String quoteCommoditySymbolIfNeeded s | any (`elem` nonsimplecommoditychars) s = "\"" ++ s ++ "\"" | otherwise = s diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index f9c86631c..ab582ed21 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -489,6 +489,7 @@ posting = do let (ptype, account') = (accountNamePostingType account, unbracket account) amount <- spaceandamountormissing _ <- balanceassertion + _ <- fixedlotprice many spacenonewline (inlinecomment, inlinetag) <- inlinecomment (nextlinecomments, nextlinetags) <- commentlines @@ -518,8 +519,8 @@ tests_posting = [ assertBool "posting parses a quoted commodity with numbers" (isRight $ parseWithCtx nullctx posting " a 1 \"DE123\"\n") - ,"posting parses a balance assertion" ~: do - assertBool "" (isRight $ parseWithCtx nullctx posting " a 1 \"DE123\" =$1\n") + ,"posting parses balance assertions and fixed lot prices" ~: do + assertBool "" (isRight $ parseWithCtx nullctx posting " a 1 \"DE123\" =$1 { =2.2 EUR} \n") ] -- | Parse an account name, then apply any parent account prefix and/or account aliases currently in effect. @@ -670,6 +671,21 @@ balanceassertion = return $ Just a) <|> return Nothing +-- http://ledger-cli.org/3.0/doc/ledger3.html#Fixing-Lot-Prices +fixedlotprice :: GenParser Char JournalContext (Maybe MixedAmount) +fixedlotprice = + try (do + many spacenonewline + char '{' + many spacenonewline + char '=' + many spacenonewline + a <- amount -- XXX should restrict to a simple amount + many spacenonewline + char '}' + return $ Just a) + <|> return Nothing + -- | Parse a numeric quantity for its value and display attributes. Some -- international number formats (cf -- http://en.wikipedia.org/wiki/Decimal_separator) are accepted: either