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