| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Hledger.Read.RulesReader
Contents
Description
A reader for a CSV rules file.
This reads the actual data from a file specified by a source rule
or from a similarly-named file in the same directory.
Most of the code for reading rules files and csv files is in this module.
Synopsis
- reader :: forall (m :: Type -> Type). MonadIO m => Reader m
- dataFileFor :: FilePath -> Maybe FilePath
- rulesFileFor :: FilePath -> FilePath
- getRulesFile :: FilePath -> Maybe FilePath -> FilePath
- readRules :: FilePath -> ExceptT String IO (CsvRules, [FilePath])
- rulesEncoding :: FilePath -> CsvRules -> ExceptT String IO (Maybe DynEncoding)
- readJournalFromCsv :: FilePath -> CsvRules -> FilePath -> Text -> Maybe SepFormat -> ExceptT String IO (Journal, String -> String)
- readParsedJournalFromCsv :: FilePath -> CsvRules -> (FilePath, [FilePath]) -> FilePath -> Text -> Maybe SepFormat -> ExceptT String IO (ParsedJournal, String -> String)
- parseBalanceAssertionType :: String -> Maybe (Bool, Bool)
- tests_RulesReader :: TestTree
Reader
Misc.
dataFileFor :: FilePath -> Maybe FilePath Source #
Given a rules file path, what would be the corresponding data file ? (Remove a .rules extension.)
rulesFileFor :: FilePath -> FilePath Source #
Given a csv file path, what would be the corresponding rules file ? (Add a .rules extension.)
getRulesFile :: FilePath -> Maybe FilePath -> FilePath Source #
Return the given rules file path, or if none is given, the default rules file for the given csv file; or if the csv file is "-", raise an error.
readRules :: FilePath -> ExceptT String IO (CsvRules, [FilePath]) Source #
An exception-throwing IO action that reads and validates the specified CSV rules file (which may include other rules files). Also returns the paths of all the rules files read, so that changes to any of them can be detected later (see jauxfiles).
rulesEncoding :: FilePath -> CsvRules -> ExceptT String IO (Maybe DynEncoding) Source #
Read the encoding specified by the encoding rule, if any.
Or throw an error if an unrecognised encoding is specified.
readJournalFromCsv :: FilePath -> CsvRules -> FilePath -> Text -> Maybe SepFormat -> ExceptT String IO (Journal, String -> String) Source #
Read a Journal from the given CSV data (and filename, used for error messages), or return an error. Proceed as follows:
- Conversion rules are provided, or they are parsed from the specified rules file, or from the default rules file for the CSV data file. If rules parsing fails, or the required rules file does not exist, throw an error.
- Parse the CSV data using the rules, or throw an error.
- Convert the CSV records to hledger transactions using the rules.
- Return the transactions as a Journal, along with an error context adder: a function which, given a later error message (eg from journal finalisation) mentioning a position in this CSV file, appends the corresponding CSV record's field values to it.
readParsedJournalFromCsv :: FilePath -> CsvRules -> (FilePath, [FilePath]) -> FilePath -> Text -> Maybe SepFormat -> ExceptT String IO (ParsedJournal, String -> String) Source #
Like readJournalFromCsv, but returns an unfinalised journal ready for journalFinalise:
its lists are reversed, as that expects (readJournalFromCsv produces them in normal order,
unlike JournalReader's parser; XXX inefficient), and the given data file and its auxiliary files
(rules files, and for a rules file, the data file it read, if any) are noted in jauxfiles,
so that the files command can show them and changes to them can be detected when reloading.
parseBalanceAssertionType :: String -> Maybe (Bool, Bool) Source #
Detect from a balance assertion's syntax (=, ==, =*, ==*) whether it is (a) total (multi-commodity) and (b) subaccount-inclusive. Returns nothing if invalid syntax was provided.