module XMLQuery
where
import XMLQuery.Prelude hiding (Text)
import qualified XMLQuery.Prelude as Prelude
import qualified XMLQuery.AST as AST
type Text =
Alt AST.Text
text :: (Prelude.Text -> Either Prelude.Text a) -> Text a
text =
liftAlt . AST.Text
textValue :: Text Prelude.Text
textValue =
text pure
type Element =
Alt AST.Element
elementNameText :: Text a -> Element a
elementNameText =
liftAlt . AST.ElementNameText
elementAttr :: Attr a -> Element a
elementAttr =
liftAlt . AST.ElementAttr
elementNodes :: Nodes a -> Element a
elementNodes =
liftAlt . AST.ElementNodes
elementNameIs :: Prelude.Text -> Element ()
elementNameIs expected =
elementNameText (text textParserFn)
where
textParserFn actual =
if actual == expected
then Right ()
else Left ("elementNameIs: The actual name \"" <> actual <> "\" does not equal the expected \"" <> expected <> "\"")
type Attr =
Alt AST.Attr
attrNameText :: Text a -> Attr a
attrNameText =
liftAlt . AST.AttrNameText
attrValueText :: Text a -> Attr a
attrValueText =
liftAlt . AST.AttrValueText
attrNameIs :: Prelude.Text -> Attr ()
attrNameIs expected =
attrNameText (text textParserFn)
where
textParserFn actual =
if actual == expected
then Right ()
else Left ("attrNameIs: The actual name \"" <> actual <> "\" does not equal the expected \"" <> expected <> "\"")
attrValueIs :: Prelude.Text -> Attr ()
attrValueIs expected =
attrValueText (text textParserFn)
where
textParserFn actual =
if actual == expected
then Right ()
else Left ("attrValueIs: The actual name \"" <> actual <> "\" does not equal the expected \"" <> expected <> "\"")
type Nodes =
Alt AST.Nodes
nodesImmediateNode :: Node a -> Nodes a
nodesImmediateNode =
liftAlt . AST.NodesNode
nodesEventualNode :: Node a -> Nodes a
nodesEventualNode node =
fix $ \loop ->
nodesImmediateNode node <|> (nodesImmediateNode (pure ()) *> loop)
type Node =
Alt AST.Node
nodeElement :: Element a -> Node a
nodeElement =
liftAlt . AST.NodeElement
nodeText :: Text a -> Node a
nodeText =
liftAlt . AST.NodeText