Safe Haskell | None |
---|
This is the entry point to hledger's reading system, which can read Journals from various data formats. Use this module if you want to parse journal data or read journal files. Generally it should not be necessary to import modules below this one.
- defaultJournalPath :: IO String
- defaultJournal :: IO Journal
- readJournal :: Maybe StorageFormat -> Maybe FilePath -> Maybe FilePath -> String -> IO (Either String Journal)
- readJournal' :: String -> IO Journal
- readJournalFile :: Maybe StorageFormat -> Maybe FilePath -> FilePath -> IO (Either String Journal)
- requireJournalFileExists :: FilePath -> IO ()
- ensureJournalFileExists :: FilePath -> IO ()
- postingp :: GenParser Char JournalContext Posting
- accountnamep :: GenParser Char st AccountName
- amountp :: GenParser Char JournalContext Amount
- amountp' :: String -> Amount
- mamountp' :: String -> MixedAmount
- numberp :: GenParser Char JournalContext (Quantity, Int, Char, Char, [Int])
- codep :: GenParser Char JournalContext String
- samplejournal :: IO Journal
- tests_Hledger_Read :: Test
Journal reading API
defaultJournalPath :: IO StringSource
All the data formats we can read. formats = map rFormat readers
Get the default journal file path specified by the environment.
Like ledger, we look first for the LEDGER_FILE environment
variable, and if that does not exist, for the legacy LEDGER
environment variable. If neither is set, or the value is blank,
return the hard-coded default, which is .hledger.journal
in the
users's home directory (or in the current directory, if we cannot
determine a home directory).
defaultJournal :: IO JournalSource
Read the default journal file specified by the environment, or raise an error.
readJournal :: Maybe StorageFormat -> Maybe FilePath -> Maybe FilePath -> String -> IO (Either String Journal)Source
Read a journal from this string, trying whatever readers seem appropriate:
- if a format is specified, try that reader only
- or if one or more readers recognises the file path and data, try those
- otherwise, try them all.
A CSV conversion rules file may also be specified for use by the CSV reader.
readJournal' :: String -> IO JournalSource
Read a journal from the given string, trying all known formats, or simply throw an error.
readJournalFile :: Maybe StorageFormat -> Maybe FilePath -> FilePath -> IO (Either String Journal)Source
Read a Journal from this file (or stdin if the filename is -) or give an error message, using the specified data format or trying all known formats. A CSV conversion rules file may be specified for better conversion of that format.
requireJournalFileExists :: FilePath -> IO ()Source
If the specified journal file does not exist, give a helpful error and quit.
ensureJournalFileExists :: FilePath -> IO ()Source
Ensure there is a journal file at the given path, creating an empty one if needed.
Parsers used elsewhere
accountnamep :: GenParser Char st AccountNameSource
Parse an account name. Account names may have single spaces inside them, and are terminated by two or more spaces. They should have one or more components of at least one character, separated by the account separator char.
amountp :: GenParser Char JournalContext AmountSource
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.
mamountp' :: String -> MixedAmountSource
Parse a mixed amount from a string, or get an error.
numberp :: GenParser Char JournalContext (Quantity, Int, Char, Char, [Int])Source
Parse a numeric quantity for its value and display attributes. Some international number formats (cf http:en.wikipedia.orgwikiDecimal_separator) are accepted: 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 (eg a thousands separator). This returns the numeric value, the precision (number of digits to the right of the decimal point), the decimal point and separator characters (defaulting to . and ,), and the positions of separators (counting leftward from the decimal point, the last is assumed to repeat).