parsing: allow - before commodity symbol as well (also fixes a convert bug)
This commit is contained in:
parent
b97d2690de
commit
f168124501
@ -518,12 +518,14 @@ someamount = try leftsymbolamount <|> try rightsymbolamount <|> nosymbolamount
|
|||||||
|
|
||||||
leftsymbolamount :: GenParser Char st MixedAmount
|
leftsymbolamount :: GenParser Char st MixedAmount
|
||||||
leftsymbolamount = do
|
leftsymbolamount = do
|
||||||
|
sign <- optionMaybe $ string "-"
|
||||||
|
let applysign = if isJust sign then negate else id
|
||||||
sym <- commoditysymbol
|
sym <- commoditysymbol
|
||||||
sp <- many spacenonewline
|
sp <- many spacenonewline
|
||||||
(q,p,comma) <- amountquantity
|
(q,p,comma) <- amountquantity
|
||||||
pri <- priceamount
|
pri <- priceamount
|
||||||
let c = Commodity {symbol=sym,side=L,spaced=not $ null sp,comma=comma,precision=p}
|
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"
|
<?> "left-symbol amount"
|
||||||
|
|
||||||
rightsymbolamount :: GenParser Char st MixedAmount
|
rightsymbolamount :: GenParser Char st MixedAmount
|
||||||
@ -715,6 +717,14 @@ tests_Parse = TestList [
|
|||||||
assertParseEqual (parseWithCtx emptyCtx postingamount " $1.")
|
assertParseEqual (parseWithCtx emptyCtx postingamount " $1.")
|
||||||
(Mixed [Amount Commodity {symbol="$",side=L,spaced=False,comma=False,precision=0} 1 Nothing])
|
(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
|
entry1_str = unlines
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user