From 07a4b21620ed230f0880e74d968b12422e01bfa2 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 18 Jun 2024 09:03:24 +0100 Subject: [PATCH] dev: refactor: move emptyorcommentlinep'; hlint --- hledger-lib/Hledger/Read/Common.hs | 21 ++++++++++++++++++++- hledger-lib/Hledger/Read/TimedotReader.hs | 19 ++----------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 24573311e..cc2c7ccbf 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -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 diff --git a/hledger-lib/Hledger/Read/TimedotReader.hs b/hledger-lib/Hledger/Read/TimedotReader.hs index 7c7bed673..5d0c6dce0 100644 --- a/hledger-lib/Hledger/Read/TimedotReader.hs +++ b/hledger-lib/Hledger/Read/TimedotReader.hs @@ -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 -