From 9674f2a8cc0fb01f8a6b31312b94486cafabe450 Mon Sep 17 00:00:00 2001 From: Alex Chen Date: Wed, 20 Jun 2018 19:52:49 -0600 Subject: [PATCH] lib: tweak whitespace parsing for better parse errors - expands the set of expected tokens when e.g. parsing the invalid posting `account $1 a` - whitespace can affect parse errors because of the longest match rule where errors that occur later take precedence over those that occur earlier --- hledger-lib/Hledger/Read/Common.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 8803b6ba9..d9676449f 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -523,6 +523,7 @@ test_spaceandamountormissingp = do amountp :: JournalParser m Amount amountp = label "amount" $ do amount <- amountwithoutpricep + lift $ skipMany spacenonewline price <- priceamountp pure $ amount { aprice = price } @@ -657,7 +658,7 @@ simplecommoditysymbolp = takeWhile1P Nothing (not . isNonsimpleCommodityChar) priceamountp :: JournalParser m Price priceamountp = option NoPrice $ do - try $ lift (skipMany spacenonewline) *> char '@' + char '@' priceConstructor <- char '@' *> pure TotalPrice <|> pure UnitPrice lift (skipMany spacenonewline)