Add regex to the query language
This commit is contained in:
@ -21,6 +21,9 @@ import Data.Buuka
|
||||
import Data.List
|
||||
(isPrefixOf, isSuffixOf)
|
||||
|
||||
import Text.Regex.TDFA
|
||||
((=~))
|
||||
|
||||
import Data.Functor.Foldable
|
||||
(Fix(..))
|
||||
|
||||
@ -31,6 +34,7 @@ data Field a where
|
||||
data QueryF f where
|
||||
StartsWith :: Field String -> String -> QueryF f
|
||||
EndsWith :: Field String -> String -> QueryF f
|
||||
Regex :: Field String -> String -> QueryF f
|
||||
And :: f -> f -> QueryF f
|
||||
|
||||
deriving instance Functor QueryF
|
||||
@ -52,4 +56,6 @@ evaluate = \case
|
||||
EndsWith Url x -> \BuukaEntry{url=URL u} -> x `isSuffixOf` u
|
||||
StartsWith Title x -> \BuukaEntry{title=t} -> maybe False (x `isPrefixOf`) t
|
||||
EndsWith Title x -> \BuukaEntry{title=t} -> maybe False (x `isSuffixOf`) t
|
||||
Regex Url x -> \BuukaEntry{url=URL u} -> u =~ x
|
||||
Regex Title x -> \BuukaEntry{title=t} -> maybe False (=~ x) t
|
||||
And a b -> \e -> a e && b e
|
||||
|
Reference in New Issue
Block a user