drop the FilterPatterns type

This commit is contained in:
Simon Michael 2008-10-01 11:43:18 +00:00
parent a4039de739
commit bf136fae5c
4 changed files with 10 additions and 13 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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