70: ignore ledger's fixed lot price declarations

This commit is contained in:
Simon Michael 2012-11-17 02:40:27 +00:00
parent 28baf926f7
commit 1c1058be4e
3 changed files with 30 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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