hledger-lib-0.26: Core data types, parsers and utilities for the hledger accounting tool.

Safe HaskellNone




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



Parsers used elsewhere

parseJournalWith :: ParsecT [Char] JournalContext (ExceptT String IO) (JournalUpdate, JournalContext) -> Bool -> FilePath -> String -> ExceptT String IO Journal Source

Given a JournalUpdate-generating parsec parser, file path and data string, parse and post-process a Journal so that it's ready to use, or give an error.

journal :: ParsecT [Char] JournalContext (ExceptT String IO) (JournalUpdate, JournalContext) Source

Top-level journal parser. Returns a single composite, I/O performing, error-raising JournalUpdate (and final JournalContext) which can be applied to an empty journal to get the final result.

datetimep :: Stream [Char] m Char => ParsecT [Char] JournalContext 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).

accountnamep :: Stream [Char] m Char => ParsecT [Char] st m AccountName Source

Parse an account name. Account names start with a non-space, may have single spaces inside them, and are terminated by two or more spaces (or end of input). Also they have one or more components of at least one character, separated by the account separator char. (This parser will also consume one following space, if present.)

modifiedaccountname :: Stream [Char] m Char => ParsecT [Char] JournalContext m AccountName Source

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

amountp :: Stream [Char] m t => ParsecT [Char] JournalContext m Amount Source

Parse a single-commodity amount, with optional symbol on the left or right, optional unit or total price, and optional (ignored) ledger-style balance assertion or fixed lot price declaration.

amountp' :: String -> Amount Source

Parse an amount from a string, or get an error.

mamountp' :: String -> MixedAmount Source

Parse a mixed amount from a string, or get an error.

numberp :: Stream [Char] m t => ParsecT [Char] JournalContext m (Quantity, Int, Maybe Char, Maybe DigitGroupStyle) Source

Parse a string representation of a number for its value and display attributes.

Some international number formats are accepted, eg either period or comma may be used for the decimal point, and the other of these may be used for separating digit groups in the integer part. See http://en.wikipedia.org/wiki/Decimal_separator for more examples.

This returns: the parsed numeric value, the precision (number of digits seen following the decimal point), the decimal point character used if any, and the digit group style if any.