{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module Text.Haiji.Syntax.Filter
( Filter(..)
, filter
) where
#if MIN_VERSION_base(4,8,0)
#else
import Control.Applicative
#endif
import Data.Attoparsec.Text
import Prelude hiding (filter)
data Filter = FilterAbs
| FilterLength
deriving Filter -> Filter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Filter -> Filter -> Bool
$c/= :: Filter -> Filter -> Bool
== :: Filter -> Filter -> Bool
$c== :: Filter -> Filter -> Bool
Eq
instance Show Filter where
show :: Filter -> String
show (Filter
FilterAbs) = String
"|abs"
show (Filter
FilterLength) = String
"|length"
filter :: Parser Filter
filter :: Parser Filter
filter = Char -> Parser Char
char Char
'|' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
Parser Text ()
skipSpace forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
forall (f :: * -> *) a. Alternative f => [f a] -> f a
choice
[ Parser Filter
filterAbs
, Parser Filter
filterLength
]
filterAbs :: Parser Filter
filterAbs :: Parser Filter
filterAbs = Text -> Parser Text
string Text
"abs" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) a. Monad m => a -> m a
return Filter
FilterAbs
filterLength :: Parser Filter
filterLength :: Parser Filter
filterLength = Text -> Parser Text
string Text
"length" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) a. Monad m => a -> m a
return Filter
FilterLength