lib: weaken parser types
This commit is contained in:
parent
4a9e418b7a
commit
2d21ec0174
@ -217,12 +217,12 @@ generateAutomaticPostings j = j { jtxns = map modifier $ jtxns j }
|
||||
|
||||
-- | Given a megaparsec ParsedJournal parser, input options, file
|
||||
-- path and file content: parse and post-process a Journal, or give an error.
|
||||
parseAndFinaliseJournal :: ErroringJournalParser IO ParsedJournal -> InputOpts
|
||||
parseAndFinaliseJournal :: JournalParser IO ParsedJournal -> InputOpts
|
||||
-> FilePath -> Text -> ExceptT String IO Journal
|
||||
parseAndFinaliseJournal parser iopts f txt = do
|
||||
t <- liftIO getClockTime
|
||||
y <- liftIO getCurrentYear
|
||||
ep <- runParserT (evalStateT parser nulljournal {jparsedefaultyear=Just y}) f txt
|
||||
ep <- liftIO $ runParserT (evalStateT parser nulljournal {jparsedefaultyear=Just y}) f txt
|
||||
case ep of
|
||||
Right pj ->
|
||||
let pj' = if auto_ iopts then generateAutomaticPostings pj else pj in
|
||||
|
||||
@ -139,7 +139,7 @@ aliasesFromOpts = map (\a -> fromparse $ runParser accountaliasp ("--alias "++qu
|
||||
-- >>> rejp (journalp <* eof) "2015/1/1\n a 0\n"
|
||||
-- Right Journal with 1 transactions, 1 accounts
|
||||
--
|
||||
journalp :: MonadIO m => ErroringJournalParser m ParsedJournal
|
||||
journalp :: MonadIO m => JournalParser m ParsedJournal
|
||||
journalp = do
|
||||
many addJournalItemP
|
||||
eof
|
||||
@ -147,7 +147,7 @@ journalp = do
|
||||
|
||||
-- | A side-effecting parser; parses any kind of journal item
|
||||
-- and updates the parse state accordingly.
|
||||
addJournalItemP :: MonadIO m => ErroringJournalParser m ()
|
||||
addJournalItemP :: MonadIO m => JournalParser m ()
|
||||
addJournalItemP =
|
||||
-- all journal line types can be distinguished by the first
|
||||
-- character, can use choice without backtracking
|
||||
@ -166,7 +166,7 @@ addJournalItemP =
|
||||
-- | Parse any journal directive and update the parse state accordingly.
|
||||
-- Cf http://hledger.org/manual.html#directives,
|
||||
-- http://ledger-cli.org/3.0/doc/ledger3.html#Command-Directives
|
||||
directivep :: MonadIO m => ErroringJournalParser m ()
|
||||
directivep :: MonadIO m => JournalParser m ()
|
||||
directivep = (do
|
||||
optional $ char '!'
|
||||
choice [
|
||||
@ -186,7 +186,7 @@ directivep = (do
|
||||
]
|
||||
) <?> "directive"
|
||||
|
||||
includedirectivep :: MonadIO m => ErroringJournalParser m ()
|
||||
includedirectivep :: MonadIO m => JournalParser m ()
|
||||
includedirectivep = do
|
||||
string "include"
|
||||
lift (skipSome spacenonewline)
|
||||
|
||||
@ -83,7 +83,7 @@ reader = Reader
|
||||
parse :: InputOpts -> FilePath -> Text -> ExceptT String IO Journal
|
||||
parse = parseAndFinaliseJournal timeclockfilep
|
||||
|
||||
timeclockfilep :: MonadIO m => ErroringJournalParser m ParsedJournal
|
||||
timeclockfilep :: MonadIO m => JournalParser m ParsedJournal
|
||||
timeclockfilep = do many timeclockitemp
|
||||
eof
|
||||
j@Journal{jparsetimeclockentries=es} <- get
|
||||
|
||||
Loading…
Reference in New Issue
Block a user