diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 615fc52df..cfc3e2e6b 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -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 diff --git a/hledger-lib/hledger_journal.m4.md b/hledger-lib/hledger_journal.m4.md index 8f0fb143c..7ffaefe6a 100644 --- a/hledger-lib/hledger_journal.m4.md +++ b/hledger-lib/hledger_journal.m4.md @@ -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