import Prelude hiding (filter)
-- import Control.Applicative ((<$>), (<*))
import Control.Exception (assert)
-import Control.Monad (liftM, join, when)
+import Control.Monad (liftM, join, when, (>=>), void)
-- import Control.Monad.Trans.Except (ExceptT(..), throwE)
import qualified Data.Char
import Data.Data
=> ParsecT s u m (String -> r Filter_Text)
filter_text =
R.choice_try
- [ R.char '~' >> return (\s -> Regex.of_StringM s >>= (return . Filter_Text_Regex))
+ [ R.char '~' >> return (Regex.of_StringM >=> (return . Filter_Text_Regex))
, R.char '=' >> return (\s -> return (Filter_Text_Exact $ Text.pack s))
, return (\s -> return (Filter_Text_Exact $ Text.pack s))
]
=> ParsecT s u m (o -> Filter_Ord o)
filter_ord =
R.choice_try
- [ R.string "=" >> return Filter_Ord_Eq
- , R.string "<=" >> return Filter_Ord_Le
- , R.string ">=" >> return Filter_Ord_Ge
- , R.string "<" >> return Filter_Ord_Lt
- , R.string ">" >> return Filter_Ord_Gt
+ [ R.string "=" >> return (Filter_Ord Eq)
+ , R.string "<=" >> return (Filter_Ord Le) -- NOTE: before "<"
+ , R.string ">=" >> return (Filter_Ord Ge) -- NOTE: before ">"
+ , R.string "<" >> return (Filter_Ord Lt)
+ , R.string ">" >> return (Filter_Ord Gt)
]
filter_ord_operator
where
borders = R.between (R.char '(') (R.char ')')
inside = liftM concat $ R.many (R.choice_try [borders preserve_inside, R.many1 $ R.noneOf "()"])
- preserve_inside = inside >>= (\x -> return $ '(':(x++')':[]))
+ preserve_inside = inside >>= (\x -> return $ '(':(x++[')']))
-- ** Read 'Filter_Bool'
]
]
where
- binary name fun assoc = R.Infix (filter_bool_operator name >> return fun) assoc
- prefix name fun = R.Prefix (filter_bool_operator name >> return fun)
+ binary name fun = R.Infix (filter_bool_operator name >> return fun)
+ prefix name fun = R.Prefix (filter_bool_operator name >> return fun)
-- postfix name fun = Text.Parsec.Expr.Postfix (filter_bool_operator name >> return fun)
filter_bool_operator
where
account_section_end =
R.choice_try
- [ R.char account_section_sep >> return ()
- , R.space_horizontal >> return ()
+ [ void $ R.char account_section_sep
+ , void $ R.space_horizontal
, R.eof
]
=> ParsecT s u m Filter_Account
filter_account = do
R.notFollowedBy $ R.space_horizontal
- R.many1_separated filter_account_section $
- R.char account_section_sep
+ Filter_Ord o () <-
+ R.option (Filter_Ord Eq ()) $ R.try $
+ (\f -> f ()) <$> filter_ord
+ fmap (Filter_Account o) $
+ R.many1_separated filter_account_section $
+ R.char account_section_sep
filter_account_operator
:: Stream s m Char
return $ do
ctx <- R.getState
let (year, _, _) = Date.gregorian $ context_date ctx
- Date.Read.date Error_Filter_Date (Just year)
- >>= return . Bool . Filter_Date_UTC . tst
+ liftM (Bool . Filter_Date_UTC . tst) $
+ Date.Read.date Error_Filter_Date (Just year)
]
where
read_date_pattern
, d2 )
(hour, minute, second) <-
R.option (Interval.unlimited, Interval.unlimited, Interval.unlimited) $ R.try $ do
- R.skipMany1 $ R.space_horizontal
+ _ <- R.char '_'
hour <- read_interval Error_Filter_Date_Interval read2
sep <- Date.Read.hour_separator
minute <- read_interval Error_Filter_Date_Interval read2
_ <- R.char sep
read_interval Error_Filter_Date_Interval $ of_digits <$> R.many1 R.digit
-- tz <- R.option Time.utc $ R.try $ do
- -- R.skipMany $ R.space_horizontal
+ -- -- R.skipMany $ R.space_horizontal
-- Date.Read.time_zone
return
( hour
]
R.choice_try
[ when (l /= Interval.Unlimited_low)
- (R.string ".." >> return ()) >> do
+ (void $ R.string "..") >> do
h <- R.choice_try
[ Interval.Limited <$> read_digits
, return Interval.Unlimited_high
where
filter_tag_name_end =
R.choice_try
- [ filter_text_operator >> return ()
- , R.space_horizontal >> return ()
+ [ void $ filter_text_operator
+ , void $ R.space_horizontal
, R.eof
]
filter_tag_value
where
filter_tag_value_end =
R.choice_try
- [ R.space_horizontal >> return ()
+ [ void $ R.space_horizontal
, R.eof
]
, jump [ "C" ] filter_amount_operator
( Filter.Filter_Balance_Negative
<$> filter_amount )
- , jump [ "B", "" ] filter_amount_operator
+ , jump [ "B" ] filter_amount_operator
( Filter.Filter_Balance_Amount
<$> filter_amount )
, return