parsing: ignore ledger-style balance assertions ("= BAL" after a posting's amount)
This commit is contained in:
		
							parent
							
								
									e4e4681649
								
							
						
					
					
						commit
						28baf926f7
					
				| @ -488,6 +488,7 @@ posting = do | ||||
|   account <- modifiedaccountname | ||||
|   let (ptype, account') = (accountNamePostingType account, unbracket account) | ||||
|   amount <- spaceandamountormissing | ||||
|   _ <- balanceassertion | ||||
|   many spacenonewline | ||||
|   (inlinecomment, inlinetag) <- inlinecomment | ||||
|   (nextlinecomments, nextlinetags) <- commentlines | ||||
| @ -516,6 +517,9 @@ 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") | ||||
|  ] | ||||
| 
 | ||||
| -- | 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 | ||||
|  ] | ||||
| 
 | ||||
| -- | Parse an amount, with an optional left or right currency symbol and | ||||
| -- optional price. | ||||
| -- | Parse an amount, optionally with a left or right currency symbol, | ||||
| -- price, and/or (ignored) ledger-style balance assertion. | ||||
| amount :: GenParser Char JournalContext MixedAmount | ||||
| amount = try leftsymbolamount <|> try rightsymbolamount <|> nosymbolamount | ||||
| 
 | ||||
| @ -656,6 +660,16 @@ priceamount = | ||||
|             return $ Just $ UnitPrice a)) | ||||
|          <|> 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 | ||||
| -- international number formats (cf | ||||
| -- http://en.wikipedia.org/wiki/Decimal_separator) are accepted: either | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user