lib: cleanups
This commit is contained in:
parent
0f5ee154c4
commit
097c9e09b6
@ -176,16 +176,6 @@ directivep = do
|
|||||||
]
|
]
|
||||||
<?> "directive"
|
<?> "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 :: ErroringJournalParser ()
|
||||||
includedirectivep = do
|
includedirectivep = do
|
||||||
string "include"
|
string "include"
|
||||||
@ -194,12 +184,12 @@ includedirectivep = do
|
|||||||
parentpos <- getPosition
|
parentpos <- getPosition
|
||||||
parentj <- getState
|
parentj <- getState
|
||||||
let childj = newJournalWithParseStateFrom parentj
|
let childj = newJournalWithParseStateFrom parentj
|
||||||
(ep :: Either String ParsedJournal) <-
|
(ej :: Either String ParsedJournal) <-
|
||||||
liftIO $ runExceptT $ do
|
liftIO $ runExceptT $ do
|
||||||
let curdir = takeDirectory (sourceName parentpos)
|
let curdir = takeDirectory (sourceName parentpos)
|
||||||
filepath <- expandPath curdir filename `orRethrowIOError` (show parentpos ++ " locating " ++ filename)
|
filepath <- expandPath curdir filename `orRethrowIOError` (show parentpos ++ " locating " ++ filename)
|
||||||
txt <- readFile' filepath `orRethrowIOError` (show parentpos ++ " reading " ++ filepath)
|
txt <- readFile' filepath `orRethrowIOError` (show parentpos ++ " reading " ++ filepath)
|
||||||
(ep1::Either ParseError ParsedJournal) <-
|
(ej1::Either ParseError ParsedJournal) <-
|
||||||
runParserT
|
runParserT
|
||||||
(choice' [journalp
|
(choice' [journalp
|
||||||
,timeclockfilep
|
,timeclockfilep
|
||||||
@ -212,12 +202,21 @@ includedirectivep = do
|
|||||||
. ((show parentpos ++ " in included file " ++ show filename ++ ":\n") ++)
|
. ((show parentpos ++ " in included file " ++ show filename ++ ":\n") ++)
|
||||||
. show)
|
. show)
|
||||||
(return . journalAddFile (filepath,txt))
|
(return . journalAddFile (filepath,txt))
|
||||||
ep1
|
ej1
|
||||||
case ep of
|
case ej of
|
||||||
Left e -> throwError e
|
Left e -> throwError e
|
||||||
Right jchild -> modifyState (\jparent ->
|
Right childj -> modifyState (\parentj -> childj <> parentj)
|
||||||
-- trace ("jparent txns: " ++ show (jtxns jparent)) $ trace ("jchild txns: "++ show (jtxns jchild)) $
|
-- discard child's parse info, prepend its (reversed) list data, combine other fields
|
||||||
jchild <> jparent)
|
|
||||||
|
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
|
-- | Lift an IO action into the exception monad, rethrowing any IO
|
||||||
-- error with the given message prepended.
|
-- error with the given message prepended.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user