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

Safe Haskell | None
Language | Haskell2010

Hledger.Read.JournalReader

Contents

- Reader
- 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

Synopsis

- reader :: Reader
- parseJournalWith :: ParsecT [Char] JournalContext (ExceptT String IO) (JournalUpdate, JournalContext) -> Bool -> FilePath -> String -> ExceptT String IO Journal
- getParentAccount :: Stream [Char] m Char => ParsecT [Char] JournalContext m String
- journal :: ParsecT [Char] JournalContext (ExceptT String IO) (JournalUpdate, JournalContext)
- directive :: ParsecT [Char] JournalContext (ExceptT String IO) JournalUpdate
- defaultyeardirective :: ParsecT [Char] JournalContext (ExceptT String IO) JournalUpdate
- historicalpricedirective :: ParsecT [Char] JournalContext (ExceptT String IO) HistoricalPrice
- datetimep :: Stream [Char] m Char => ParsecT [Char] JournalContext m LocalTime
- codep :: Stream [Char] m Char => ParsecT [Char] JournalContext m String
- accountnamep :: Stream [Char] m Char => ParsecT [Char] st m AccountName
- modifiedaccountname :: Stream [Char] m Char => ParsecT [Char] JournalContext m AccountName
- postingp :: Stream [Char] m Char => ParsecT [Char] JournalContext m Posting
- amountp :: Stream [Char] m t => ParsecT [Char] JournalContext m Amount
- amountp' :: String -> Amount
- mamountp' :: String -> MixedAmount
- numberp :: Stream [Char] m t => ParsecT [Char] JournalContext m (Quantity, Int, Maybe Char, Maybe DigitGroupStyle)
- statusp :: Stream [Char] m Char => ParsecT [Char] JournalContext m ClearedStatus
- emptyorcommentlinep :: Stream [Char] m Char => ParsecT [Char] JournalContext m ()
- followingcommentp :: Stream [Char] m Char => ParsecT [Char] JournalContext m String
- accountaliasp :: Stream [Char] m Char => ParsecT [Char] st m AccountAlias
- tests_Hledger_Read_JournalReader :: Test

# Reader

reader :: Reader Source

# 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.

getParentAccount :: Stream [Char] m Char => ParsecT [Char] JournalContext m String Source

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.

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

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

historicalpricedirective :: ParsecT [Char] JournalContext (ExceptT String IO) HistoricalPrice Source

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).

codep :: Stream [Char] m Char => ParsecT [Char] JournalContext m String Source

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.

postingp :: Stream [Char] m Char => ParsecT [Char] JournalContext m Posting Source

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.

statusp :: Stream [Char] m Char => ParsecT [Char] JournalContext m ClearedStatus Source

emptyorcommentlinep :: Stream [Char] m Char => ParsecT [Char] JournalContext m () Source

followingcommentp :: Stream [Char] m Char => ParsecT [Char] JournalContext m String Source

accountaliasp :: Stream [Char] m Char => ParsecT [Char] st m AccountAlias Source

# Tests

tests_Hledger_Read_JournalReader :: Test Source