dev: refactor: move emptyorcommentlinep'; hlint

This commit is contained in:
Simon Michael 2024-06-18 09:03:24 +01:00
parent 46cda5e7de
commit 07a4b21620
2 changed files with 22 additions and 18 deletions

View File

@ -96,6 +96,7 @@ module Hledger.Read.Common (
isSameLineCommentStart,
multilinecommentp,
emptyorcommentlinep,
emptyorcommentlinep',
followingcommentp,
transactioncommentp,
commenttagsp,
@ -361,7 +362,7 @@ journalFinalise iopts@InputOpts{auto_,balancingopts_,infer_costs_,infer_equity_,
-- >>= Right . dbg0With (concatMap (T.unpack.showTransaction).jtxns)
-- >>= \j -> deepseq (concatMap (T.unpack.showTransaction).jtxns $ j) (return j)
<&> dbg9With (lbl "amounts after styling, forecasting, auto-posting".showJournalAmountsDebug)
>>= (\j -> if checkordereddates then journalCheckOrdereddates j <&> const j else Right j) -- check ordereddates before assertions. The outer parentheses are needed.
>>= (\j -> if checkordereddates then journalCheckOrdereddates j $> j else Right j) -- check ordereddates before assertions. The outer parentheses are needed.
>>= journalBalanceTransactions balancingopts_{ignore_assertions_=not checkassertions} -- infer balance assignments and missing amounts, and maybe check balance assertions.
<&> dbg9With (lbl "amounts after transaction-balancing".showJournalAmountsDebug)
-- <&> dbg9With (("journalFinalise amounts after styling, forecasting, auto postings, transaction balancing"<>).showJournalAmountsDebug)
@ -1277,6 +1278,24 @@ emptyorcommentlinep = do
{-# INLINABLE emptyorcommentlinep #-}
-- | A new comment line parser (from TimedotReader).
-- Parse empty lines, all-blank lines, and lines beginning with any of
-- the provided comment-beginning characters.
emptyorcommentlinep' :: [Char] -> TextParser m ()
emptyorcommentlinep' cs =
label ("empty line or comment line beginning with "++cs) $ do
-- traceparse "emptyorcommentlinep" -- XXX possible to combine label and traceparse ?
skipNonNewlineSpaces
void newline <|> void commentp
-- traceparse' "emptyorcommentlinep"
where
commentp = do
choice (map (some.char) cs)
void $ takeWhileP Nothing (/='\n')
void $ optional newline
{-# INLINABLE emptyorcommentlinep' #-}
-- | Is this a character that, as the first non-whitespace on a line,
-- starts a comment line ?
isLineCommentStart :: Char -> Bool

View File

@ -114,7 +114,7 @@ timedotp = preamblep >> many dayp >> eof >> get
preamblep :: JournalParser m ()
preamblep = do
lift $ traceparse "preamblep"
many $ notFollowedBy datelinep >> (lift $ emptyorcommentlinep "#;*")
many $ notFollowedBy datelinep >> (lift $ emptyorcommentlinep' "#;*")
lift $ traceparse' "preamblep"
-- | Parse timedot day entries to multi-posting time transactions for that day.
@ -157,7 +157,7 @@ datelinep = do
commentlinesp :: JournalParser m ()
commentlinesp = do
lift $ traceparse "commentlinesp"
void $ many $ try $ lift $ emptyorcommentlinep "#;"
void $ many $ try $ lift $ emptyorcommentlinep' "#;"
-- orgnondatelinep :: JournalParser m ()
-- orgnondatelinep = do
@ -277,18 +277,3 @@ letterquantitiesp =
]
return groups
-- | XXX new comment line parser, move to Hledger.Read.Common.emptyorcommentlinep
-- Parse empty lines, all-blank lines, and lines beginning with any of the provided
-- comment-beginning characters.
emptyorcommentlinep :: [Char] -> TextParser m ()
emptyorcommentlinep cs =
label ("empty line or comment line beginning with "++cs) $ do
traceparse "emptyorcommentlinep" -- XXX possible to combine label and traceparse ?
skipNonNewlineSpaces
void newline <|> void commentp
traceparse' "emptyorcommentlinep"
where
commentp = do
choice (map (some.char) cs)
takeWhileP Nothing (/='\n') <* newline