From 17b11aaf1e3525e123e2b8a62188d644e4be3dde Mon Sep 17 00:00:00 2001 From: Alex Chen Date: Sat, 12 May 2018 14:59:53 -0600 Subject: [PATCH] lib: refactor parsing of bracketed posting dates --- hledger-lib/Hledger/Read/Common.hs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index fe1cf19ec..1c6bd9e4a 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -872,7 +872,7 @@ followingcommentandtagsp mdefdate = do -- Reparse the comment for any bracketed style posting dates. -- Use the transaction date for defaults, if provided. eBracketedDates <- fmap sequence - $ traverse (runErroringJournalParserAt (postingdatesp mdefdate)) + $ traverse (runErroringJournalParserAt (bracketedpostingdatesp mdefdate)) commentLines bracketedDates <- case eBracketedDates of Right dss -> pure $ concat dss @@ -1002,19 +1002,18 @@ tagswithvaluepositions = do --- ** posting dates --- | Parse all posting dates found in a string. Posting dates can be --- expressed with date/date2 tags and/or bracketed dates. The dates --- are parsed fully to give useful errors. Missing years can be --- inferred only if a default date is provided. +-- | Parse all bracketed posting dates found in a string. The dates are +-- parsed fully to give useful errors. Missing years can be inferred only +-- if a default date is provided. -- -postingdatesp :: Monad m => Maybe Day -> ErroringJournalParser m [(TagName,Day)] -postingdatesp mdefdate = do - -- pdbg 0 $ "postingdatesp" - let p = bracketeddatetagsp mdefdate - nonp = - many (notFollowedBy p >> anyChar) - -- anyChar `manyTill` (lookAhead (try (p >> return ()) <|> eof)) - concat <$> many (try (nonp >> p)) +bracketedpostingdatesp + :: Monad m => Maybe Day -> ErroringJournalParser m [(TagName,Day)] +bracketedpostingdatesp mdefdate = do + -- pdbg 0 $ "bracketedpostingdatesp" + skipMany $ notChar '[' + fmap concat + $ sepEndBy (try (bracketeddatetagsp mdefdate) <|> char '[' *> pure []) + (skipMany $ notChar '[') --- ** bracketed dates