Compare commits

..

No commits in common. "527cc0a34cb7872702099cefea3a8bd288d28617" and "4112ed2aeb866aa96fc8091c3d5d255dd05ac3fd" have entirely different histories.

3 changed files with 9 additions and 16 deletions

View File

@ -59,7 +59,6 @@ library
, text , text
, lens , lens
, hashable , hashable
, regex-tdfa
hs-source-dirs: src hs-source-dirs: src
executable buuka executable buuka

View File

@ -1,8 +1,8 @@
{ mkDerivation, aeson, base, bytestring, containers { mkDerivation, aeson, base, bytestring, containers
, deriving-compat, exceptions, filepath, hashable, hashids , deriving-compat, exceptions, filepath, hashable, hashids
, hedgehog, hedgehog-corpus, lens, mtl, optparse-applicative , hedgehog, hedgehog-corpus, lens, mtl, optparse-applicative
, regex-tdfa, stdenv, tasty, tasty-hedgehog, tasty-hunit, text , stdenv, tasty, tasty-hedgehog, tasty-hunit, text, transformers
, transformers, unliftio, vector, yaml , unliftio, vector, yaml
}: }:
mkDerivation { mkDerivation {
pname = "buuka"; pname = "buuka";
@ -12,7 +12,7 @@ mkDerivation {
isExecutable = true; isExecutable = true;
libraryHaskellDepends = [ libraryHaskellDepends = [
aeson base bytestring containers exceptions filepath hashable aeson base bytestring containers exceptions filepath hashable
hashids lens mtl regex-tdfa text transformers unliftio vector yaml hashids lens mtl text transformers unliftio vector yaml
]; ];
executableHaskellDepends = [ base optparse-applicative unliftio ]; executableHaskellDepends = [ base optparse-applicative unliftio ];
testHaskellDepends = [ testHaskellDepends = [

View File

@ -21,9 +21,6 @@ import Data.Buuka
import Data.List import Data.List
(isPrefixOf, isSuffixOf) (isPrefixOf, isSuffixOf)
import Text.Regex.TDFA
((=~))
import Data.Functor.Foldable import Data.Functor.Foldable
(Fix(..)) (Fix(..))
@ -31,20 +28,19 @@ data Field a where
Url :: Field String Url :: Field String
Title :: Field String Title :: Field String
data QueryF f where data QueryF f
StartsWith :: Field String -> String -> QueryF f = forall a. StartsWith (Field a) a
EndsWith :: Field String -> String -> QueryF f | forall a. EndsWith (Field a) a
Regex :: Field String -> String -> QueryF f | And f f
And :: f -> f -> QueryF f
deriving instance Functor QueryF deriving instance Functor QueryF
type Query = Fix QueryF type Query = Fix QueryF
startsWith :: Field String -> String -> Query startsWith :: Field a -> a -> Query
startsWith field x = Fix (StartsWith field x) startsWith field x = Fix (StartsWith field x)
endsWith :: Field String -> String -> Query endsWith :: Field a -> a -> Query
endsWith field x = Fix (EndsWith field x) endsWith field x = Fix (EndsWith field x)
(.&&.) :: Query -> Query -> Query (.&&.) :: Query -> Query -> Query
@ -56,6 +52,4 @@ evaluate = \case
EndsWith Url x -> \BuukaEntry{url=URL u} -> x `isSuffixOf` u EndsWith Url x -> \BuukaEntry{url=URL u} -> x `isSuffixOf` u
StartsWith Title x -> \BuukaEntry{title=t} -> maybe False (x `isPrefixOf`) t StartsWith Title x -> \BuukaEntry{title=t} -> maybe False (x `isPrefixOf`) t
EndsWith Title x -> \BuukaEntry{title=t} -> maybe False (x `isSuffixOf`) 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 And a b -> \e -> a e && b e