HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Modulehledger-lib-1.52.4GHC2021

Hledger.Read.JournalReader

A reader for hledger's journal file format (http://hledger.org/hledger.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 and invocable here.

Some important parts of journal parsing are therefore kept in Hledger.Read.Common, to avoid import cycles.

  • 22 values
  • Packagehledger-lib-1.52.4
  • Exports22
  • LanguageGHC2021
  • LicenceGPL-3.0-or-later
  • SourceJournalReader.hs

Reader-finding utils

2 declarations
findReader mformat mpath

Find the reader named by mformat, if provided. ("ssv" and "tsv" are recognised as alternate names for the csv reader, which also handles those formats.) Or, if a file path is provided, find the first reader that handles its file extension, if any.

Reader

1 declaration

Parsing utils

5 declarations

Parsers used elsewhere

13 declarations

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

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

Parse a date and time in YYYY-MM-DD HH:MM[:SS][+-ZZZZ] format. Slash (/) 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).

valuedatep :: JournalParser m Day
#

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

Parse an account name plus one following space if present (see accountnamep); then apply any parent account prefix and/or account aliases currently in effect, in that order. Ie first add the parent account prefix, then rewrite with aliases. This calls error if any account alias with an invalid regular expression exists. The flag says whether account names may include semicolons; currently account names in journal format may, but account names in timeclock/timedot formats may not.

A blank or comment line in journal format: a line that's empty or containing only whitespace or whose first non-whitespace character is semicolon, hash, or star. See also emptyorcommentlinep2.

Parse a comment following a journal item, possibly continued on multiple lines, and return the comment text.

Example5 expressions
rtp followingcommentp ""   -- no commentRight ""rtp followingcommentp ";"    -- just a (empty) same-line comment. newline is addedRight "\n"rtp followingcommentp ";  \n"Right "\n"rtp followingcommentp ";\n ;\n"  -- a same-line and a next-line commentRight "\n\n"rtp followingcommentp "\n ;\n"  -- just a next-line comment. Insert an empty same-line comment so the next-line comment doesn't become a same-line comment.Right "\n\n"

Tests

1 declaration