hledger-lib-1.2: Core data types, parsers and functionality for the hledger accounting tools

Safe Haskell | None
Language | Haskell2010

Hledger.Read.JournalReader

Contents

- Reader
- Parsing utils
- Parsers used elsewhere
- Tests

Description

A reader for hledger's journal file format (http://hledger.org/MANUAL.html#the-journal-file). hledger's journal format is a compatible subset of c++ ledger's (http://ledger-cli.org/3.0/doc/ledger3.html#Journal-Format), so this reader should handle many ledger files as well. Example:

    2012/3/24 gift
        expenses:gifts  $10
        assets:cash

Journal format supports the include directive which can read files in other formats, so the other file format readers need to be importable here. Some low-level journal syntax parsers which those readers also use are therefore defined separately in Hledger.Read.Common, avoiding import cycles.

Synopsis

- reader :: Reader
- genericSourcePos :: SourcePos -> GenericSourcePos
- parseAndFinaliseJournal :: ErroringJournalParser IO ParsedJournal -> Bool -> FilePath -> Text -> ExceptT String IO Journal
- runJournalParser :: Monad m => TextParser m a -> Text -> m (Either (ParseError Char Dec) a)
- rjp :: Monad m => TextParser m a -> Text -> m (Either (ParseError Char Dec) a)
- runErroringJournalParser :: Monad m => ErroringJournalParser m a -> Text -> m (Either String a)
- rejp :: Monad m => ErroringJournalParser m a -> Text -> m (Either String a)
- getParentAccount :: JournalStateParser m AccountName
- journalp :: MonadIO m => ErroringJournalParser m ParsedJournal
- directivep :: MonadIO m => ErroringJournalParser m ()
- defaultyeardirectivep :: JournalStateParser m ()
- marketpricedirectivep :: Monad m => JournalStateParser m MarketPrice
- datetimep :: JournalStateParser m LocalTime
- datep :: JournalStateParser m Day
- modifiedaccountnamep :: JournalStateParser m AccountName
- postingp :: MonadIO m => Maybe Day -> ErroringJournalParser m Posting
- statusp :: TextParser m ClearedStatus
- emptyorcommentlinep :: JournalStateParser m ()
- followingcommentp :: JournalStateParser m Text
- accountaliasp :: TextParser m AccountAlias
- tests_Hledger_Read_JournalReader :: Test

# Reader

reader :: Reader Source #

# Parsing utils

genericSourcePos :: SourcePos -> GenericSourcePos Source #

parseAndFinaliseJournal :: ErroringJournalParser IO ParsedJournal -> Bool -> FilePath -> Text -> ExceptT String IO Journal Source #

Given a megaparsec ParsedJournal parser, balance assertion flag, file path and file content: parse and post-process a Journal, or give an error.

runJournalParser :: Monad m => TextParser m a -> Text -> m (Either (ParseError Char Dec) a) Source #

Run a journal parser with a null journal-parsing state.

rjp :: Monad m => TextParser m a -> Text -> m (Either (ParseError Char Dec) a) Source #

Run a journal parser with a null journal-parsing state.

runErroringJournalParser :: Monad m => ErroringJournalParser m a -> Text -> m (Either String a) Source #

Run an error-raising journal parser with a null journal-parsing state.

rejp :: Monad m => ErroringJournalParser m a -> Text -> m (Either String a) Source #

Run an error-raising journal parser with a null journal-parsing state.

# Parsers used elsewhere

getParentAccount :: JournalStateParser m AccountName Source #

journalp :: MonadIO m => ErroringJournalParser m ParsedJournal Source #

A journal parser. Accumulates and returns a ParsedJournal, which should be finalised/validated before use.

    >>> rejp (journalp <* eof) "2015/1/1\n a  0\n"
    Right Journal  with 1 transactions, 1 accounts

directivep :: MonadIO m => ErroringJournalParser m () Source #

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

defaultyeardirectivep :: JournalStateParser m () Source #

marketpricedirectivep :: Monad m => JournalStateParser m MarketPrice Source #

datetimep :: JournalStateParser m LocalTime Source #

Parse a date and time in YYYYMMDD HH:MM[:SS][+-ZZZZ] format. Hyphen (-) and period (.) are also allowed as date separators. The year may be omitted if a default year has been set. Seconds are optional. The timezone is optional and ignored (the time is always interpreted as a local time). Leading zeroes may be omitted (except in a timezone).

datep :: JournalStateParser m Day Source #

Parse a date in YYYYMMDD format. Hyphen (-) and period (.) are also allowed as separators. The year may be omitted if a default year has been set. Leading zeroes may be omitted.

modifiedaccountnamep :: JournalStateParser m AccountName Source #

    > parsewith twoorthreepartdatestringp "2016/01/2"

Right "2016012" twoorthreepartdatestringp = do n1 <- some digitChar c <- datesepchar n2 <- some digitChar mn3 optional $ char c> some digitChar return $ n1 ++ c:n2 ++ maybe "" (c:) mn3

Parse an account name, then apply any parent account prefix and/or account aliases currently in effect.

postingp :: MonadIO m => Maybe Day -> ErroringJournalParser m Posting Source #

statusp :: TextParser m ClearedStatus Source #

emptyorcommentlinep :: JournalStateParser m () Source #

followingcommentp :: JournalStateParser m Text Source #

Parse a possibly multi-line comment following a semicolon.

accountaliasp :: TextParser m AccountAlias Source #

# Tests

tests_Hledger_Read_JournalReader :: Test Source #