lib: restrict backtracking when parsing postings (#747)

This commit is contained in:
Alex Chen 2018-05-09 22:40:33 -06:00 committed by Simon Michael
parent 129f6e6839
commit a409d09435

View File

@ -581,7 +581,7 @@ test_transactionp = do
-- Parse the following whitespace-beginning lines as postings, posting -- Parse the following whitespace-beginning lines as postings, posting
-- tags, and/or comments (inferring year, if needed, from the given date). -- tags, and/or comments (inferring year, if needed, from the given date).
postingsp :: MonadIO m => Maybe Day -> ErroringJournalParser m [Posting] postingsp :: MonadIO m => Maybe Day -> ErroringJournalParser m [Posting]
postingsp mdate = many (try $ postingp mdate) <?> "postings" postingsp mdate = many (postingp mdate) <?> "postings"
-- linebeginningwithspaces :: Monad m => JournalParser m String -- linebeginningwithspaces :: Monad m => JournalParser m String
-- linebeginningwithspaces = do -- linebeginningwithspaces = do
@ -593,10 +593,12 @@ postingsp mdate = many (try $ postingp mdate) <?> "postings"
postingp :: MonadIO m => Maybe Day -> ErroringJournalParser m Posting postingp :: MonadIO m => Maybe Day -> ErroringJournalParser m Posting
postingp mtdate = do postingp mtdate = do
-- pdbg 0 "postingp" -- pdbg 0 "postingp"
(status, account) <- try $ do
lift (skipSome spacenonewline) lift (skipSome spacenonewline)
status <- lift statusp status <- lift statusp
lift (skipMany spacenonewline) lift (skipMany spacenonewline)
account <- modifiedaccountnamep account <- modifiedaccountnamep
return (status, account)
let (ptype, account') = (accountNamePostingType account, textUnbracket account) let (ptype, account') = (accountNamePostingType account, textUnbracket account)
amount <- spaceandamountormissingp amount <- spaceandamountormissingp
massertion <- partialbalanceassertionp massertion <- partialbalanceassertionp