module Text.XML.HaXml.Xtract.Combinators where
import Text.XML.HaXml.Types
import Text.XML.HaXml.Combinators (CFilter)
import qualified Text.XML.HaXml.Combinators as C
type DFilter i = Content i -> Content i -> [Content i]
local,global :: CFilter i -> DFilter i
local :: CFilter i -> DFilter i
local CFilter i
f Content i
_xml Content i
sub = CFilter i
f Content i
sub
global :: CFilter i -> DFilter i
global CFilter i
f Content i
xml Content i
_sub = CFilter i
f Content i
xml
dfilter :: DFilter i -> CFilter i
dfilter :: DFilter i -> CFilter i
dfilter DFilter i
f Content i
xml = DFilter i
f Content i
xml Content i
xml
cfilter :: DFilter i -> CFilter i
cfilter :: DFilter i -> CFilter i
cfilter DFilter i
f = DFilter i
f Content i
forall a. HasCallStack => a
undefined
liftLocal, liftGlobal :: (CFilter i->CFilter i) -> (DFilter i->DFilter i)
liftLocal :: (CFilter i -> CFilter i) -> DFilter i -> DFilter i
liftLocal CFilter i -> CFilter i
ff DFilter i
df Content i
xml Content i
sub = CFilter i -> CFilter i
ff (DFilter i
df Content i
xml) Content i
sub
liftGlobal :: (CFilter i -> CFilter i) -> DFilter i -> DFilter i
liftGlobal CFilter i -> CFilter i
ff DFilter i
df Content i
xml Content i
_sub = CFilter i -> CFilter i
ff (DFilter i
df Content i
xml) Content i
xml
o :: DFilter i -> DFilter i -> DFilter i
DFilter i
g o :: DFilter i -> DFilter i -> DFilter i
`o` DFilter i
f = \Content i
xml-> (Content i -> [Content i]) -> [Content i] -> [Content i]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (DFilter i
g Content i
xml) ([Content i] -> [Content i])
-> (Content i -> [Content i]) -> Content i -> [Content i]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DFilter i
f Content i
xml
(|>|) :: (a->b->[c]) -> (a->b->[c]) -> (a->b->[c])
a -> b -> [c]
f |>| :: (a -> b -> [c]) -> (a -> b -> [c]) -> a -> b -> [c]
|>| a -> b -> [c]
g = \a
xml b
sub-> let first :: [c]
first = a -> b -> [c]
f a
xml b
sub in
if [c] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [c]
first then a -> b -> [c]
g a
xml b
sub else [c]
first
union :: (a->b->[c]) -> (a->b->[c]) -> (a->b->[c])
union :: (a -> b -> [c]) -> (a -> b -> [c]) -> a -> b -> [c]
union = ([c] -> [c] -> [c])
-> (a -> b -> [c]) -> (a -> b -> [c]) -> a -> b -> [c]
forall t t t t t.
(t -> t -> t) -> (t -> t -> t) -> (t -> t -> t) -> t -> t -> t
lift [c] -> [c] -> [c]
forall a. [a] -> [a] -> [a]
(++)
where
lift :: (t -> t -> t) -> (t -> t -> t) -> (t -> t -> t) -> t -> t -> t
lift t -> t -> t
f t -> t -> t
g t -> t -> t
h = \t
x t
y-> t -> t -> t
f (t -> t -> t
g t
x t
y) (t -> t -> t
h t
x t
y)
with, without :: DFilter i -> DFilter i -> DFilter i
DFilter i
f with :: DFilter i -> DFilter i -> DFilter i
`with` DFilter i
g = \Content i
xml-> (Content i -> Bool) -> [Content i] -> [Content i]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not(Bool -> Bool) -> (Content i -> Bool) -> Content i -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.[Content i] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null([Content i] -> Bool)
-> (Content i -> [Content i]) -> Content i -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.DFilter i
g Content i
xml) ([Content i] -> [Content i])
-> (Content i -> [Content i]) -> Content i -> [Content i]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DFilter i
f Content i
xml
DFilter i
f without :: DFilter i -> DFilter i -> DFilter i
`without` DFilter i
g = \Content i
xml-> (Content i -> Bool) -> [Content i] -> [Content i]
forall a. (a -> Bool) -> [a] -> [a]
filter ([Content i] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null([Content i] -> Bool)
-> (Content i -> [Content i]) -> Content i -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.DFilter i
g Content i
xml) ([Content i] -> [Content i])
-> (Content i -> [Content i]) -> Content i -> [Content i]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DFilter i
f Content i
xml
keep, none :: DFilter i
keep :: DFilter i
keep Content i
_xml Content i
sub = [Content i
sub]
none :: DFilter i
none Content i
_xml Content i
_sub = []
children, elm, txt :: DFilter i
children :: DFilter i
children = CFilter i -> DFilter i
forall i. CFilter i -> DFilter i
local CFilter i
forall i. CFilter i
C.children
elm :: DFilter i
elm = CFilter i -> DFilter i
forall i. CFilter i -> DFilter i
local CFilter i
forall i. CFilter i
C.elm
txt :: DFilter i
txt = CFilter i -> DFilter i
forall i. CFilter i -> DFilter i
local CFilter i
forall i. CFilter i
C.txt
applypred :: CFilter i -> DFilter i -> CFilter i
applypred :: CFilter i -> DFilter i -> CFilter i
applypred CFilter i
f DFilter i
p Content i
xml = (CFilter i -> DFilter i
forall a b. a -> b -> a
const CFilter i
f DFilter i -> DFilter i -> DFilter i
forall i. DFilter i -> DFilter i -> DFilter i
`with` DFilter i
p) Content i
xml Content i
xml
iffind :: String -> (String -> DFilter i) -> DFilter i -> DFilter i
iffind :: String -> (String -> DFilter i) -> DFilter i -> DFilter i
iffind String
key String -> DFilter i
yes DFilter i
no Content i
xml c :: Content i
c@(CElem (Elem QName
_ [Attribute]
as [Content i]
_) i
_) =
case QName -> [Attribute] -> Maybe AttValue
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup (String -> QName
N String
key) [Attribute]
as of
Maybe AttValue
Nothing -> DFilter i
no Content i
xml Content i
c
(Just v :: AttValue
v@(AttValue [Either String Reference]
_)) -> String -> DFilter i
yes (AttValue -> String
forall a. Show a => a -> String
show AttValue
v) Content i
xml Content i
c
iffind String
_key String -> DFilter i
_yes DFilter i
no Content i
xml Content i
other = DFilter i
no Content i
xml Content i
other
ifTxt :: (String->DFilter i) -> DFilter i -> DFilter i
ifTxt :: (String -> DFilter i) -> DFilter i -> DFilter i
ifTxt String -> DFilter i
yes DFilter i
_no Content i
xml c :: Content i
c@(CString Bool
_ String
s i
_) = String -> DFilter i
yes String
s Content i
xml Content i
c
ifTxt String -> DFilter i
_yes DFilter i
no Content i
xml Content i
c = DFilter i
no Content i
xml Content i
c
cat :: [a->b->[c]] -> (a->b->[c])
cat :: [a -> b -> [c]] -> a -> b -> [c]
cat [a -> b -> [c]]
fs a
xml b
sub = [[c]] -> [c]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ a -> b -> [c]
f a
xml b
sub | a -> b -> [c]
f <- [a -> b -> [c]]
fs ]
(/>) :: DFilter i -> DFilter i -> DFilter i
DFilter i
f /> :: DFilter i -> DFilter i -> DFilter i
/> DFilter i
g = DFilter i
g DFilter i -> DFilter i -> DFilter i
forall i. DFilter i -> DFilter i -> DFilter i
`o` DFilter i
forall i. DFilter i
children DFilter i -> DFilter i -> DFilter i
forall i. DFilter i -> DFilter i -> DFilter i
`o` DFilter i
f
(</) :: DFilter i -> DFilter i -> DFilter i
DFilter i
f </ :: DFilter i -> DFilter i -> DFilter i
</ DFilter i
g = DFilter i
f DFilter i -> DFilter i -> DFilter i
forall i. DFilter i -> DFilter i -> DFilter i
`with` (DFilter i
g DFilter i -> DFilter i -> DFilter i
forall i. DFilter i -> DFilter i -> DFilter i
`o` DFilter i
forall i. DFilter i
children)
deep, deepest, multi :: DFilter i -> DFilter i
deep :: DFilter i -> DFilter i
deep DFilter i
f = DFilter i
f DFilter i -> DFilter i -> DFilter i
forall a b c. (a -> b -> [c]) -> (a -> b -> [c]) -> a -> b -> [c]
|>| (DFilter i -> DFilter i
forall i. DFilter i -> DFilter i
deep DFilter i
f DFilter i -> DFilter i -> DFilter i
forall i. DFilter i -> DFilter i -> DFilter i
`o` DFilter i
forall i. DFilter i
children)
deepest :: DFilter i -> DFilter i
deepest DFilter i
f = (DFilter i -> DFilter i
forall i. DFilter i -> DFilter i
deepest DFilter i
f DFilter i -> DFilter i -> DFilter i
forall i. DFilter i -> DFilter i -> DFilter i
`o` DFilter i
forall i. DFilter i
children) DFilter i -> DFilter i -> DFilter i
forall a b c. (a -> b -> [c]) -> (a -> b -> [c]) -> a -> b -> [c]
|>| DFilter i
f
multi :: DFilter i -> DFilter i
multi DFilter i
f = DFilter i
f DFilter i -> DFilter i -> DFilter i
forall a b c. (a -> b -> [c]) -> (a -> b -> [c]) -> a -> b -> [c]
`union` (DFilter i -> DFilter i
forall i. DFilter i -> DFilter i
multi DFilter i
f DFilter i -> DFilter i -> DFilter i
forall i. DFilter i -> DFilter i -> DFilter i
`o` DFilter i
forall i. DFilter i
children)