From f168124501692e5952cbec58ad9fa9590469c924 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 26 May 2010 23:44:08 +0000 Subject: [PATCH] parsing: allow - before commodity symbol as well (also fixes a convert bug) --- hledger-lib/Hledger/Data/Parse.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/hledger-lib/Hledger/Data/Parse.hs b/hledger-lib/Hledger/Data/Parse.hs index b982f1968..7a4c0e53c 100644 --- a/hledger-lib/Hledger/Data/Parse.hs +++ b/hledger-lib/Hledger/Data/Parse.hs @@ -518,12 +518,14 @@ someamount = try leftsymbolamount <|> try rightsymbolamount <|> nosymbolamount leftsymbolamount :: GenParser Char st MixedAmount leftsymbolamount = do + sign <- optionMaybe $ string "-" + let applysign = if isJust sign then negate else id sym <- commoditysymbol sp <- many spacenonewline (q,p,comma) <- amountquantity pri <- priceamount let c = Commodity {symbol=sym,side=L,spaced=not $ null sp,comma=comma,precision=p} - return $ Mixed [Amount c q pri] + return $ applysign $ Mixed [Amount c q pri] "left-symbol amount" rightsymbolamount :: GenParser Char st MixedAmount @@ -715,6 +717,14 @@ tests_Parse = TestList [ assertParseEqual (parseWithCtx emptyCtx postingamount " $1.") (Mixed [Amount Commodity {symbol="$",side=L,spaced=False,comma=False,precision=0} 1 Nothing]) + ,"leftsymbolamount" ~: do + assertParseEqual (parseWithCtx emptyCtx leftsymbolamount "$1") + (Mixed [Amount Commodity {symbol="$",side=L,spaced=False,comma=False,precision=0} 1 Nothing]) + assertParseEqual (parseWithCtx emptyCtx leftsymbolamount "$-1") + (Mixed [Amount Commodity {symbol="$",side=L,spaced=False,comma=False,precision=0} (-1) Nothing]) + assertParseEqual (parseWithCtx emptyCtx leftsymbolamount "-$1") + (Mixed [Amount Commodity {symbol="$",side=L,spaced=False,comma=False,precision=0} (-1) Nothing]) + ] entry1_str = unlines