parsing: ignore ledger-style balance assertions ("= BAL" after a posting's amount)

This commit is contained in:
Simon Michael 2012-11-02 16:50:36 +00:00
parent e4e4681649
commit 28baf926f7

View File

@ -488,6 +488,7 @@ posting = do
account <- modifiedaccountname account <- modifiedaccountname
let (ptype, account') = (accountNamePostingType account, unbracket account) let (ptype, account') = (accountNamePostingType account, unbracket account)
amount <- spaceandamountormissing amount <- spaceandamountormissing
_ <- balanceassertion
many spacenonewline many spacenonewline
(inlinecomment, inlinetag) <- inlinecomment (inlinecomment, inlinetag) <- inlinecomment
(nextlinecomments, nextlinetags) <- commentlines (nextlinecomments, nextlinetags) <- commentlines
@ -516,6 +517,9 @@ tests_posting = [
assertBool "posting parses a quoted commodity with numbers" assertBool "posting parses a quoted commodity with numbers"
(isRight $ parseWithCtx nullctx posting " a 1 \"DE123\"\n") (isRight $ parseWithCtx nullctx posting " a 1 \"DE123\"\n")
,"posting parses a balance assertion" ~: do
assertBool "" (isRight $ parseWithCtx nullctx posting " a 1 \"DE123\" =$1\n")
] ]
-- | Parse an account name, then apply any parent account prefix and/or account aliases currently in effect. -- | Parse an account name, then apply any parent account prefix and/or account aliases currently in effect.
@ -564,8 +568,8 @@ tests_spaceandamountormissing = [
assertParseEqual (parseWithCtx nullctx spaceandamountormissing "") missingmixedamt assertParseEqual (parseWithCtx nullctx spaceandamountormissing "") missingmixedamt
] ]
-- | Parse an amount, with an optional left or right currency symbol and -- | Parse an amount, optionally with a left or right currency symbol,
-- optional price. -- price, and/or (ignored) ledger-style balance assertion.
amount :: GenParser Char JournalContext MixedAmount amount :: GenParser Char JournalContext MixedAmount
amount = try leftsymbolamount <|> try rightsymbolamount <|> nosymbolamount amount = try leftsymbolamount <|> try rightsymbolamount <|> nosymbolamount
@ -656,6 +660,16 @@ priceamount =
return $ Just $ UnitPrice a)) return $ Just $ UnitPrice a))
<|> return Nothing <|> return Nothing
balanceassertion :: GenParser Char JournalContext (Maybe MixedAmount)
balanceassertion =
try (do
many spacenonewline
char '='
many spacenonewline
a <- amount -- XXX should restrict to a simple amount
return $ Just a)
<|> return Nothing
-- | Parse a numeric quantity for its value and display attributes. Some -- | Parse a numeric quantity for its value and display attributes. Some
-- international number formats (cf -- international number formats (cf
-- http://en.wikipedia.org/wiki/Decimal_separator) are accepted: either -- http://en.wikipedia.org/wiki/Decimal_separator) are accepted: either