module Text.XML.Selector.Types where
import Data.List (sort)
import qualified Data.Map as M (lookup,fromList)
import Data.Maybe (fromMaybe)
data JQSelector = JQSelector {
relPrev :: RelPrev,
jqTagName :: Maybe String,
jqTagId :: Maybe String,
jqTagClass :: [String],
jqTagAttr :: [TagAttr]
} deriving (Show,Read,Ord)
instance Eq JQSelector where
(JQSelector r1 n1 i1 c1 a1) == (JQSelector r2 n2 i2 c2 a2) = r1 == r2 && n1 == n2 && i1 == i2 && (sort c1 == sort c2 && sort a1 == sort a2)
data TagAttr = TagAttr {
attrName :: String,
attrVal :: Maybe String,
attrRel :: AttrRel
} deriving (Eq,Show,Read,Ord)
data AttrRel = Equal | Begin | End | Contains | NotEqual | ContainsWord | Exists deriving (Show,Eq,Ord,Enum,Read)
relToStr :: AttrRel -> String
relToStr r = fromMaybe "N/A" $ M.lookup r (M.fromList [(Equal,"="),(Begin,"^="),(End,"$="),(Contains,"|="),(NotEqual,"!="),(ContainsWord,"*=")])
data RelPrev = Descendant | Child | Next | Sibling deriving (Eq,Show,Enum,Read,Ord)