From 46aae19a546cbdf7f318d6dd409fd7dd52743249 Mon Sep 17 00:00:00 2001 From: awjchen Date: Sun, 20 May 2018 16:02:59 -0600 Subject: [PATCH] lib: fix parsing of amounts with a whitespace digits separator --- hledger-lib/Hledger/Read/Common.hs | 5 +++-- tests/journal/amounts-and-commodities.test | 24 +++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 83eda4c3d..998bbf016 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -763,8 +763,9 @@ rawnumberp = do leadingDigits <- some digitChar option (Nothing, [leadingDigits]) . try $ do firstSep <- oneOf sepChars <|> whitespaceChar - groups <- some digitChar `sepBy1` char firstSep - return (Just firstSep, leadingDigits : groups) + secondGroup <- some digitChar + otherGroups <- many $ try $ char firstSep *> some digitChar + return (Just firstSep, leadingDigits : secondGroup : otherGroups) let remSepChars = maybe sepChars (`delete` sepChars) firstSep modifier diff --git a/tests/journal/amounts-and-commodities.test b/tests/journal/amounts-and-commodities.test index 26ac091e0..1a6d28897 100644 --- a/tests/journal/amounts-and-commodities.test +++ b/tests/journal/amounts-and-commodities.test @@ -136,17 +136,17 @@ $ hledger -f- bal -V -N #>=1 # 11. After a space-grouped amount, a posting comment should parse. -#< -#2018-01-01 -# (a) USD 1 000 ;comment -# -#$ hledger -f- print -#> // # any stdout, no stderr, 0 exit code +< +2018-01-01 + (a) USD 1 000 ;comment + +$ hledger -f- print +> // # any stdout, no stderr, 0 exit code # 12. After a space-grouped amount, trailing whitespace should parse. -#< -#2018-01-01 -# (a) USD 1 000 -# -#$ hledger -f- print -#> // # any stdout, no stderr, 0 exit code +< +2018-01-01 + (a) USD 1 000 + +$ hledger -f- print +> // # any stdout, no stderr, 0 exit code