Permalink
Browse files

journal: support space as digits sep

  • Loading branch information...
ony committed Nov 2, 2017
1 parent 05bd421 commit bbc907e08e7efe2f70ce5cc10736fc92c98cba7a
Showing with 32 additions and 2 deletions.
  1. +6 −2 hledger-lib/Hledger/Read/Common.hs
  2. +26 −0 tests/journal/numbers.test
@@ -23,6 +23,7 @@ import Prelude.Compat hiding (readFile)
import Control.Monad.Compat
import Control.Monad.Except (ExceptT(..), runExceptT, throwError) --, catchError)
import Control.Monad.State.Strict
import Data.Char
import Data.Data
import Data.Default
import Data.Functor.Identity
@@ -565,7 +566,7 @@ rawnumberp = do
(firstSep, groups) <- option (Nothing, []) $ do
leadingDigits <- some digitChar
option (Nothing, [leadingDigits]) . try $ do
firstSep <- oneOf sepChars
firstSep <- oneOf sepChars <|> whitespaceChar
groups <- some digitChar `sepBy1` char firstSep
return (Just firstSep, leadingDigits : groups)
@@ -580,11 +581,14 @@ rawnumberp = do
return (lastSep, fromMaybe [] digits)
-- make sure we didn't leading part of mistyped number
notFollowedBy $ oneOf sepChars
notFollowedBy $ oneOf sepChars <|> (whitespaceChar >> digitChar)
return $ dbg8 "rawnumberp" (firstSep, groups, extraGroup)
<?> "rawnumberp"
-- | Parse a unicode char that represents any non-control space char (Zs general category).
whitespaceChar :: TextParser m Char
whitespaceChar = charCategory Space
-- test_numberp = do
-- let s `is` n = assertParseEqual (parseWithState mempty numberp s) n
@@ -43,6 +43,32 @@ hledger bal -f -
>>>
>>>=1
# Space between digits groups
hledger bal -f - --no-total
<<<
2017/1/1
a 1 000.00 EUR
b -1 000.00 EUR
>>>
1 000.00 EUR a
-1 000.00 EUR b
>>>2
>>>=0
# Space between digits groups in commodity directive
hledger bal -f - --no-total
<<<
commodity 1 000.00 EUR
2017/1/1
a 1,000.00 EUR
b -1,000.00 EUR
>>>
1 000.00 EUR a
-1 000.00 EUR b
>>>2
>>>=0
# Omitted decimals
hledger bal -f -
<<<

0 comments on commit bbc907e

Please sign in to comment.