From 097c9e09b626eef40e019868900b0ddc7970276c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 23 May 2016 01:02:19 -0700 Subject: [PATCH] lib: cleanups --- hledger-lib/Hledger/Read/JournalReader.hs | 33 +++++++++++------------ 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index 31f214d7d..4d6de1631 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -176,16 +176,6 @@ directivep = do ] "directive" -newJournalWithParseStateFrom :: Journal -> Journal -newJournalWithParseStateFrom j = mempty{ - jparsedefaultyear = jparsedefaultyear j - ,jparsedefaultcommodity = jparsedefaultcommodity j - ,jparseparentaccounts = jparseparentaccounts j - ,jparsealiases = jparsealiases j - ,jparsetransactioncount = jparsetransactioncount j - ,jparsetimeclockentries = jparsetimeclockentries j - } - includedirectivep :: ErroringJournalParser () includedirectivep = do string "include" @@ -194,12 +184,12 @@ includedirectivep = do parentpos <- getPosition parentj <- getState let childj = newJournalWithParseStateFrom parentj - (ep :: Either String ParsedJournal) <- + (ej :: Either String ParsedJournal) <- liftIO $ runExceptT $ do let curdir = takeDirectory (sourceName parentpos) filepath <- expandPath curdir filename `orRethrowIOError` (show parentpos ++ " locating " ++ filename) txt <- readFile' filepath `orRethrowIOError` (show parentpos ++ " reading " ++ filepath) - (ep1::Either ParseError ParsedJournal) <- + (ej1::Either ParseError ParsedJournal) <- runParserT (choice' [journalp ,timeclockfilep @@ -212,12 +202,21 @@ includedirectivep = do . ((show parentpos ++ " in included file " ++ show filename ++ ":\n") ++) . show) (return . journalAddFile (filepath,txt)) - ep1 - case ep of + ej1 + case ej of Left e -> throwError e - Right jchild -> modifyState (\jparent -> - -- trace ("jparent txns: " ++ show (jtxns jparent)) $ trace ("jchild txns: "++ show (jtxns jchild)) $ - jchild <> jparent) + Right childj -> modifyState (\parentj -> childj <> parentj) + -- discard child's parse info, prepend its (reversed) list data, combine other fields + +newJournalWithParseStateFrom :: Journal -> Journal +newJournalWithParseStateFrom j = mempty{ + jparsedefaultyear = jparsedefaultyear j + ,jparsedefaultcommodity = jparsedefaultcommodity j + ,jparseparentaccounts = jparseparentaccounts j + ,jparsealiases = jparsealiases j + ,jparsetransactioncount = jparsetransactioncount j + ,jparsetimeclockentries = jparsetimeclockentries j + } -- | Lift an IO action into the exception monad, rethrowing any IO -- error with the given message prepended.