allow spaces between sign and number, when parsing

This commit is contained in:
Simon Michael 2020-04-04 14:18:04 -07:00
parent 4529d9e804
commit f219bba494
2 changed files with 11 additions and 3 deletions

View File

@ -688,8 +688,10 @@ amountp' s =
mamountp' :: String -> MixedAmount
mamountp' = Mixed . (:[]) . amountp'
-- | Parse a minus or plus sign followed by zero or more spaces,
-- or nothing, returning a function that negates or does nothing.
signp :: Num a => TextParser m (a -> a)
signp = char '-' *> pure negate <|> char '+' *> pure id <|> pure id
signp = ((char '-' *> pure negate <|> char '+' *> pure id) <* many spacenonewline) <|> pure id
multiplierp :: TextParser m Bool
multiplierp = option False $ char '*' *> pure True

View File

@ -421,12 +421,18 @@ must be enclosed in double quotes:
3 "no. 42 green apples"
Amounts can be negative. The minus sign can be written before or after
a left-side commodity symbol:
Amounts can be preceded by a minus sign (or a plus sign, though plus is the default),
The sign can be written before or after a left-side commodity symbol:
-$1
$-1
One or more spaces between the sign and the number are acceptable
when parsing (but they won't be displayed in output):
+ $1
$- 1
Scientific E notation is allowed:
1E-6