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 Format -> Maybe FilePath -> Maybe FilePath -> String -> IO (Either String Journal)
- readJournal' :: String -> IO Journal
- readJournalFile :: Maybe Format -> Maybe FilePath -> FilePath -> IO (Either String Journal)
- requireJournalFileExists :: FilePath -> IO ()
- ensureJournalFileExists :: FilePath -> IO ()
- accountname :: GenParser Char st AccountName
- amount :: GenParser Char JournalContext MixedAmount
- amount' :: String -> MixedAmount
- 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 Format -> 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 Format -> 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
accountname :: 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.
amount :: GenParser Char JournalContext MixedAmountSource
Parse an amount, optionally with a left or right currency symbol, price, and/or (ignored) ledger-style balance assertion.
amount' :: String -> MixedAmountSource
Run the amount parser on a string to get the result or an error.