lib: add a field to 'Journal' for a stack of include files
- In anticipation of megaparsec 7, which removes support for stacks of
include files (as far as I can tell)
- Intended for the 'StateT Journal' layer of the parser
- A stack of include files would be better in a 'ReaderT' layer, but I
don't want to add another layer to the parser
- Intended for detecting cycles of include files
- Potential issue: for proper error messages for include file cycles,
we must remember to provide the filepath of the root journal file via
the initial journal state passed to a 'JournalParser'; I imagine
that we may forget to do so because in all other cases it is okay
not to do so.
This commit is contained in:
parent
743098034b
commit
5e1f0ba6f7
@ -163,6 +163,7 @@ instance Sem.Semigroup Journal where
|
|||||||
,jparsealiases = jparsealiases j2
|
,jparsealiases = jparsealiases j2
|
||||||
-- ,jparsetransactioncount = jparsetransactioncount j1 + jparsetransactioncount j2
|
-- ,jparsetransactioncount = jparsetransactioncount j1 + jparsetransactioncount j2
|
||||||
,jparsetimeclockentries = jparsetimeclockentries j1 <> jparsetimeclockentries j2
|
,jparsetimeclockentries = jparsetimeclockentries j1 <> jparsetimeclockentries j2
|
||||||
|
,jincludefilestack = jincludefilestack j2
|
||||||
,jdeclaredaccounts = jdeclaredaccounts j1 <> jdeclaredaccounts j2
|
,jdeclaredaccounts = jdeclaredaccounts j1 <> jdeclaredaccounts j2
|
||||||
,jcommodities = jcommodities j1 <> jcommodities j2
|
,jcommodities = jcommodities j1 <> jcommodities j2
|
||||||
,jinferredcommodities = jinferredcommodities j1 <> jinferredcommodities j2
|
,jinferredcommodities = jinferredcommodities j1 <> jinferredcommodities j2
|
||||||
@ -189,8 +190,9 @@ nulljournal = Journal {
|
|||||||
,jparseparentaccounts = []
|
,jparseparentaccounts = []
|
||||||
,jparsealiases = []
|
,jparsealiases = []
|
||||||
-- ,jparsetransactioncount = 0
|
-- ,jparsetransactioncount = 0
|
||||||
,jparsetimeclockentries = []
|
,jparsetimeclockentries = []
|
||||||
,jdeclaredaccounts = []
|
,jincludefilestack = []
|
||||||
|
,jdeclaredaccounts = []
|
||||||
,jcommodities = M.fromList []
|
,jcommodities = M.fromList []
|
||||||
,jinferredcommodities = M.fromList []
|
,jinferredcommodities = M.fromList []
|
||||||
,jmarketprices = []
|
,jmarketprices = []
|
||||||
|
|||||||
@ -363,6 +363,7 @@ data Journal = Journal {
|
|||||||
,jparsealiases :: [AccountAlias] -- ^ the current account name aliases in effect, specified by alias directives (& options ?)
|
,jparsealiases :: [AccountAlias] -- ^ the current account name aliases in effect, specified by alias directives (& options ?)
|
||||||
-- ,jparsetransactioncount :: Integer -- ^ the current count of transactions parsed so far (only journal format txns, currently)
|
-- ,jparsetransactioncount :: Integer -- ^ the current count of transactions parsed so far (only journal format txns, currently)
|
||||||
,jparsetimeclockentries :: [TimeclockEntry] -- ^ timeclock sessions which have not been clocked out
|
,jparsetimeclockentries :: [TimeclockEntry] -- ^ timeclock sessions which have not been clocked out
|
||||||
|
,jincludefilestack :: [FilePath]
|
||||||
-- principal data
|
-- principal data
|
||||||
,jdeclaredaccounts :: [AccountName] -- ^ Accounts declared by account directives, in parse order (after journal finalisation)
|
,jdeclaredaccounts :: [AccountName] -- ^ Accounts declared by account directives, in parse order (after journal finalisation)
|
||||||
,jcommodities :: M.Map CommoditySymbol Commodity -- ^ commodities and formats declared by commodity directives
|
,jcommodities :: M.Map CommoditySymbol Commodity -- ^ commodities and formats declared by commodity directives
|
||||||
|
|||||||
@ -226,7 +226,10 @@ parseAndFinaliseJournal :: JournalParser IO ParsedJournal -> InputOpts
|
|||||||
parseAndFinaliseJournal parser iopts f txt = do
|
parseAndFinaliseJournal parser iopts f txt = do
|
||||||
t <- liftIO getClockTime
|
t <- liftIO getClockTime
|
||||||
y <- liftIO getCurrentYear
|
y <- liftIO getCurrentYear
|
||||||
ep <- liftIO $ runParserT (evalStateT parser nulljournal {jparsedefaultyear=Just y}) f txt
|
let initJournal = nulljournal
|
||||||
|
{ jparsedefaultyear = Just y
|
||||||
|
, jincludefilestack = [f] }
|
||||||
|
ep <- liftIO $ runParserT (evalStateT parser initJournal) f txt
|
||||||
case ep of
|
case ep of
|
||||||
Right pj ->
|
Right pj ->
|
||||||
let pj' = if auto_ iopts then applyTransactionModifiers pj else pj in
|
let pj' = if auto_ iopts then applyTransactionModifiers pj else pj in
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user