From bf136fae5cb61e8329757dc7d2108e3248236dee Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 1 Oct 2008 11:43:18 +0000 Subject: [PATCH] drop the FilterPatterns type --- Ledger.hs | 6 +++--- Options.hs | 6 +++--- Types.hs | 3 --- hledger.hs | 8 ++++---- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Ledger.hs b/Ledger.hs index 6df10701c..0192f82ed 100644 --- a/Ledger.hs +++ b/Ledger.hs @@ -38,7 +38,7 @@ instance Show Ledger where -- 1. filter based on account/description patterns, if any -- 2. cache per-account info -- also, figure out the precision(s) to use -cacheLedger :: FilterPatterns -> LedgerFile -> Ledger +cacheLedger :: (Regex,Regex) -> LedgerFile -> Ledger cacheLedger pats l = let lprecision = maximum $ map (precision . amount) $ rawLedgerTransactions l @@ -66,7 +66,7 @@ cacheLedger pats l = -- | description patterns, if any, and which have at least one -- | transaction matching one of the account patterns, if any. -- | No description or account patterns implies match all. -filterLedgerEntries :: FilterPatterns -> LedgerFile -> LedgerFile +filterLedgerEntries :: (Regex,Regex) -> LedgerFile -> LedgerFile filterLedgerEntries (acctpat,descpat) (LedgerFile ms ps es f) = LedgerFile ms ps filteredentries f where @@ -84,7 +84,7 @@ filterLedgerEntries (acctpat,descpat) (LedgerFile ms ps es f) = -- | in each ledger entry, filter out transactions which do not match -- | the account patterns, if any. (Entries are no longer balanced -- | after this.) -filterLedgerTransactions :: FilterPatterns -> LedgerFile -> LedgerFile +filterLedgerTransactions :: (Regex,Regex) -> LedgerFile -> LedgerFile filterLedgerTransactions (acctpat,descpat) (LedgerFile ms ps es f) = LedgerFile ms ps (map filterentrytxns es) f where diff --git a/Options.hs b/Options.hs index 297053716..7dcf9ad3f 100644 --- a/Options.hs +++ b/Options.hs @@ -74,9 +74,9 @@ tildeExpand xs = return xs -- | ledger pattern arguments are: 0 or more account patterns -- | optionally followed by -- and 0 or more description patterns. --- | Here we convert the arguments, if any, to FilterPatterns, --- | which is a pair of maybe regexps. -parsePatternArgs :: [String] -> FilterPatterns +-- | No arguments implies match all. We convert the arguments to +-- | a pair of regexps. +parsePatternArgs :: [String] -> (Regex,Regex) parsePatternArgs args = (regexFor as, regexFor ds') where (as, ds) = break (=="--") args ds' = dropWhile (=="--") ds diff --git a/Types.hs b/Types.hs index 5662fb5ab..a3eff6bc8 100644 --- a/Types.hs +++ b/Types.hs @@ -6,9 +6,6 @@ where import Utils import qualified Data.Map as Map --- | account and description-matching patterns, see 'Options.parsePatternArgs'. -type FilterPatterns = (Regex, Regex) - type Date = String type DateTime = String diff --git a/hledger.hs b/hledger.hs index 6f0d249cb..a885f7201 100644 --- a/hledger.hs +++ b/hledger.hs @@ -65,16 +65,16 @@ main = do | cmd `isPrefixOf` "balance" = balance opts pats | otherwise = putStr usage -doWithFilteredLedger :: [Flag] -> FilterPatterns -> (Ledger -> IO ()) -> IO () +doWithFilteredLedger :: [Flag] -> (Regex,Regex) -> (Ledger -> IO ()) -> IO () doWithFilteredLedger opts pats cmd = do ledgerFilePath opts >>= parseLedgerFile >>= doWithParsed pats cmd -doWithParsed :: FilterPatterns -> (Ledger -> IO ()) -> (Either ParseError LedgerFile) -> IO () +doWithParsed :: (Regex,Regex) -> (Ledger -> IO ()) -> (Either ParseError LedgerFile) -> IO () doWithParsed pats cmd parsed = do case parsed of Left e -> parseError e Right l -> cmd $ cacheLedger pats l -type Command = [Flag] -> FilterPatterns -> IO () +type Command = [Flag] -> (Regex,Regex) -> IO () test :: Command test opts pats = do @@ -100,7 +100,7 @@ balance opts pats = do depth = case (pats, showsubs) of -- when there are no account patterns and no -s, -- show only to depth 1. (This was clearer and more - -- correct when FilterPatterns used maybe.) + -- correct when we used maybe.) ((wildcard,_), False) -> 1 otherwise -> 9999