Compare commits
3 Commits
4112ed2aeb
...
527cc0a34c
Author | SHA1 | Date | |
---|---|---|---|
527cc0a34c | |||
7bae9ca92e | |||
9048581ea1 |
@ -59,6 +59,7 @@ library
|
||||
, text
|
||||
, lens
|
||||
, hashable
|
||||
, regex-tdfa
|
||||
hs-source-dirs: src
|
||||
|
||||
executable buuka
|
||||
|
@ -1,8 +1,8 @@
|
||||
{ mkDerivation, aeson, base, bytestring, containers
|
||||
, deriving-compat, exceptions, filepath, hashable, hashids
|
||||
, hedgehog, hedgehog-corpus, lens, mtl, optparse-applicative
|
||||
, stdenv, tasty, tasty-hedgehog, tasty-hunit, text, transformers
|
||||
, unliftio, vector, yaml
|
||||
, regex-tdfa, stdenv, tasty, tasty-hedgehog, tasty-hunit, text
|
||||
, transformers, unliftio, vector, yaml
|
||||
}:
|
||||
mkDerivation {
|
||||
pname = "buuka";
|
||||
@ -12,7 +12,7 @@ mkDerivation {
|
||||
isExecutable = true;
|
||||
libraryHaskellDepends = [
|
||||
aeson base bytestring containers exceptions filepath hashable
|
||||
hashids lens mtl text transformers unliftio vector yaml
|
||||
hashids lens mtl regex-tdfa text transformers unliftio vector yaml
|
||||
];
|
||||
executableHaskellDepends = [ base optparse-applicative unliftio ];
|
||||
testHaskellDepends = [
|
||||
|
@ -21,6 +21,9 @@ import Data.Buuka
|
||||
import Data.List
|
||||
(isPrefixOf, isSuffixOf)
|
||||
|
||||
import Text.Regex.TDFA
|
||||
((=~))
|
||||
|
||||
import Data.Functor.Foldable
|
||||
(Fix(..))
|
||||
|
||||
@ -28,19 +31,20 @@ data Field a where
|
||||
Url :: Field String
|
||||
Title :: Field String
|
||||
|
||||
data QueryF f
|
||||
= forall a. StartsWith (Field a) a
|
||||
| forall a. EndsWith (Field a) a
|
||||
| And f f
|
||||
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
|
||||
|
||||
type Query = Fix QueryF
|
||||
|
||||
startsWith :: Field a -> a -> Query
|
||||
startsWith :: Field String -> String -> Query
|
||||
startsWith field x = Fix (StartsWith field x)
|
||||
|
||||
endsWith :: Field a -> a -> Query
|
||||
endsWith :: Field String -> String -> Query
|
||||
endsWith field x = Fix (EndsWith field x)
|
||||
|
||||
(.&&.) :: Query -> Query -> Query
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user