From 7291977e6f6f290913f4470193d4d6eeee0a5288 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 2 Mar 2014 13:37:10 -0800 Subject: [PATCH] rename Format to StorageFormat --- hledger-lib/Hledger/Data/Types.hs | 4 ++-- hledger-lib/Hledger/Read.hs | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hledger-lib/Hledger/Data/Types.hs b/hledger-lib/Hledger/Data/Types.hs index a9bc53feb..fc75862c8 100644 --- a/hledger-lib/Hledger/Data/Types.hs +++ b/hledger-lib/Hledger/Data/Types.hs @@ -169,13 +169,13 @@ data Journal = Journal { type JournalUpdate = ErrorT String IO (Journal -> Journal) -- | The id of a data format understood by hledger, eg @journal@ or @csv@. -type Format = String +type StorageFormat = String -- | A hledger journal reader is a triple of format name, format-detecting -- predicate, and a parser to Journal. data Reader = Reader { -- name of the format this reader handles - rFormat :: Format + rFormat :: StorageFormat -- quickly check if this reader can probably handle the given file path and file content ,rDetector :: FilePath -> String -> Bool -- parse the given string, using the given parse rules file if any, returning a journal or error aware of the given file path diff --git a/hledger-lib/Hledger/Read.hs b/hledger-lib/Hledger/Read.hs index e76b6f2c4..bc1a9a5cf 100644 --- a/hledger-lib/Hledger/Read.hs +++ b/hledger-lib/Hledger/Read.hs @@ -114,7 +114,7 @@ tests_readJournal' = [ -- - otherwise, try them all. -- -- A CSV conversion rules file may also be specified for use by the CSV reader. -readJournal :: Maybe Format -> Maybe FilePath -> Maybe FilePath -> String -> IO (Either String Journal) +readJournal :: Maybe StorageFormat -> Maybe FilePath -> Maybe FilePath -> String -> IO (Either String Journal) readJournal format rulesfile path s = -- trace (show (format, rulesfile, path)) $ tryReaders $ readersFor (format, path, s) @@ -134,19 +134,19 @@ readJournal format rulesfile path s = path' = fromMaybe "(string)" path -- | Which readers are worth trying for this (possibly unspecified) format, filepath, and data ? -readersFor :: (Maybe Format, Maybe FilePath, String) -> [Reader] +readersFor :: (Maybe StorageFormat, Maybe FilePath, String) -> [Reader] readersFor (format,path,s) = case format of - Just f -> case readerForFormat f of Just r -> [r] - Nothing -> [] + Just f -> case readerForStorageFormat f of Just r -> [r] + Nothing -> [] Nothing -> case path of Nothing -> readers Just "-" -> readers Just p -> case readersForPathAndData (p,s) of [] -> readers rs -> rs -- | Find the (first) reader which can handle the given format, if any. -readerForFormat :: Format -> Maybe Reader -readerForFormat s | null rs = Nothing +readerForStorageFormat :: StorageFormat -> Maybe Reader +readerForStorageFormat s | null rs = Nothing | otherwise = Just $ head rs where rs = filter ((s==).rFormat) readers :: [Reader] @@ -159,7 +159,7 @@ readersForPathAndData (f,s) = filter (\r -> (rDetector r) f s) readers -- 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. -readJournalFile :: Maybe Format -> Maybe FilePath -> FilePath -> IO (Either String Journal) +readJournalFile :: Maybe StorageFormat -> Maybe FilePath -> FilePath -> IO (Either String Journal) readJournalFile format rulesfile "-" = do hSetNewlineMode stdin universalNewlineMode getContents >>= readJournal format rulesfile (Just "(stdin)")