{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PatternGuards #-}
module Text.Pandoc.Readers.ODT.Generic.XMLConverter
( ElementName
, XMLConverterState
, XMLConverter
, FallibleXMLConverter
, runConverter'
, getExtraState
, setExtraState
, modifyExtraState
, producingExtraState
, findChild'
, filterChildrenName'
, isSet'
, isSetWithDefault
, elName
, searchAttr
, lookupAttr
, lookupAttr'
, lookupDefaultingAttr
, findAttr'
, findAttrText'
, findAttr
, findAttrText
, findAttrTextWithDefault
, readAttr
, readAttr'
, readAttrWithDefault
, getAttr
, executeIn
, executeInSub
, withEveryL
, tryAll
, matchContent'
, matchContent
) where
import Prelude hiding (Applicative(..))
import Control.Applicative hiding ( liftA, liftA2 )
import Control.Monad ( MonadPlus )
import Control.Arrow
import Data.Bool ( bool )
import Data.Either ( rights )
import qualified Data.Map as M
import Data.Text (Text)
import Data.Default
import Data.Maybe
import Data.List (foldl')
import qualified Text.Pandoc.XML.Light as XML
import Text.Pandoc.Readers.ODT.Arrows.State
import Text.Pandoc.Readers.ODT.Arrows.Utils
import Text.Pandoc.Readers.ODT.Generic.Namespaces
import Text.Pandoc.Readers.ODT.Generic.Utils
import Text.Pandoc.Readers.ODT.Generic.Fallible
type ElementName = Text
type AttributeName = Text
type AttributeValue = Text
type TextAttributeValue = Text
type NameSpacePrefix = Text
type NameSpacePrefixes nsID = M.Map nsID NameSpacePrefix
data XMLConverterState nsID extraState where
XMLConverterState :: NameSpaceID nsID
=> {
forall nsID extraState.
XMLConverterState nsID extraState -> [Element]
parentElements :: [XML.Element]
, forall nsID extraState.
XMLConverterState nsID extraState -> NameSpacePrefixes nsID
namespacePrefixes :: NameSpacePrefixes nsID
, forall nsID extraState.
XMLConverterState nsID extraState -> NameSpacePrefixes nsID
namespaceIRIs :: NameSpaceIRIs nsID
, forall nsID extraState.
XMLConverterState nsID extraState -> extraState
moreState :: extraState
}
-> XMLConverterState nsID extraState
createStartState :: (NameSpaceID nsID)
=> XML.Element
-> extraState
-> XMLConverterState nsID extraState
createStartState :: forall nsID extraState.
NameSpaceID nsID =>
Element -> extraState -> XMLConverterState nsID extraState
createStartState Element
element extraState
extraState =
XMLConverterState
{ parentElements :: [Element]
parentElements = [Element
element]
, namespacePrefixes :: NameSpacePrefixes nsID
namespacePrefixes = NameSpacePrefixes nsID
forall k a. Map k a
M.empty
, namespaceIRIs :: NameSpacePrefixes nsID
namespaceIRIs = NameSpacePrefixes nsID
forall nsID. NameSpaceID nsID => NameSpaceIRIs nsID
getInitialIRImap
, moreState :: extraState
moreState = extraState
extraState
}
instance Functor (XMLConverterState nsID) where
fmap :: forall a b.
(a -> b) -> XMLConverterState nsID a -> XMLConverterState nsID b
fmap a -> b
f ( XMLConverterState [Element]
parents NameSpacePrefixes nsID
prefixes NameSpacePrefixes nsID
iRIs a
extraState )
= [Element]
-> NameSpacePrefixes nsID
-> NameSpacePrefixes nsID
-> b
-> XMLConverterState nsID b
forall nsID extraState.
NameSpaceID nsID =>
[Element]
-> NameSpacePrefixes nsID
-> NameSpacePrefixes nsID
-> extraState
-> XMLConverterState nsID extraState
XMLConverterState [Element]
parents NameSpacePrefixes nsID
prefixes NameSpacePrefixes nsID
iRIs (a -> b
f a
extraState)
replaceExtraState :: extraState
-> XMLConverterState nsID _x
-> XMLConverterState nsID extraState
extraState
x XMLConverterState nsID _x
s
= (_x -> extraState)
-> XMLConverterState nsID _x -> XMLConverterState nsID extraState
forall a b.
(a -> b) -> XMLConverterState nsID a -> XMLConverterState nsID b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (extraState -> _x -> extraState
forall a b. a -> b -> a
const extraState
x) XMLConverterState nsID _x
s
currentElement :: XMLConverterState nsID extraState
-> XML.Element
currentElement :: forall nsID extraState.
XMLConverterState nsID extraState -> Element
currentElement XMLConverterState nsID extraState
state = [Element] -> Element
forall a. HasCallStack => [a] -> a
head (XMLConverterState nsID extraState -> [Element]
forall nsID extraState.
XMLConverterState nsID extraState -> [Element]
parentElements XMLConverterState nsID extraState
state)
swapStack' :: XMLConverterState nsID extraState
-> [XML.Element]
-> ( XMLConverterState nsID extraState , [XML.Element] )
swapStack' :: forall nsID extraState.
XMLConverterState nsID extraState
-> [Element] -> (XMLConverterState nsID extraState, [Element])
swapStack' XMLConverterState nsID extraState
state [Element]
stack
= ( XMLConverterState nsID extraState
state { parentElements :: [Element]
parentElements = [Element]
stack }
, XMLConverterState nsID extraState -> [Element]
forall nsID extraState.
XMLConverterState nsID extraState -> [Element]
parentElements XMLConverterState nsID extraState
state
)
pushElement :: XML.Element
-> XMLConverterState nsID extraState
-> XMLConverterState nsID extraState
pushElement :: forall nsID extraState.
Element
-> XMLConverterState nsID extraState
-> XMLConverterState nsID extraState
pushElement Element
e XMLConverterState nsID extraState
state = XMLConverterState nsID extraState
state { parentElements :: [Element]
parentElements = Element
eElement -> [Element] -> [Element]
forall a. a -> [a] -> [a]
:XMLConverterState nsID extraState -> [Element]
forall nsID extraState.
XMLConverterState nsID extraState -> [Element]
parentElements XMLConverterState nsID extraState
state }
popElement :: XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
popElement :: forall nsID extraState.
XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
popElement XMLConverterState nsID extraState
state
| Element
_:es :: [Element]
es@(Element
_:[Element]
_) <- XMLConverterState nsID extraState -> [Element]
forall nsID extraState.
XMLConverterState nsID extraState -> [Element]
parentElements XMLConverterState nsID extraState
state = XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
forall a. a -> Maybe a
Just (XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState))
-> XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
forall a b. (a -> b) -> a -> b
$ XMLConverterState nsID extraState
state { parentElements :: [Element]
parentElements = [Element]
es }
| Bool
otherwise = Maybe (XMLConverterState nsID extraState)
forall a. Maybe a
Nothing
type XMLConverter nsID extraState input output
= ArrowState (XMLConverterState nsID extraState ) input output
type FallibleXMLConverter nsID extraState input output
= XMLConverter nsID extraState input (Fallible output)
runConverter :: XMLConverter nsID extraState input output
-> XMLConverterState nsID extraState
-> input
-> output
runConverter :: forall nsID extraState input output.
XMLConverter nsID extraState input output
-> XMLConverterState nsID extraState -> input -> output
runConverter XMLConverter nsID extraState input output
converter XMLConverterState nsID extraState
state input
input = (XMLConverterState nsID extraState, output) -> output
forall a b. (a, b) -> b
snd ((XMLConverterState nsID extraState, output) -> output)
-> (XMLConverterState nsID extraState, output) -> output
forall a b. (a -> b) -> a -> b
$ XMLConverter nsID extraState input output
-> (XMLConverterState nsID extraState, input)
-> (XMLConverterState nsID extraState, output)
forall state a b. ArrowState state a b -> (state, a) -> (state, b)
runArrowState XMLConverter nsID extraState input output
converter (XMLConverterState nsID extraState
state,input
input)
runConverter' :: (NameSpaceID nsID)
=> FallibleXMLConverter nsID extraState () success
-> extraState
-> XML.Element
-> Fallible success
runConverter' :: forall nsID extraState success.
NameSpaceID nsID =>
FallibleXMLConverter nsID extraState () success
-> extraState -> Element -> Fallible success
runConverter' FallibleXMLConverter nsID extraState () success
converter extraState
extraState Element
element = FallibleXMLConverter nsID extraState () success
-> XMLConverterState nsID extraState -> () -> Fallible success
forall nsID extraState input output.
XMLConverter nsID extraState input output
-> XMLConverterState nsID extraState -> input -> output
runConverter (FallibleXMLConverter nsID extraState () ()
forall nsID extraState x.
NameSpaceID nsID =>
FallibleXMLConverter nsID extraState x ()
readNSattributes FallibleXMLConverter nsID extraState () ()
-> FallibleXMLConverter nsID extraState () success
-> FallibleXMLConverter nsID extraState () success
forall (a :: * -> * -> *) x failure success success'.
ArrowChoice a =>
FallibleArrow a x failure success
-> FallibleArrow a success failure success'
-> FallibleArrow a x failure success'
>>? FallibleXMLConverter nsID extraState () success
converter) (Element -> extraState -> XMLConverterState nsID extraState
forall nsID extraState.
NameSpaceID nsID =>
Element -> extraState -> XMLConverterState nsID extraState
createStartState Element
element extraState
extraState) ()
getCurrentElement :: XMLConverter nsID extraState x XML.Element
getCurrentElement :: forall nsID extraState x. XMLConverter nsID extraState x Element
getCurrentElement = (XMLConverterState nsID extraState -> Element)
-> ArrowState (XMLConverterState nsID extraState) x Element
forall state b x. (state -> b) -> ArrowState state x b
extractFromState XMLConverterState nsID extraState -> Element
forall nsID extraState.
XMLConverterState nsID extraState -> Element
currentElement
getExtraState :: XMLConverter nsID extraState x extraState
= (XMLConverterState nsID extraState -> extraState)
-> ArrowState (XMLConverterState nsID extraState) x extraState
forall state b x. (state -> b) -> ArrowState state x b
extractFromState XMLConverterState nsID extraState -> extraState
forall nsID extraState.
XMLConverterState nsID extraState -> extraState
moreState
setExtraState :: XMLConverter nsID extraState extraState extraState
= (XMLConverterState nsID extraState
-> extraState -> (XMLConverterState nsID extraState, extraState))
-> ArrowState
(XMLConverterState nsID extraState) extraState extraState
forall state a b.
(state -> a -> (state, b)) -> ArrowState state a b
withState ((XMLConverterState nsID extraState
-> extraState -> (XMLConverterState nsID extraState, extraState))
-> ArrowState
(XMLConverterState nsID extraState) extraState extraState)
-> (XMLConverterState nsID extraState
-> extraState -> (XMLConverterState nsID extraState, extraState))
-> ArrowState
(XMLConverterState nsID extraState) extraState extraState
forall a b. (a -> b) -> a -> b
$ \XMLConverterState nsID extraState
state extraState
extra
-> (extraState
-> XMLConverterState nsID extraState
-> XMLConverterState nsID extraState
forall extraState nsID _x.
extraState
-> XMLConverterState nsID _x -> XMLConverterState nsID extraState
replaceExtraState extraState
extra XMLConverterState nsID extraState
state , extraState
extra)
modifyExtraState :: (extraState -> extraState)
-> XMLConverter nsID extraState x x
= (XMLConverterState nsID extraState
-> XMLConverterState nsID extraState)
-> ArrowState (XMLConverterState nsID extraState) x x
forall state a. (state -> state) -> ArrowState state a a
modifyState((XMLConverterState nsID extraState
-> XMLConverterState nsID extraState)
-> ArrowState (XMLConverterState nsID extraState) x x)
-> ((extraState -> extraState)
-> XMLConverterState nsID extraState
-> XMLConverterState nsID extraState)
-> (extraState -> extraState)
-> ArrowState (XMLConverterState nsID extraState) x x
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(extraState -> extraState)
-> XMLConverterState nsID extraState
-> XMLConverterState nsID extraState
forall a b.
(a -> b) -> XMLConverterState nsID a -> XMLConverterState nsID b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
convertingExtraState :: extraState'
-> FallibleXMLConverter nsID extraState' extraState extraState
-> FallibleXMLConverter nsID extraState x x
extraState'
v FallibleXMLConverter nsID extraState' extraState extraState
a = ArrowState
(XMLConverterState nsID extraState)
x
(Either () (XMLConverterState nsID extraState'))
-> ArrowState
(XMLConverterState nsID extraState')
(XMLConverterState nsID extraState)
(Either () (XMLConverterState nsID extraState))
-> ArrowState (XMLConverterState nsID extraState) x (Either () x)
forall s x f s'.
ArrowState s x (Either f s')
-> ArrowState s' s (Either f s) -> ArrowState s x (Either f x)
withSubStateF ArrowState
(XMLConverterState nsID extraState)
x
(Either () (XMLConverterState nsID extraState'))
setVAsExtraState ArrowState
(XMLConverterState nsID extraState')
(XMLConverterState nsID extraState)
(Either () (XMLConverterState nsID extraState))
modifyWithA
where
setVAsExtraState :: ArrowState
(XMLConverterState nsID extraState)
x
(Either () (XMLConverterState nsID extraState'))
setVAsExtraState = ArrowState
(XMLConverterState nsID extraState)
x
(XMLConverterState nsID extraState')
-> ArrowState
(XMLConverterState nsID extraState)
x
(Either () (XMLConverterState nsID extraState'))
forall (a :: * -> * -> *) x success failure.
ArrowChoice a =>
a x success -> FallibleArrow a x failure success
liftAsSuccess (ArrowState
(XMLConverterState nsID extraState)
x
(XMLConverterState nsID extraState')
-> ArrowState
(XMLConverterState nsID extraState)
x
(Either () (XMLConverterState nsID extraState')))
-> ArrowState
(XMLConverterState nsID extraState)
x
(XMLConverterState nsID extraState')
-> ArrowState
(XMLConverterState nsID extraState)
x
(Either () (XMLConverterState nsID extraState'))
forall a b. (a -> b) -> a -> b
$ (XMLConverterState nsID extraState
-> XMLConverterState nsID extraState)
-> ArrowState
(XMLConverterState nsID extraState)
x
(XMLConverterState nsID extraState)
forall state b x. (state -> b) -> ArrowState state x b
extractFromState XMLConverterState nsID extraState
-> XMLConverterState nsID extraState
forall a. a -> a
id ArrowState
(XMLConverterState nsID extraState)
x
(XMLConverterState nsID extraState)
-> (XMLConverterState nsID extraState
-> XMLConverterState nsID extraState')
-> ArrowState
(XMLConverterState nsID extraState)
x
(XMLConverterState nsID extraState')
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ extraState'
-> XMLConverterState nsID extraState
-> XMLConverterState nsID extraState'
forall extraState nsID _x.
extraState
-> XMLConverterState nsID _x -> XMLConverterState nsID extraState
replaceExtraState extraState'
v
modifyWithA :: ArrowState
(XMLConverterState nsID extraState')
(XMLConverterState nsID extraState)
(Either () (XMLConverterState nsID extraState))
modifyWithA = ArrowState
(XMLConverterState nsID extraState')
(XMLConverterState nsID extraState)
(Fallible extraState)
-> ArrowState
(XMLConverterState nsID extraState')
(XMLConverterState nsID extraState)
(XMLConverterState nsID extraState, Fallible extraState)
forall (a :: * -> * -> *) b c. Arrow a => a b c -> a b (b, c)
keepingTheValue (XMLConverterState nsID extraState -> extraState
forall nsID extraState.
XMLConverterState nsID extraState -> extraState
moreState (XMLConverterState nsID extraState -> extraState)
-> FallibleXMLConverter nsID extraState' extraState extraState
-> ArrowState
(XMLConverterState nsID extraState')
(XMLConverterState nsID extraState)
(Fallible extraState)
forall (a :: * -> * -> *) b c d.
Arrow a =>
(b -> c) -> a c d -> a b d
^>> FallibleXMLConverter nsID extraState' extraState extraState
a)
ArrowState
(XMLConverterState nsID extraState')
(XMLConverterState nsID extraState)
(XMLConverterState nsID extraState, Fallible extraState)
-> ((XMLConverterState nsID extraState, Fallible extraState)
-> Either () (XMLConverterState nsID extraState))
-> ArrowState
(XMLConverterState nsID extraState')
(XMLConverterState nsID extraState)
(Either () (XMLConverterState nsID extraState))
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ (XMLConverterState nsID extraState, Fallible extraState)
-> Either () (XMLConverterState nsID extraState, extraState)
forall f a.
(XMLConverterState nsID extraState, Either f a)
-> Either f (XMLConverterState nsID extraState, a)
forall (v :: * -> *) f a.
ChoiceVector v =>
v (Either f a) -> Either f (v a)
spreadChoice ((XMLConverterState nsID extraState, Fallible extraState)
-> Either () (XMLConverterState nsID extraState, extraState))
-> (XMLConverterState nsID extraState
-> extraState -> XMLConverterState nsID extraState)
-> (XMLConverterState nsID extraState, Fallible extraState)
-> Either () (XMLConverterState nsID extraState)
forall (a :: * -> * -> *) x f b b' c.
ArrowChoice a =>
FallibleArrow a x f (b, b')
-> (b -> b' -> c) -> FallibleArrow a x f c
>>?% (extraState
-> XMLConverterState nsID extraState
-> XMLConverterState nsID extraState)
-> XMLConverterState nsID extraState
-> extraState
-> XMLConverterState nsID extraState
forall a b c. (a -> b -> c) -> b -> a -> c
flip extraState
-> XMLConverterState nsID extraState
-> XMLConverterState nsID extraState
forall extraState nsID _x.
extraState
-> XMLConverterState nsID _x -> XMLConverterState nsID extraState
replaceExtraState
producingExtraState :: extraState'
-> a
-> FallibleXMLConverter nsID extraState' a extraState
-> FallibleXMLConverter nsID extraState x x
extraState'
v a
x FallibleXMLConverter nsID extraState' a extraState
a = extraState'
-> FallibleXMLConverter nsID extraState' extraState extraState
-> FallibleXMLConverter nsID extraState x x
forall extraState' nsID extraState x.
extraState'
-> FallibleXMLConverter nsID extraState' extraState extraState
-> FallibleXMLConverter nsID extraState x x
convertingExtraState extraState'
v (a -> ArrowState (XMLConverterState nsID extraState') extraState a
forall (a :: * -> * -> *) c x. Arrow a => c -> a x c
returnV a
x ArrowState (XMLConverterState nsID extraState') extraState a
-> FallibleXMLConverter nsID extraState' a extraState
-> FallibleXMLConverter nsID extraState' extraState extraState
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> FallibleXMLConverter nsID extraState' a extraState
a)
lookupNSiri :: (NameSpaceID nsID)
=> nsID
-> XMLConverter nsID extraState x (Maybe NameSpaceIRI)
lookupNSiri :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> XMLConverter nsID extraState x (Maybe Text)
lookupNSiri nsID
nsID = (XMLConverterState nsID extraState -> Maybe Text)
-> ArrowState (XMLConverterState nsID extraState) x (Maybe Text)
forall state b x. (state -> b) -> ArrowState state x b
extractFromState
((XMLConverterState nsID extraState -> Maybe Text)
-> ArrowState (XMLConverterState nsID extraState) x (Maybe Text))
-> (XMLConverterState nsID extraState -> Maybe Text)
-> ArrowState (XMLConverterState nsID extraState) x (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \XMLConverterState nsID extraState
state -> nsID -> NameSpaceIRIs nsID -> Maybe Text
forall nsID.
NameSpaceID nsID =>
nsID -> NameSpaceIRIs nsID -> Maybe Text
getIRI nsID
nsID (NameSpaceIRIs nsID -> Maybe Text)
-> NameSpaceIRIs nsID -> Maybe Text
forall a b. (a -> b) -> a -> b
$ XMLConverterState nsID extraState -> NameSpaceIRIs nsID
forall nsID extraState.
XMLConverterState nsID extraState -> NameSpacePrefixes nsID
namespaceIRIs XMLConverterState nsID extraState
state
lookupNSprefix :: (NameSpaceID nsID)
=> nsID
-> XMLConverter nsID extraState x (Maybe NameSpacePrefix)
lookupNSprefix :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> XMLConverter nsID extraState x (Maybe Text)
lookupNSprefix nsID
nsID = (XMLConverterState nsID extraState -> Maybe Text)
-> ArrowState (XMLConverterState nsID extraState) x (Maybe Text)
forall state b x. (state -> b) -> ArrowState state x b
extractFromState
((XMLConverterState nsID extraState -> Maybe Text)
-> ArrowState (XMLConverterState nsID extraState) x (Maybe Text))
-> (XMLConverterState nsID extraState -> Maybe Text)
-> ArrowState (XMLConverterState nsID extraState) x (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \XMLConverterState nsID extraState
state -> nsID -> Map nsID Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup nsID
nsID (Map nsID Text -> Maybe Text) -> Map nsID Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ XMLConverterState nsID extraState -> Map nsID Text
forall nsID extraState.
XMLConverterState nsID extraState -> NameSpacePrefixes nsID
namespacePrefixes XMLConverterState nsID extraState
state
readNSattributes :: (NameSpaceID nsID)
=> FallibleXMLConverter nsID extraState x ()
readNSattributes :: forall nsID extraState x.
NameSpaceID nsID =>
FallibleXMLConverter nsID extraState x ()
readNSattributes = (XMLConverterState nsID extraState
-> (XMLConverterState nsID extraState, Fallible ()))
-> ArrowState (XMLConverterState nsID extraState) x (Fallible ())
forall state b a. (state -> (state, b)) -> ArrowState state a b
fromState ((XMLConverterState nsID extraState
-> (XMLConverterState nsID extraState, Fallible ()))
-> ArrowState (XMLConverterState nsID extraState) x (Fallible ()))
-> (XMLConverterState nsID extraState
-> (XMLConverterState nsID extraState, Fallible ()))
-> ArrowState (XMLConverterState nsID extraState) x (Fallible ())
forall a b. (a -> b) -> a -> b
$ \XMLConverterState nsID extraState
state -> (XMLConverterState nsID extraState, Fallible ())
-> (XMLConverterState nsID extraState
-> (XMLConverterState nsID extraState, Fallible ()))
-> Maybe (XMLConverterState nsID extraState)
-> (XMLConverterState nsID extraState, Fallible ())
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (XMLConverterState nsID extraState
state, Fallible ()
forall failure _x. Monoid failure => Either failure _x
failEmpty )
( , () -> Fallible ()
forall a _x. a -> Either _x a
succeedWith ())
(XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
forall nsID extraState.
NameSpaceID nsID =>
XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
extractNSAttrs XMLConverterState nsID extraState
state )
where
extractNSAttrs :: (NameSpaceID nsID)
=> XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
extractNSAttrs :: forall nsID extraState.
NameSpaceID nsID =>
XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
extractNSAttrs XMLConverterState nsID extraState
startState
= (Maybe (XMLConverterState nsID extraState)
-> (Text, Text) -> Maybe (XMLConverterState nsID extraState))
-> Maybe (XMLConverterState nsID extraState)
-> [(Text, Text)]
-> Maybe (XMLConverterState nsID extraState)
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Maybe (XMLConverterState nsID extraState)
state (Text, Text)
d -> Maybe (XMLConverterState nsID extraState)
state Maybe (XMLConverterState nsID extraState)
-> (XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState))
-> Maybe (XMLConverterState nsID extraState)
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Text, Text)
-> XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
forall {nsID} {extraState}.
NameSpaceID nsID =>
(Text, Text)
-> XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
addNS (Text, Text)
d)
(XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
forall a. a -> Maybe a
Just XMLConverterState nsID extraState
startState)
[(Text, Text)]
nsAttribs
where nsAttribs :: [(Text, Text)]
nsAttribs = (Attr -> Maybe (Text, Text)) -> [Attr] -> [(Text, Text)]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Attr -> Maybe (Text, Text)
readNSattr (Element -> [Attr]
XML.elAttribs Element
element)
element :: Element
element = XMLConverterState nsID extraState -> Element
forall nsID extraState.
XMLConverterState nsID extraState -> Element
currentElement XMLConverterState nsID extraState
startState
readNSattr :: Attr -> Maybe (Text, Text)
readNSattr (XML.Attr (XML.QName Text
name Maybe Text
_ (Just Text
"xmlns")) Text
iri)
= (Text, Text) -> Maybe (Text, Text)
forall a. a -> Maybe a
Just (Text
name, Text
iri)
readNSattr Attr
_ = Maybe (Text, Text)
forall a. Maybe a
Nothing
addNS :: (Text, Text)
-> XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
addNS (Text
prefix, Text
iri) XMLConverterState nsID extraState
state = ((NameSpaceIRIs nsID, nsID) -> XMLConverterState nsID extraState)
-> Maybe (NameSpaceIRIs nsID, nsID)
-> Maybe (XMLConverterState nsID extraState)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (NameSpaceIRIs nsID, nsID) -> XMLConverterState nsID extraState
updateState
(Maybe (NameSpaceIRIs nsID, nsID)
-> Maybe (XMLConverterState nsID extraState))
-> Maybe (NameSpaceIRIs nsID, nsID)
-> Maybe (XMLConverterState nsID extraState)
forall a b. (a -> b) -> a -> b
$ Text -> NameSpaceIRIs nsID -> Maybe (NameSpaceIRIs nsID, nsID)
forall nsID.
NameSpaceID nsID =>
Text -> NameSpaceIRIs nsID -> Maybe (NameSpaceIRIs nsID, nsID)
getNamespaceID Text
iri
(NameSpaceIRIs nsID -> Maybe (NameSpaceIRIs nsID, nsID))
-> NameSpaceIRIs nsID -> Maybe (NameSpaceIRIs nsID, nsID)
forall a b. (a -> b) -> a -> b
$ XMLConverterState nsID extraState -> NameSpaceIRIs nsID
forall nsID extraState.
XMLConverterState nsID extraState -> NameSpacePrefixes nsID
namespaceIRIs XMLConverterState nsID extraState
state
where updateState :: (NameSpaceIRIs nsID, nsID) -> XMLConverterState nsID extraState
updateState (NameSpaceIRIs nsID
iris,nsID
nsID)
= XMLConverterState nsID extraState
state { namespaceIRIs :: NameSpaceIRIs nsID
namespaceIRIs = NameSpaceIRIs nsID
iris
, namespacePrefixes :: NameSpaceIRIs nsID
namespacePrefixes = nsID -> Text -> NameSpaceIRIs nsID -> NameSpaceIRIs nsID
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert nsID
nsID Text
prefix
(NameSpaceIRIs nsID -> NameSpaceIRIs nsID)
-> NameSpaceIRIs nsID -> NameSpaceIRIs nsID
forall a b. (a -> b) -> a -> b
$ XMLConverterState nsID extraState -> NameSpaceIRIs nsID
forall nsID extraState.
XMLConverterState nsID extraState -> NameSpacePrefixes nsID
namespacePrefixes XMLConverterState nsID extraState
state
}
qualifyName :: (NameSpaceID nsID)
=> nsID -> ElementName
-> XMLConverter nsID extraState x XML.QName
qualifyName :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x QName
qualifyName nsID
nsID Text
name = nsID -> XMLConverter nsID extraState x (Maybe Text)
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> XMLConverter nsID extraState x (Maybe Text)
lookupNSiri nsID
nsID
XMLConverter nsID extraState x (Maybe Text)
-> XMLConverter nsID extraState x (Maybe Text)
-> ArrowState
(XMLConverterState nsID extraState) x (Maybe Text, Maybe Text)
forall b c c'.
ArrowState (XMLConverterState nsID extraState) b c
-> ArrowState (XMLConverterState nsID extraState) b c'
-> ArrowState (XMLConverterState nsID extraState) b (c, c')
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& nsID -> XMLConverter nsID extraState x (Maybe Text)
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> XMLConverter nsID extraState x (Maybe Text)
lookupNSprefix nsID
nsID
ArrowState
(XMLConverterState nsID extraState) x (Maybe Text, Maybe Text)
-> (Maybe Text -> Maybe Text -> QName)
-> ArrowState (XMLConverterState nsID extraState) x QName
forall (a :: * -> * -> *) x b c d.
Arrow a =>
a x (b, c) -> (b -> c -> d) -> a x d
>>% Text -> Maybe Text -> Maybe Text -> QName
XML.QName Text
name
elemNameMatches :: (NameSpaceID nsID)
=> nsID -> (ElementName -> Bool)
-> XMLConverter nsID extraState XML.Element Bool
elemNameMatches :: forall nsID extraState.
NameSpaceID nsID =>
nsID -> (Text -> Bool) -> XMLConverter nsID extraState Element Bool
elemNameMatches nsID
nsID Text -> Bool
f = ArrowState (XMLConverterState nsID extraState) Element (Maybe Text)
-> ArrowState
(XMLConverterState nsID extraState) Element (Element, Maybe Text)
forall (a :: * -> * -> *) b c. Arrow a => a b c -> a b (b, c)
keepingTheValue (nsID
-> ArrowState
(XMLConverterState nsID extraState) Element (Maybe Text)
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> XMLConverter nsID extraState x (Maybe Text)
lookupNSiri nsID
nsID) ArrowState
(XMLConverterState nsID extraState) Element (Element, Maybe Text)
-> (Element -> Maybe Text -> Bool)
-> ArrowState (XMLConverterState nsID extraState) Element Bool
forall (a :: * -> * -> *) x b c d.
Arrow a =>
a x (b, c) -> (b -> c -> d) -> a x d
>>% Element -> Maybe Text -> Bool
hasMatchingName
where hasMatchingName :: Element -> Maybe Text -> Bool
hasMatchingName Element
e Maybe Text
iri = let name :: QName
name = Element -> QName
XML.elName Element
e
in Text -> Bool
f (QName -> Text
XML.qName QName
name)
Bool -> Bool -> Bool
&& QName -> Maybe Text
XML.qURI QName
name Maybe Text -> Maybe Text -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe Text
iri
elemNameIs :: (NameSpaceID nsID)
=> nsID -> ElementName
-> XMLConverter nsID extraState XML.Element Bool
elemNameIs :: forall nsID extraState.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState Element Bool
elemNameIs nsID
nsID Text
name = nsID -> (Text -> Bool) -> XMLConverter nsID extraState Element Bool
forall nsID extraState.
NameSpaceID nsID =>
nsID -> (Text -> Bool) -> XMLConverter nsID extraState Element Bool
elemNameMatches nsID
nsID (Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
name)
elName :: XML.Element -> ElementName
elName :: Element -> Text
elName = QName -> Text
XML.qName (QName -> Text) -> (Element -> QName) -> Element -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Element -> QName
XML.elName
elContent :: XMLConverter nsID extraState x [XML.Content]
elContent :: forall nsID extraState x. XMLConverter nsID extraState x [Content]
elContent = XMLConverter nsID extraState x Element
forall nsID extraState x. XMLConverter nsID extraState x Element
getCurrentElement
XMLConverter nsID extraState x Element
-> (Element -> [Content])
-> ArrowState (XMLConverterState nsID extraState) x [Content]
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ Element -> [Content]
XML.elContent
findChildren :: (NameSpaceID nsID)
=> nsID -> ElementName
-> XMLConverter nsID extraState x [XML.Element]
findChildren :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x [Element]
findChildren nsID
nsID Text
name = nsID -> Text -> XMLConverter nsID extraState x QName
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x QName
qualifyName nsID
nsID Text
name
XMLConverter nsID extraState x QName
-> ArrowState (XMLConverterState nsID extraState) x Element
-> ArrowState
(XMLConverterState nsID extraState) x (QName, Element)
forall b c c'.
ArrowState (XMLConverterState nsID extraState) b c
-> ArrowState (XMLConverterState nsID extraState) b c'
-> ArrowState (XMLConverterState nsID extraState) b (c, c')
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& ArrowState (XMLConverterState nsID extraState) x Element
forall nsID extraState x. XMLConverter nsID extraState x Element
getCurrentElement
ArrowState (XMLConverterState nsID extraState) x (QName, Element)
-> (QName -> Element -> [Element])
-> ArrowState (XMLConverterState nsID extraState) x [Element]
forall (a :: * -> * -> *) x b c d.
Arrow a =>
a x (b, c) -> (b -> c -> d) -> a x d
>>% QName -> Element -> [Element]
XML.findChildren
findChild' :: (NameSpaceID nsID)
=> nsID
-> ElementName
-> XMLConverter nsID extraState x (Maybe XML.Element)
findChild' :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe Element)
findChild' nsID
nsID Text
name = nsID -> Text -> XMLConverter nsID extraState x QName
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x QName
qualifyName nsID
nsID Text
name
XMLConverter nsID extraState x QName
-> ArrowState (XMLConverterState nsID extraState) x Element
-> ArrowState
(XMLConverterState nsID extraState) x (QName, Element)
forall b c c'.
ArrowState (XMLConverterState nsID extraState) b c
-> ArrowState (XMLConverterState nsID extraState) b c'
-> ArrowState (XMLConverterState nsID extraState) b (c, c')
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& ArrowState (XMLConverterState nsID extraState) x Element
forall nsID extraState x. XMLConverter nsID extraState x Element
getCurrentElement
ArrowState (XMLConverterState nsID extraState) x (QName, Element)
-> (QName -> Element -> Maybe Element)
-> ArrowState (XMLConverterState nsID extraState) x (Maybe Element)
forall (a :: * -> * -> *) x b c d.
Arrow a =>
a x (b, c) -> (b -> c -> d) -> a x d
>>% QName -> Element -> Maybe Element
XML.findChild
findChild :: (NameSpaceID nsID)
=> nsID -> ElementName
-> FallibleXMLConverter nsID extraState x XML.Element
findChild :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> FallibleXMLConverter nsID extraState x Element
findChild nsID
nsID Text
name = nsID -> Text -> XMLConverter nsID extraState x (Maybe Element)
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe Element)
findChild' nsID
nsID Text
name
XMLConverter nsID extraState x (Maybe Element)
-> ArrowState
(XMLConverterState nsID extraState)
(Maybe Element)
(Fallible Element)
-> ArrowState
(XMLConverterState nsID extraState) x (Fallible Element)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ArrowState
(XMLConverterState nsID extraState)
(Maybe Element)
(Fallible Element)
forall (a :: * -> * -> *) b.
ArrowChoice a =>
a (Maybe b) (Fallible b)
maybeToChoice
filterChildrenName' :: (NameSpaceID nsID)
=> nsID
-> (ElementName -> Bool)
-> XMLConverter nsID extraState x [XML.Element]
filterChildrenName' :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> (Text -> Bool) -> XMLConverter nsID extraState x [Element]
filterChildrenName' nsID
nsID Text -> Bool
f = XMLConverter nsID extraState x Element
forall nsID extraState x. XMLConverter nsID extraState x Element
getCurrentElement
XMLConverter nsID extraState x Element
-> ArrowState (XMLConverterState nsID extraState) Element [Element]
-> ArrowState (XMLConverterState nsID extraState) x [Element]
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (Element -> [Element])
-> ArrowState (XMLConverterState nsID extraState) Element [Element]
forall b c.
(b -> c) -> ArrowState (XMLConverterState nsID extraState) b c
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr Element -> [Element]
XML.elChildren
ArrowState (XMLConverterState nsID extraState) Element [Element]
-> ArrowState
(XMLConverterState nsID extraState) [Element] [Element]
-> ArrowState (XMLConverterState nsID extraState) Element [Element]
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ArrowState
(XMLConverterState nsID extraState) Element (Element, Bool)
-> ArrowState
(XMLConverterState nsID extraState) [Element] [(Element, Bool)]
forall (f :: * -> *) (m :: * -> *) s x y.
(Foldable f, MonadPlus m) =>
ArrowState s x y -> ArrowState s (f x) (m y)
iterateS (ArrowState (XMLConverterState nsID extraState) Element Bool
-> ArrowState
(XMLConverterState nsID extraState) Element (Element, Bool)
forall (a :: * -> * -> *) b c. Arrow a => a b c -> a b (b, c)
keepingTheValue (nsID
-> (Text -> Bool)
-> ArrowState (XMLConverterState nsID extraState) Element Bool
forall nsID extraState.
NameSpaceID nsID =>
nsID -> (Text -> Bool) -> XMLConverter nsID extraState Element Bool
elemNameMatches nsID
nsID Text -> Bool
f))
ArrowState
(XMLConverterState nsID extraState) [Element] [(Element, Bool)]
-> ArrowState
(XMLConverterState nsID extraState) [(Element, Bool)] [Element]
-> ArrowState
(XMLConverterState nsID extraState) [Element] [Element]
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ([(Element, Bool)] -> [Element])
-> ArrowState
(XMLConverterState nsID extraState) [(Element, Bool)] [Element]
forall b c.
(b -> c) -> ArrowState (XMLConverterState nsID extraState) b c
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (((Element, Bool) -> Element) -> [(Element, Bool)] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map (Element, Bool) -> Element
forall a b. (a, b) -> a
fst ([(Element, Bool)] -> [Element])
-> ([(Element, Bool)] -> [(Element, Bool)])
-> [(Element, Bool)]
-> [Element]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Element, Bool) -> Bool) -> [(Element, Bool)] -> [(Element, Bool)]
forall a. (a -> Bool) -> [a] -> [a]
filter (Element, Bool) -> Bool
forall a b. (a, b) -> b
snd)
isSet' :: (NameSpaceID nsID)
=> nsID -> AttributeName
-> XMLConverter nsID extraState x (Maybe Bool)
isSet' :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe Bool)
isSet' nsID
nsID Text
attrName = nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
findAttr' nsID
nsID Text
attrName
XMLConverter nsID extraState x (Maybe Text)
-> (Maybe Text -> Maybe Bool)
-> ArrowState (XMLConverterState nsID extraState) x (Maybe Bool)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ (Maybe Text -> (Text -> Maybe Bool) -> Maybe Bool
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Maybe Bool
stringToBool')
isSetWithDefault :: (NameSpaceID nsID)
=> nsID -> AttributeName
-> Bool
-> XMLConverter nsID extraState x Bool
isSetWithDefault :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> Bool -> XMLConverter nsID extraState x Bool
isSetWithDefault nsID
nsID Text
attrName Bool
def'
= nsID -> Text -> XMLConverter nsID extraState x (Maybe Bool)
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe Bool)
isSet' nsID
nsID Text
attrName
XMLConverter nsID extraState x (Maybe Bool)
-> (Maybe Bool -> Bool)
-> ArrowState (XMLConverterState nsID extraState) x Bool
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ Bool -> Maybe Bool -> Bool
forall a. a -> Maybe a -> a
fromMaybe Bool
def'
searchAttrIn :: (NameSpaceID nsID)
=> nsID -> AttributeName
-> [(AttributeValue,a)]
-> FallibleXMLConverter nsID extraState x a
searchAttrIn :: forall nsID a extraState x.
NameSpaceID nsID =>
nsID
-> Text -> [(Text, a)] -> FallibleXMLConverter nsID extraState x a
searchAttrIn nsID
nsID Text
attrName [(Text, a)]
dict
= nsID -> Text -> FallibleXMLConverter nsID extraState x Text
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> FallibleXMLConverter nsID extraState x Text
findAttr nsID
nsID Text
attrName
FallibleXMLConverter nsID extraState x Text
-> (Text -> Either () a)
-> FallibleArrow
(ArrowState (XMLConverterState nsID extraState)) x () a
forall (a :: * -> * -> *) x failure success success'.
ArrowChoice a =>
FallibleArrow a x failure success
-> (success -> Either failure success')
-> FallibleArrow a x failure success'
>>?^? Maybe a -> Either () a
forall (a :: * -> * -> *) b.
ArrowChoice a =>
a (Maybe b) (Fallible b)
maybeToChoice(Maybe a -> Either () a)
-> (Text -> Maybe a) -> Text -> Either () a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Text -> [(Text, a)] -> Maybe a
forall a b. Eq a => a -> [(a, b)] -> Maybe b
`lookup` [(Text, a)]
dict )
searchAttr :: (NameSpaceID nsID)
=> nsID -> AttributeName
-> a
-> [(AttributeValue,a)]
-> XMLConverter nsID extraState x a
searchAttr :: forall nsID a extraState x.
NameSpaceID nsID =>
nsID
-> Text -> a -> [(Text, a)] -> XMLConverter nsID extraState x a
searchAttr nsID
nsID Text
attrName a
defV [(Text, a)]
dict
= nsID
-> Text -> [(Text, a)] -> FallibleXMLConverter nsID extraState x a
forall nsID a extraState x.
NameSpaceID nsID =>
nsID
-> Text -> [(Text, a)] -> FallibleXMLConverter nsID extraState x a
searchAttrIn nsID
nsID Text
attrName [(Text, a)]
dict
FallibleXMLConverter nsID extraState x a
-> ArrowState (XMLConverterState nsID extraState) (Fallible a) a
-> ArrowState (XMLConverterState nsID extraState) x a
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> a -> () -> a
forall a b. a -> b -> a
const a
defV (() -> a)
-> (a -> a)
-> ArrowState (XMLConverterState nsID extraState) (Fallible a) a
forall (a :: * -> * -> *) b d c.
ArrowChoice a =>
(b -> d) -> (c -> d) -> a (Either b c) d
^|||^ a -> a
forall a. a -> a
id
lookupAttr :: (NameSpaceID nsID, Lookupable a)
=> nsID -> AttributeName
-> FallibleXMLConverter nsID extraState x a
lookupAttr :: forall nsID a extraState x.
(NameSpaceID nsID, Lookupable a) =>
nsID -> Text -> FallibleXMLConverter nsID extraState x a
lookupAttr nsID
nsID Text
attrName = nsID -> Text -> XMLConverter nsID extraState x (Maybe a)
forall nsID a extraState x.
(NameSpaceID nsID, Lookupable a) =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe a)
lookupAttr' nsID
nsID Text
attrName
XMLConverter nsID extraState x (Maybe a)
-> (Maybe a -> Fallible a)
-> ArrowState (XMLConverterState nsID extraState) x (Fallible a)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ Maybe a -> Fallible a
forall (a :: * -> * -> *) b.
ArrowChoice a =>
a (Maybe b) (Fallible b)
maybeToChoice
lookupAttr' :: (NameSpaceID nsID, Lookupable a)
=> nsID -> AttributeName
-> XMLConverter nsID extraState x (Maybe a)
lookupAttr' :: forall nsID a extraState x.
(NameSpaceID nsID, Lookupable a) =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe a)
lookupAttr' nsID
nsID Text
attrName
= nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
findAttr' nsID
nsID Text
attrName
XMLConverter nsID extraState x (Maybe Text)
-> (Maybe Text -> Maybe a)
-> ArrowState (XMLConverterState nsID extraState) x (Maybe a)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ (Maybe Text -> (Text -> Maybe a) -> Maybe a
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Maybe a
forall a. Lookupable a => Text -> Maybe a
readLookupable)
lookupAttrWithDefault :: (NameSpaceID nsID, Lookupable a)
=> nsID -> AttributeName
-> a
-> XMLConverter nsID extraState x a
lookupAttrWithDefault :: forall nsID a extraState x.
(NameSpaceID nsID, Lookupable a) =>
nsID -> Text -> a -> XMLConverter nsID extraState x a
lookupAttrWithDefault nsID
nsID Text
attrName a
deflt
= nsID -> Text -> XMLConverter nsID extraState x (Maybe a)
forall nsID a extraState x.
(NameSpaceID nsID, Lookupable a) =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe a)
lookupAttr' nsID
nsID Text
attrName
XMLConverter nsID extraState x (Maybe a)
-> (Maybe a -> a)
-> ArrowState (XMLConverterState nsID extraState) x a
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe a
deflt
lookupDefaultingAttr :: (NameSpaceID nsID, Lookupable a, Default a)
=> nsID -> AttributeName
-> XMLConverter nsID extraState x a
lookupDefaultingAttr :: forall nsID a extraState x.
(NameSpaceID nsID, Lookupable a, Default a) =>
nsID -> Text -> XMLConverter nsID extraState x a
lookupDefaultingAttr nsID
nsID Text
attrName
= nsID -> Text -> a -> XMLConverter nsID extraState x a
forall nsID a extraState x.
(NameSpaceID nsID, Lookupable a) =>
nsID -> Text -> a -> XMLConverter nsID extraState x a
lookupAttrWithDefault nsID
nsID Text
attrName a
forall a. Default a => a
def
findAttr' :: (NameSpaceID nsID)
=> nsID -> AttributeName
-> XMLConverter nsID extraState x (Maybe AttributeValue)
findAttr' :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
findAttr' nsID
nsID Text
attrName = nsID -> Text -> XMLConverter nsID extraState x QName
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x QName
qualifyName nsID
nsID Text
attrName
XMLConverter nsID extraState x QName
-> ArrowState (XMLConverterState nsID extraState) x Element
-> ArrowState
(XMLConverterState nsID extraState) x (QName, Element)
forall b c c'.
ArrowState (XMLConverterState nsID extraState) b c
-> ArrowState (XMLConverterState nsID extraState) b c'
-> ArrowState (XMLConverterState nsID extraState) b (c, c')
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& ArrowState (XMLConverterState nsID extraState) x Element
forall nsID extraState x. XMLConverter nsID extraState x Element
getCurrentElement
ArrowState (XMLConverterState nsID extraState) x (QName, Element)
-> (QName -> Element -> Maybe Text)
-> ArrowState (XMLConverterState nsID extraState) x (Maybe Text)
forall (a :: * -> * -> *) x b c d.
Arrow a =>
a x (b, c) -> (b -> c -> d) -> a x d
>>% QName -> Element -> Maybe Text
XML.findAttr
findAttrText' :: (NameSpaceID nsID)
=> nsID -> AttributeName
-> XMLConverter nsID extraState x (Maybe TextAttributeValue)
findAttrText' :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
findAttrText' nsID
nsID Text
attrName
= nsID -> Text -> XMLConverter nsID extraState x QName
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x QName
qualifyName nsID
nsID Text
attrName
XMLConverter nsID extraState x QName
-> ArrowState (XMLConverterState nsID extraState) x Element
-> ArrowState
(XMLConverterState nsID extraState) x (QName, Element)
forall b c c'.
ArrowState (XMLConverterState nsID extraState) b c
-> ArrowState (XMLConverterState nsID extraState) b c'
-> ArrowState (XMLConverterState nsID extraState) b (c, c')
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& ArrowState (XMLConverterState nsID extraState) x Element
forall nsID extraState x. XMLConverter nsID extraState x Element
getCurrentElement
ArrowState (XMLConverterState nsID extraState) x (QName, Element)
-> (QName -> Element -> Maybe Text)
-> ArrowState (XMLConverterState nsID extraState) x (Maybe Text)
forall (a :: * -> * -> *) x b c d.
Arrow a =>
a x (b, c) -> (b -> c -> d) -> a x d
>>% QName -> Element -> Maybe Text
XML.findAttr
findAttr :: (NameSpaceID nsID)
=> nsID -> AttributeName
-> FallibleXMLConverter nsID extraState x AttributeValue
findAttr :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> FallibleXMLConverter nsID extraState x Text
findAttr nsID
nsID Text
attrName = nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
findAttr' nsID
nsID Text
attrName
XMLConverter nsID extraState x (Maybe Text)
-> ArrowState
(XMLConverterState nsID extraState) (Maybe Text) (Fallible Text)
-> ArrowState (XMLConverterState nsID extraState) x (Fallible Text)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ArrowState
(XMLConverterState nsID extraState) (Maybe Text) (Fallible Text)
forall (a :: * -> * -> *) b.
ArrowChoice a =>
a (Maybe b) (Fallible b)
maybeToChoice
findAttrText :: (NameSpaceID nsID)
=> nsID -> AttributeName
-> FallibleXMLConverter nsID extraState x TextAttributeValue
findAttrText :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> FallibleXMLConverter nsID extraState x Text
findAttrText nsID
nsID Text
attrName
= nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
findAttr' nsID
nsID Text
attrName
XMLConverter nsID extraState x (Maybe Text)
-> ArrowState
(XMLConverterState nsID extraState) (Maybe Text) (Fallible Text)
-> ArrowState (XMLConverterState nsID extraState) x (Fallible Text)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ArrowState
(XMLConverterState nsID extraState) (Maybe Text) (Fallible Text)
forall (a :: * -> * -> *) b.
ArrowChoice a =>
a (Maybe b) (Fallible b)
maybeToChoice
findAttrTextWithDefault :: (NameSpaceID nsID)
=> nsID -> AttributeName
-> TextAttributeValue
-> XMLConverter nsID extraState x TextAttributeValue
findAttrTextWithDefault :: forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> Text -> XMLConverter nsID extraState x Text
findAttrTextWithDefault nsID
nsID Text
attrName Text
deflt
= nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
findAttr' nsID
nsID Text
attrName
XMLConverter nsID extraState x (Maybe Text)
-> (Maybe Text -> Text)
-> ArrowState (XMLConverterState nsID extraState) x Text
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
deflt
readAttr :: (NameSpaceID nsID, Read attrValue)
=> nsID -> AttributeName
-> FallibleXMLConverter nsID extraState x attrValue
readAttr :: forall nsID attrValue extraState x.
(NameSpaceID nsID, Read attrValue) =>
nsID -> Text -> FallibleXMLConverter nsID extraState x attrValue
readAttr nsID
nsID Text
attrName = nsID -> Text -> XMLConverter nsID extraState x (Maybe attrValue)
forall nsID attrValue extraState x.
(NameSpaceID nsID, Read attrValue) =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe attrValue)
readAttr' nsID
nsID Text
attrName
XMLConverter nsID extraState x (Maybe attrValue)
-> ArrowState
(XMLConverterState nsID extraState)
(Maybe attrValue)
(Fallible attrValue)
-> ArrowState
(XMLConverterState nsID extraState) x (Fallible attrValue)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ArrowState
(XMLConverterState nsID extraState)
(Maybe attrValue)
(Fallible attrValue)
forall (a :: * -> * -> *) b.
ArrowChoice a =>
a (Maybe b) (Fallible b)
maybeToChoice
readAttr' :: (NameSpaceID nsID, Read attrValue)
=> nsID -> AttributeName
-> XMLConverter nsID extraState x (Maybe attrValue)
readAttr' :: forall nsID attrValue extraState x.
(NameSpaceID nsID, Read attrValue) =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe attrValue)
readAttr' nsID
nsID Text
attrName = nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
findAttr' nsID
nsID Text
attrName
XMLConverter nsID extraState x (Maybe Text)
-> (Maybe Text -> Maybe attrValue)
-> ArrowState
(XMLConverterState nsID extraState) x (Maybe attrValue)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ (Maybe Text -> (Text -> Maybe attrValue) -> Maybe attrValue
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Maybe attrValue
forall r. Read r => Text -> Maybe r
tryToRead)
readAttrWithDefault :: (NameSpaceID nsID, Read attrValue)
=> nsID -> AttributeName
-> attrValue
-> XMLConverter nsID extraState x attrValue
readAttrWithDefault :: forall nsID attrValue extraState x.
(NameSpaceID nsID, Read attrValue) =>
nsID
-> Text -> attrValue -> XMLConverter nsID extraState x attrValue
readAttrWithDefault nsID
nsID Text
attrName attrValue
deflt
= nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x (Maybe Text)
findAttr' nsID
nsID Text
attrName
XMLConverter nsID extraState x (Maybe Text)
-> (Maybe Text -> attrValue)
-> ArrowState (XMLConverterState nsID extraState) x attrValue
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ (Maybe Text -> (Text -> Maybe attrValue) -> Maybe attrValue
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Maybe attrValue
forall r. Read r => Text -> Maybe r
tryToRead)
(Maybe Text -> Maybe attrValue)
-> (Maybe attrValue -> attrValue) -> Maybe Text -> attrValue
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ attrValue -> Maybe attrValue -> attrValue
forall a. a -> Maybe a -> a
fromMaybe attrValue
deflt
getAttr :: (NameSpaceID nsID, Read attrValue, Default attrValue)
=> nsID -> AttributeName
-> XMLConverter nsID extraState x attrValue
getAttr :: forall nsID attrValue extraState x.
(NameSpaceID nsID, Read attrValue, Default attrValue) =>
nsID -> Text -> XMLConverter nsID extraState x attrValue
getAttr nsID
nsID Text
attrName = nsID
-> Text -> attrValue -> XMLConverter nsID extraState x attrValue
forall nsID attrValue extraState x.
(NameSpaceID nsID, Read attrValue) =>
nsID
-> Text -> attrValue -> XMLConverter nsID extraState x attrValue
readAttrWithDefault nsID
nsID Text
attrName attrValue
forall a. Default a => a
def
jumpThere :: XMLConverter nsID extraState XML.Element XML.Element
jumpThere :: forall nsID extraState.
XMLConverter nsID extraState Element Element
jumpThere = (XMLConverterState nsID extraState
-> Element -> (XMLConverterState nsID extraState, Element))
-> ArrowState (XMLConverterState nsID extraState) Element Element
forall state a b.
(state -> a -> (state, b)) -> ArrowState state a b
withState (\XMLConverterState nsID extraState
state Element
element
-> ( Element
-> XMLConverterState nsID extraState
-> XMLConverterState nsID extraState
forall nsID extraState.
Element
-> XMLConverterState nsID extraState
-> XMLConverterState nsID extraState
pushElement Element
element XMLConverterState nsID extraState
state , Element
element )
)
swapStack :: XMLConverter nsID extraState [XML.Element] [XML.Element]
swapStack :: forall nsID extraState.
XMLConverter nsID extraState [Element] [Element]
swapStack = (XMLConverterState nsID extraState
-> [Element] -> (XMLConverterState nsID extraState, [Element]))
-> ArrowState
(XMLConverterState nsID extraState) [Element] [Element]
forall state a b.
(state -> a -> (state, b)) -> ArrowState state a b
withState XMLConverterState nsID extraState
-> [Element] -> (XMLConverterState nsID extraState, [Element])
forall nsID extraState.
XMLConverterState nsID extraState
-> [Element] -> (XMLConverterState nsID extraState, [Element])
swapStack'
jumpBack :: FallibleXMLConverter nsID extraState _x _x
jumpBack :: forall nsID extraState _x.
FallibleXMLConverter nsID extraState _x _x
jumpBack = (XMLConverterState nsID extraState
-> Either () (XMLConverterState nsID extraState))
-> ArrowState (XMLConverterState nsID extraState) _x (Either () _x)
forall state f a.
(state -> Either f state) -> ArrowState state a (Either f a)
tryModifyState (XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
forall nsID extraState.
XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState)
popElement (XMLConverterState nsID extraState
-> Maybe (XMLConverterState nsID extraState))
-> (Maybe (XMLConverterState nsID extraState)
-> Either () (XMLConverterState nsID extraState))
-> XMLConverterState nsID extraState
-> Either () (XMLConverterState nsID extraState)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Maybe (XMLConverterState nsID extraState)
-> Either () (XMLConverterState nsID extraState)
forall (a :: * -> * -> *) b.
ArrowChoice a =>
a (Maybe b) (Fallible b)
maybeToChoice)
switchingTheStack :: XMLConverter nsID moreState a b
-> XMLConverter nsID moreState (a, XML.Element) b
switchingTheStack :: forall nsID moreState a b.
XMLConverter nsID moreState a b
-> XMLConverter nsID moreState (a, Element) b
switchingTheStack XMLConverter nsID moreState a b
a = ArrowState (XMLConverterState nsID moreState) Element [Element]
-> ArrowState
(XMLConverterState nsID moreState) (a, Element) (a, [Element])
forall b c d.
ArrowState (XMLConverterState nsID moreState) b c
-> ArrowState (XMLConverterState nsID moreState) (d, b) (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ( (Element -> [Element] -> [Element]
forall a. a -> [a] -> [a]
:[]) (Element -> [Element])
-> ArrowState
(XMLConverterState nsID moreState) [Element] [Element]
-> ArrowState (XMLConverterState nsID moreState) Element [Element]
forall (a :: * -> * -> *) b c d.
Arrow a =>
(b -> c) -> a c d -> a b d
^>> ArrowState (XMLConverterState nsID moreState) [Element] [Element]
forall nsID extraState.
XMLConverter nsID extraState [Element] [Element]
swapStack )
ArrowState
(XMLConverterState nsID moreState) (a, Element) (a, [Element])
-> ArrowState (XMLConverterState nsID moreState) (a, [Element]) b
-> ArrowState (XMLConverterState nsID moreState) (a, Element) b
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> XMLConverter nsID moreState a b
-> ArrowState
(XMLConverterState nsID moreState) (a, [Element]) (b, [Element])
forall b c d.
ArrowState (XMLConverterState nsID moreState) b c
-> ArrowState (XMLConverterState nsID moreState) (b, d) (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first XMLConverter nsID moreState a b
a
ArrowState
(XMLConverterState nsID moreState) (a, [Element]) (b, [Element])
-> ArrowState (XMLConverterState nsID moreState) (b, [Element]) b
-> ArrowState (XMLConverterState nsID moreState) (a, [Element]) b
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ArrowState (XMLConverterState nsID moreState) [Element] [Element]
-> ArrowState
(XMLConverterState nsID moreState) (b, [Element]) (b, [Element])
forall b c d.
ArrowState (XMLConverterState nsID moreState) b c
-> ArrowState (XMLConverterState nsID moreState) (d, b) (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ArrowState (XMLConverterState nsID moreState) [Element] [Element]
forall nsID extraState.
XMLConverter nsID extraState [Element] [Element]
swapStack
ArrowState
(XMLConverterState nsID moreState) (b, [Element]) (b, [Element])
-> ((b, [Element]) -> b)
-> ArrowState (XMLConverterState nsID moreState) (b, [Element]) b
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ (b, [Element]) -> b
forall a b. (a, b) -> a
fst
executeThere :: FallibleXMLConverter nsID moreState a b
-> FallibleXMLConverter nsID moreState (a, XML.Element) b
executeThere :: forall nsID moreState a b.
FallibleXMLConverter nsID moreState a b
-> FallibleXMLConverter nsID moreState (a, Element) b
executeThere FallibleXMLConverter nsID moreState a b
a = ArrowState (XMLConverterState nsID moreState) Element Element
-> ArrowState
(XMLConverterState nsID moreState) (a, Element) (a, Element)
forall b c d.
ArrowState (XMLConverterState nsID moreState) b c
-> ArrowState (XMLConverterState nsID moreState) (d, b) (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ArrowState (XMLConverterState nsID moreState) Element Element
forall nsID extraState.
XMLConverter nsID extraState Element Element
jumpThere
ArrowState
(XMLConverterState nsID moreState) (a, Element) (a, Element)
-> ArrowState
(XMLConverterState nsID moreState) (a, Element) (Fallible b)
-> ArrowState
(XMLConverterState nsID moreState) (a, Element) (Fallible b)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (a, Element) -> a
forall a b. (a, b) -> a
fst
((a, Element) -> a)
-> FallibleXMLConverter nsID moreState a b
-> ArrowState
(XMLConverterState nsID moreState) (a, Element) (Fallible b)
forall (a :: * -> * -> *) b c d.
Arrow a =>
(b -> c) -> a c d -> a b d
^>> FallibleXMLConverter nsID moreState a b
a
FallibleXMLConverter nsID moreState a b
-> ArrowState
(XMLConverterState nsID moreState) (Fallible b) (Fallible b)
-> FallibleXMLConverter nsID moreState a b
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> FallibleXMLConverter nsID moreState (Fallible b) (Fallible b)
forall nsID extraState _x.
FallibleXMLConverter nsID extraState _x _x
jumpBack
FallibleXMLConverter nsID moreState (Fallible b) (Fallible b)
-> (Fallible (Fallible b) -> Fallible b)
-> ArrowState
(XMLConverterState nsID moreState) (Fallible b) (Fallible b)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ Fallible (Fallible b) -> Fallible b
forall failure x.
Either failure (Either failure x) -> Either failure x
collapseEither
executeIn :: XMLConverter nsID extraState XML.Element s
-> XMLConverter nsID extraState XML.Element s
executeIn :: forall nsID extraState s.
XMLConverter nsID extraState Element s
-> XMLConverter nsID extraState Element s
executeIn XMLConverter nsID extraState Element s
a = ArrowState
(XMLConverterState nsID extraState) Element (Element, Element)
forall (a :: * -> * -> *) b. Arrow a => a b (b, b)
duplicate ArrowState
(XMLConverterState nsID extraState) Element (Element, Element)
-> ArrowState
(XMLConverterState nsID extraState) (Element, Element) s
-> XMLConverter nsID extraState Element s
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> XMLConverter nsID extraState Element s
-> ArrowState
(XMLConverterState nsID extraState) (Element, Element) s
forall nsID moreState a b.
XMLConverter nsID moreState a b
-> XMLConverter nsID moreState (a, Element) b
switchingTheStack XMLConverter nsID extraState Element s
a
executeInSub :: (NameSpaceID nsID)
=> nsID -> ElementName
-> FallibleXMLConverter nsID extraState f s
-> FallibleXMLConverter nsID extraState f s
executeInSub :: forall nsID extraState f s.
NameSpaceID nsID =>
nsID
-> Text
-> FallibleXMLConverter nsID extraState f s
-> FallibleXMLConverter nsID extraState f s
executeInSub nsID
nsID Text
name FallibleXMLConverter nsID extraState f s
a = ArrowState (XMLConverterState nsID extraState) f (Fallible Element)
-> ArrowState
(XMLConverterState nsID extraState) f (f, Fallible Element)
forall (a :: * -> * -> *) b c. Arrow a => a b c -> a b (b, c)
keepingTheValue
(nsID
-> Text
-> ArrowState
(XMLConverterState nsID extraState) f (Fallible Element)
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> FallibleXMLConverter nsID extraState x Element
findChild nsID
nsID Text
name)
ArrowState
(XMLConverterState nsID extraState) f (f, Fallible Element)
-> ArrowState
(XMLConverterState nsID extraState)
(f, Fallible Element)
(Fallible s)
-> FallibleXMLConverter nsID extraState f s
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ((f, Fallible Element) -> Either () (f, Element))
-> ArrowState
(XMLConverterState nsID extraState)
(f, Fallible Element)
(Either () (f, Element))
forall a b state. (a -> b) -> ArrowState state a b
ignoringState (f, Fallible Element) -> Either () (f, Element)
forall {a} {a} {b}. (a, Either a b) -> Either a (a, b)
liftFailure
ArrowState
(XMLConverterState nsID extraState)
(f, Fallible Element)
(Either () (f, Element))
-> FallibleArrow
(ArrowState (XMLConverterState nsID extraState)) (f, Element) () s
-> ArrowState
(XMLConverterState nsID extraState)
(f, Fallible Element)
(Fallible s)
forall (a :: * -> * -> *) x failure success success'.
ArrowChoice a =>
FallibleArrow a x failure success
-> FallibleArrow a success failure success'
-> FallibleArrow a x failure success'
>>? FallibleXMLConverter nsID extraState f s
-> FallibleArrow
(ArrowState (XMLConverterState nsID extraState)) (f, Element) () s
forall nsID moreState a b.
XMLConverter nsID moreState a b
-> XMLConverter nsID moreState (a, Element) b
switchingTheStack FallibleXMLConverter nsID extraState f s
a
where liftFailure :: (a, Either a b) -> Either a (a, b)
liftFailure (a
_, Left a
f) = a -> Either a (a, b)
forall a b. a -> Either a b
Left a
f
liftFailure (a
x, Right b
e) = (a, b) -> Either a (a, b)
forall a b. b -> Either a b
Right (a
x, b
e)
prepareIteration :: (NameSpaceID nsID)
=> nsID -> ElementName
-> XMLConverter nsID extraState b [(b, XML.Element)]
prepareIteration :: forall nsID extraState b.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState b [(b, Element)]
prepareIteration nsID
nsID Text
name = ArrowState (XMLConverterState nsID extraState) b [Element]
-> ArrowState (XMLConverterState nsID extraState) b (b, [Element])
forall (a :: * -> * -> *) b c. Arrow a => a b c -> a b (b, c)
keepingTheValue
(nsID
-> Text
-> ArrowState (XMLConverterState nsID extraState) b [Element]
forall nsID extraState x.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState x [Element]
findChildren nsID
nsID Text
name)
ArrowState (XMLConverterState nsID extraState) b (b, [Element])
-> (b -> [Element] -> [(b, Element)])
-> ArrowState (XMLConverterState nsID extraState) b [(b, Element)]
forall (a :: * -> * -> *) x b c d.
Arrow a =>
a x (b, c) -> (b -> c -> d) -> a x d
>>% b -> [Element] -> [(b, Element)]
forall a b. a -> [b] -> [(a, b)]
distributeValue
withEveryL :: (NameSpaceID nsID)
=> nsID -> ElementName
-> FallibleXMLConverter nsID extraState a b
-> FallibleXMLConverter nsID extraState a [b]
withEveryL :: forall nsID extraState a b.
NameSpaceID nsID =>
nsID
-> Text
-> FallibleXMLConverter nsID extraState a b
-> FallibleXMLConverter nsID extraState a [b]
withEveryL = nsID
-> Text
-> FallibleXMLConverter nsID extraState a b
-> FallibleXMLConverter nsID extraState a [b]
forall nsID (m :: * -> *) extraState a b.
(NameSpaceID nsID, MonadPlus m) =>
nsID
-> Text
-> FallibleXMLConverter nsID extraState a b
-> FallibleXMLConverter nsID extraState a (m b)
withEvery
withEvery :: (NameSpaceID nsID, MonadPlus m)
=> nsID -> ElementName
-> FallibleXMLConverter nsID extraState a b
-> FallibleXMLConverter nsID extraState a (m b)
withEvery :: forall nsID (m :: * -> *) extraState a b.
(NameSpaceID nsID, MonadPlus m) =>
nsID
-> Text
-> FallibleXMLConverter nsID extraState a b
-> FallibleXMLConverter nsID extraState a (m b)
withEvery nsID
nsID Text
name FallibleXMLConverter nsID extraState a b
a = nsID -> Text -> XMLConverter nsID extraState a [(a, Element)]
forall nsID extraState b.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState b [(b, Element)]
prepareIteration nsID
nsID Text
name
XMLConverter nsID extraState a [(a, Element)]
-> ArrowState
(XMLConverterState nsID extraState) [(a, Element)] (Fallible (m b))
-> ArrowState
(XMLConverterState nsID extraState) a (Fallible (m b))
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ArrowState
(XMLConverterState nsID extraState) (a, Element) (Either () b)
-> ArrowState
(XMLConverterState nsID extraState) [(a, Element)] (Fallible (m b))
forall (f :: * -> *) (m :: * -> *) s x e y.
(Foldable f, MonadPlus m) =>
ArrowState s x (Either e y) -> ArrowState s (f x) (Either e (m y))
iterateS' (FallibleXMLConverter nsID extraState a b
-> ArrowState
(XMLConverterState nsID extraState) (a, Element) (Either () b)
forall nsID moreState a b.
XMLConverter nsID moreState a b
-> XMLConverter nsID moreState (a, Element) b
switchingTheStack FallibleXMLConverter nsID extraState a b
a)
tryAll :: (NameSpaceID nsID)
=> nsID -> ElementName
-> FallibleXMLConverter nsID extraState b a
-> XMLConverter nsID extraState b [a]
tryAll :: forall nsID extraState b a.
NameSpaceID nsID =>
nsID
-> Text
-> FallibleXMLConverter nsID extraState b a
-> XMLConverter nsID extraState b [a]
tryAll nsID
nsID Text
name FallibleXMLConverter nsID extraState b a
a = nsID -> Text -> XMLConverter nsID extraState b [(b, Element)]
forall nsID extraState b.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState b [(b, Element)]
prepareIteration nsID
nsID Text
name
XMLConverter nsID extraState b [(b, Element)]
-> ArrowState
(XMLConverterState nsID extraState) [(b, Element)] [a]
-> ArrowState (XMLConverterState nsID extraState) b [a]
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ArrowState
(XMLConverterState nsID extraState) (b, Element) (Fallible a)
-> ArrowState
(XMLConverterState nsID extraState) [(b, Element)] [Fallible a]
forall (f :: * -> *) (m :: * -> *) s x y.
(Foldable f, MonadPlus m) =>
ArrowState s x y -> ArrowState s (f x) (m y)
iterateS (FallibleXMLConverter nsID extraState b a
-> ArrowState
(XMLConverterState nsID extraState) (b, Element) (Fallible a)
forall nsID moreState a b.
XMLConverter nsID moreState a b
-> XMLConverter nsID moreState (a, Element) b
switchingTheStack FallibleXMLConverter nsID extraState b a
a)
ArrowState
(XMLConverterState nsID extraState) [(b, Element)] [Fallible a]
-> ([Fallible a] -> [a])
-> ArrowState
(XMLConverterState nsID extraState) [(b, Element)] [a]
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ [Fallible a] -> [a]
forall a b. [Either a b] -> [b]
rights
type IdXMLConverter nsID moreState x
= XMLConverter nsID moreState x x
type MaybeCConverter nsID moreState x
= Maybe (IdXMLConverter nsID moreState (x, XML.Content))
type ContentMatchConverter nsID extraState x
= IdXMLConverter nsID
extraState
(MaybeCConverter nsID extraState x, XML.Content)
makeMatcherC :: (NameSpaceID nsID)
=> nsID -> ElementName
-> FallibleXMLConverter nsID extraState a a
-> ContentMatchConverter nsID extraState a
makeMatcherC :: forall nsID extraState a.
NameSpaceID nsID =>
nsID
-> Text
-> FallibleXMLConverter nsID extraState a a
-> ContentMatchConverter nsID extraState a
makeMatcherC nsID
nsID Text
name FallibleXMLConverter nsID extraState a a
c = ( ArrowState
(XMLConverterState nsID extraState)
Content
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
-> ArrowState
(XMLConverterState nsID extraState)
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)),
Content)
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)),
Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
forall b c d.
ArrowState (XMLConverterState nsID extraState) b c
-> ArrowState (XMLConverterState nsID extraState) (d, b) (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ( FallibleXMLConverter nsID extraState Content Element
forall nsID extraState.
FallibleXMLConverter nsID extraState Content Element
contentToElem
FallibleXMLConverter nsID extraState Content Element
-> ArrowState
(XMLConverterState nsID extraState)
(Fallible Element)
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
-> ArrowState
(XMLConverterState nsID extraState)
Content
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content))
-> ArrowState
(XMLConverterState nsID extraState)
()
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
forall (a :: * -> * -> *) c x. Arrow a => c -> a x c
returnV Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content))
forall a. Maybe a
Nothing
ArrowState
(XMLConverterState nsID extraState)
()
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
-> ArrowState
(XMLConverterState nsID extraState)
Element
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
-> ArrowState
(XMLConverterState nsID extraState)
(Fallible Element)
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
forall b d c.
ArrowState (XMLConverterState nsID extraState) b d
-> ArrowState (XMLConverterState nsID extraState) c d
-> ArrowState (XMLConverterState nsID extraState) (Either b c) d
forall (a :: * -> * -> *) b d c.
ArrowChoice a =>
a b d -> a c d -> a (Either b c) d
||| ( nsID -> Text -> XMLConverter nsID extraState Element Bool
forall nsID extraState.
NameSpaceID nsID =>
nsID -> Text -> XMLConverter nsID extraState Element Bool
elemNameIs nsID
nsID Text
name
XMLConverter nsID extraState Element Bool
-> (Bool
-> Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
-> ArrowState
(XMLConverterState nsID extraState)
Element
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content))
-> Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content))
-> Bool
-> Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content))
forall a. a -> a -> Bool -> a
bool Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content))
forall a. Maybe a
Nothing (ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)
-> Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content))
forall a. a -> Maybe a
Just ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)
cWithJump)
)
)
ArrowState
(XMLConverterState nsID extraState)
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)),
Content)
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)),
Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
-> (Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content))
-> Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content))
-> Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
-> ArrowState
(XMLConverterState nsID extraState)
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)),
Content)
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
forall (a :: * -> * -> *) x b c d.
Arrow a =>
a x (b, c) -> (b -> c -> d) -> a x d
>>% Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content))
-> Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content))
-> Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content))
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>)
) ArrowState
(XMLConverterState nsID extraState)
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)),
Content)
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)))
-> ((Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)),
Content)
-> Content)
-> ArrowState
(XMLConverterState nsID extraState)
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)),
Content)
(Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)),
Content)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> (b -> c') -> a b (c, c')
&&&^ (Maybe
(ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)),
Content)
-> Content
forall a b. (a, b) -> b
snd
where cWithJump :: ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)
cWithJump = ( (a, Content) -> a
forall a b. (a, b) -> a
fst
((a, Content) -> a)
-> ArrowState
(XMLConverterState nsID extraState) (a, Content) (Either () a)
-> ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Either () a)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
(b -> c) -> a b c' -> a b (c, c')
^&&& ( FallibleXMLConverter nsID extraState Content Element
-> ArrowState
(XMLConverterState nsID extraState)
(a, Content)
(a, Fallible Element)
forall b c d.
ArrowState (XMLConverterState nsID extraState) b c
-> ArrowState (XMLConverterState nsID extraState) (d, b) (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second FallibleXMLConverter nsID extraState Content Element
forall nsID extraState.
FallibleXMLConverter nsID extraState Content Element
contentToElem
ArrowState
(XMLConverterState nsID extraState)
(a, Content)
(a, Fallible Element)
-> ArrowState
(XMLConverterState nsID extraState)
(a, Fallible Element)
(Either () a)
-> ArrowState
(XMLConverterState nsID extraState) (a, Content) (Either () a)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (a, Fallible Element) -> Either () (a, Element)
forall f a. (a, Either f a) -> Either f (a, a)
forall (v :: * -> *) f a.
ChoiceVector v =>
v (Either f a) -> Either f (v a)
spreadChoice
((a, Fallible Element) -> Either () (a, Element))
-> FallibleArrow
(ArrowState (XMLConverterState nsID extraState)) (a, Element) () a
-> ArrowState
(XMLConverterState nsID extraState)
(a, Fallible Element)
(Either () a)
forall (a :: * -> * -> *) x failure success success'.
ArrowChoice a =>
(x -> Either failure success)
-> FallibleArrow a success failure success'
-> FallibleArrow a x failure success'
^>>? FallibleXMLConverter nsID extraState a a
-> FallibleArrow
(ArrowState (XMLConverterState nsID extraState)) (a, Element) () a
forall nsID moreState a b.
FallibleXMLConverter nsID moreState a b
-> FallibleXMLConverter nsID moreState (a, Element) b
executeThere FallibleXMLConverter nsID extraState a a
c
)
ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Either () a)
-> (a -> Either () a -> a)
-> ArrowState (XMLConverterState nsID extraState) (a, Content) a
forall (a :: * -> * -> *) x b c d.
Arrow a =>
a x (b, c) -> (b -> c -> d) -> a x d
>>% a -> Either () a -> a
forall a _f. a -> Either _f a -> a
recover)
ArrowState (XMLConverterState nsID extraState) (a, Content) a
-> ((a, Content) -> Content)
-> ArrowState
(XMLConverterState nsID extraState) (a, Content) (a, Content)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> (b -> c') -> a b (c, c')
&&&^ (a, Content) -> Content
forall a b. (a, b) -> b
snd
contentToElem :: FallibleXMLConverter nsID extraState XML.Content XML.Element
contentToElem :: forall nsID extraState.
FallibleXMLConverter nsID extraState Content Element
contentToElem = (Content -> Fallible Element)
-> ArrowState
(XMLConverterState nsID extraState) Content (Fallible Element)
forall b c.
(b -> c) -> ArrowState (XMLConverterState nsID extraState) b c
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr ((Content -> Fallible Element)
-> ArrowState
(XMLConverterState nsID extraState) Content (Fallible Element))
-> (Content -> Fallible Element)
-> ArrowState
(XMLConverterState nsID extraState) Content (Fallible Element)
forall a b. (a -> b) -> a -> b
$ \case
XML.Elem Element
e' -> Element -> Fallible Element
forall a _x. a -> Either _x a
succeedWith Element
e'
Content
_ -> Fallible Element
forall failure _x. Monoid failure => Either failure _x
failEmpty
prepareMatchersC :: (NameSpaceID nsID)
=> [(nsID, ElementName, FallibleXMLConverter nsID extraState x x)]
-> ContentMatchConverter nsID extraState x
prepareMatchersC :: forall nsID extraState x.
NameSpaceID nsID =>
[(nsID, Text, FallibleXMLConverter nsID extraState x x)]
-> ContentMatchConverter nsID extraState x
prepareMatchersC = [ArrowState
(XMLConverterState nsID extraState)
(MaybeCConverter nsID extraState x, Content)
(MaybeCConverter nsID extraState x, Content)]
-> ArrowState
(XMLConverterState nsID extraState)
(MaybeCConverter nsID extraState x, Content)
(MaybeCConverter nsID extraState x, Content)
forall (cat :: * -> * -> *) (f :: * -> *) a.
(Category cat, Foldable f) =>
f (cat a a) -> cat a a
reverseComposition ([ArrowState
(XMLConverterState nsID extraState)
(MaybeCConverter nsID extraState x, Content)
(MaybeCConverter nsID extraState x, Content)]
-> ArrowState
(XMLConverterState nsID extraState)
(MaybeCConverter nsID extraState x, Content)
(MaybeCConverter nsID extraState x, Content))
-> ([(nsID, Text, FallibleXMLConverter nsID extraState x x)]
-> [ArrowState
(XMLConverterState nsID extraState)
(MaybeCConverter nsID extraState x, Content)
(MaybeCConverter nsID extraState x, Content)])
-> [(nsID, Text, FallibleXMLConverter nsID extraState x x)]
-> ArrowState
(XMLConverterState nsID extraState)
(MaybeCConverter nsID extraState x, Content)
(MaybeCConverter nsID extraState x, Content)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((nsID, Text, FallibleXMLConverter nsID extraState x x)
-> ArrowState
(XMLConverterState nsID extraState)
(MaybeCConverter nsID extraState x, Content)
(MaybeCConverter nsID extraState x, Content))
-> [(nsID, Text, FallibleXMLConverter nsID extraState x x)]
-> [ArrowState
(XMLConverterState nsID extraState)
(MaybeCConverter nsID extraState x, Content)
(MaybeCConverter nsID extraState x, Content)]
forall a b. (a -> b) -> [a] -> [b]
map ((nsID
-> Text
-> FallibleXMLConverter nsID extraState x x
-> ArrowState
(XMLConverterState nsID extraState)
(MaybeCConverter nsID extraState x, Content)
(MaybeCConverter nsID extraState x, Content))
-> (nsID, Text, FallibleXMLConverter nsID extraState x x)
-> ArrowState
(XMLConverterState nsID extraState)
(MaybeCConverter nsID extraState x, Content)
(MaybeCConverter nsID extraState x, Content)
forall a b c z. (a -> b -> c -> z) -> (a, b, c) -> z
uncurry3 nsID
-> Text
-> FallibleXMLConverter nsID extraState x x
-> ArrowState
(XMLConverterState nsID extraState)
(MaybeCConverter nsID extraState x, Content)
(MaybeCConverter nsID extraState x, Content)
forall nsID extraState a.
NameSpaceID nsID =>
nsID
-> Text
-> FallibleXMLConverter nsID extraState a a
-> ContentMatchConverter nsID extraState a
makeMatcherC)
matchContent' :: (NameSpaceID nsID)
=> [(nsID, ElementName, FallibleXMLConverter nsID extraState a a)]
-> XMLConverter nsID extraState a a
matchContent' :: forall nsID extraState a.
NameSpaceID nsID =>
[(nsID, Text, FallibleXMLConverter nsID extraState a a)]
-> XMLConverter nsID extraState a a
matchContent' [(nsID, Text, FallibleXMLConverter nsID extraState a a)]
lookups = [(nsID, Text, FallibleXMLConverter nsID extraState a a)]
-> XMLConverter nsID extraState (a, Content) a
-> XMLConverter nsID extraState a a
forall nsID extraState a.
NameSpaceID nsID =>
[(nsID, Text, FallibleXMLConverter nsID extraState a a)]
-> XMLConverter nsID extraState (a, Content) a
-> XMLConverter nsID extraState a a
matchContent [(nsID, Text, FallibleXMLConverter nsID extraState a a)]
lookups (((a, Content) -> a) -> XMLConverter nsID extraState (a, Content) a
forall b c.
(b -> c) -> ArrowState (XMLConverterState nsID extraState) b c
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (a, Content) -> a
forall a b. (a, b) -> a
fst)
matchContent :: (NameSpaceID nsID)
=> [(nsID, ElementName, FallibleXMLConverter nsID extraState a a)]
-> XMLConverter nsID extraState (a,XML.Content) a
-> XMLConverter nsID extraState a a
matchContent :: forall nsID extraState a.
NameSpaceID nsID =>
[(nsID, Text, FallibleXMLConverter nsID extraState a a)]
-> XMLConverter nsID extraState (a, Content) a
-> XMLConverter nsID extraState a a
matchContent [(nsID, Text, FallibleXMLConverter nsID extraState a a)]
lookups XMLConverter nsID extraState (a, Content) a
fallback
= let matcher :: ContentMatchConverter nsID extraState a
matcher = [(nsID, Text, FallibleXMLConverter nsID extraState a a)]
-> ContentMatchConverter nsID extraState a
forall nsID extraState x.
NameSpaceID nsID =>
[(nsID, Text, FallibleXMLConverter nsID extraState x x)]
-> ContentMatchConverter nsID extraState x
prepareMatchersC [(nsID, Text, FallibleXMLConverter nsID extraState a a)]
lookups
in ArrowState
(XMLConverterState nsID extraState)
a
(ArrowState (XMLConverterState nsID extraState) a a)
-> ArrowState
(XMLConverterState nsID extraState)
a
(a, ArrowState (XMLConverterState nsID extraState) a a)
forall (a :: * -> * -> *) b c. Arrow a => a b c -> a b (b, c)
keepingTheValue (
XMLConverter nsID extraState a [Content]
forall nsID extraState x. XMLConverter nsID extraState x [Content]
elContent
XMLConverter nsID extraState a [Content]
-> ArrowState
(XMLConverterState nsID extraState)
[Content]
(ArrowState (XMLConverterState nsID extraState) a a)
-> ArrowState
(XMLConverterState nsID extraState)
a
(ArrowState (XMLConverterState nsID extraState) a a)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (Content
-> (Maybe (IdXMLConverter nsID extraState (a, Content)), Content))
-> [Content]
-> [(Maybe (IdXMLConverter nsID extraState (a, Content)), Content)]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe (IdXMLConverter nsID extraState (a, Content))
forall a. Maybe a
Nothing,)
([Content]
-> [(Maybe (IdXMLConverter nsID extraState (a, Content)),
Content)])
-> ArrowState
(XMLConverterState nsID extraState)
[(Maybe (IdXMLConverter nsID extraState (a, Content)), Content)]
(ArrowState (XMLConverterState nsID extraState) a a)
-> ArrowState
(XMLConverterState nsID extraState)
[Content]
(ArrowState (XMLConverterState nsID extraState) a a)
forall (a :: * -> * -> *) b c d.
Arrow a =>
(b -> c) -> a c d -> a b d
^>> ContentMatchConverter nsID extraState a
-> ArrowState
(XMLConverterState nsID extraState)
[(Maybe (IdXMLConverter nsID extraState (a, Content)), Content)]
[(Maybe (IdXMLConverter nsID extraState (a, Content)), Content)]
forall (f :: * -> *) (m :: * -> *) s x y.
(Foldable f, MonadPlus m) =>
ArrowState s x y -> ArrowState s (f x) (m y)
iterateSL ContentMatchConverter nsID extraState a
matcher
ArrowState
(XMLConverterState nsID extraState)
[(Maybe (IdXMLConverter nsID extraState (a, Content)), Content)]
[(Maybe (IdXMLConverter nsID extraState (a, Content)), Content)]
-> ([(Maybe (IdXMLConverter nsID extraState (a, Content)),
Content)]
-> ArrowState (XMLConverterState nsID extraState) a a)
-> ArrowState
(XMLConverterState nsID extraState)
[(Maybe (IdXMLConverter nsID extraState (a, Content)), Content)]
(ArrowState (XMLConverterState nsID extraState) a a)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ ((Maybe (IdXMLConverter nsID extraState (a, Content)), Content)
-> ArrowState (XMLConverterState nsID extraState) a a)
-> [(Maybe (IdXMLConverter nsID extraState (a, Content)), Content)]
-> [ArrowState (XMLConverterState nsID extraState) a a]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe (IdXMLConverter nsID extraState (a, Content)), Content)
-> ArrowState (XMLConverterState nsID extraState) a a
swallowOrFallback
([(Maybe (IdXMLConverter nsID extraState (a, Content)), Content)]
-> [ArrowState (XMLConverterState nsID extraState) a a])
-> ([ArrowState (XMLConverterState nsID extraState) a a]
-> ArrowState (XMLConverterState nsID extraState) a a)
-> [(Maybe (IdXMLConverter nsID extraState (a, Content)), Content)]
-> ArrowState (XMLConverterState nsID extraState) a a
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> [ArrowState (XMLConverterState nsID extraState) a a]
-> ArrowState (XMLConverterState nsID extraState) a a
forall (cat :: * -> * -> *) (f :: * -> *) a.
(Category cat, Foldable f) =>
f (cat a a) -> cat a a
reverseComposition
)
ArrowState
(XMLConverterState nsID extraState)
a
(a, ArrowState (XMLConverterState nsID extraState) a a)
-> ArrowState
(XMLConverterState nsID extraState)
(a, ArrowState (XMLConverterState nsID extraState) a a)
a
-> ArrowState (XMLConverterState nsID extraState) a a
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (a, ArrowState (XMLConverterState nsID extraState) a a)
-> (ArrowState (XMLConverterState nsID extraState) a a, a)
forall a b. (a, b) -> (b, a)
swap
((a, ArrowState (XMLConverterState nsID extraState) a a)
-> (ArrowState (XMLConverterState nsID extraState) a a, a))
-> ArrowState
(XMLConverterState nsID extraState)
(ArrowState (XMLConverterState nsID extraState) a a, a)
a
-> ArrowState
(XMLConverterState nsID extraState)
(a, ArrowState (XMLConverterState nsID extraState) a a)
a
forall (a :: * -> * -> *) b c d.
Arrow a =>
(b -> c) -> a c d -> a b d
^>> ArrowState
(XMLConverterState nsID extraState)
(ArrowState (XMLConverterState nsID extraState) a a, a)
a
forall b c.
ArrowState
(XMLConverterState nsID extraState)
(ArrowState (XMLConverterState nsID extraState) b c, b)
c
forall (a :: * -> * -> *) b c. ArrowApply a => a (a b c, b) c
app
where
swallowOrFallback :: (Maybe (IdXMLConverter nsID extraState (a, Content)), Content)
-> ArrowState (XMLConverterState nsID extraState) a a
swallowOrFallback (Just IdXMLConverter nsID extraState (a, Content)
converter,Content
content) = (,Content
content) (a -> (a, Content))
-> XMLConverter nsID extraState (a, Content) a
-> ArrowState (XMLConverterState nsID extraState) a a
forall (a :: * -> * -> *) b c d.
Arrow a =>
(b -> c) -> a c d -> a b d
^>> IdXMLConverter nsID extraState (a, Content)
converter IdXMLConverter nsID extraState (a, Content)
-> ((a, Content) -> a)
-> XMLConverter nsID extraState (a, Content) a
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ (a, Content) -> a
forall a b. (a, b) -> a
fst
swallowOrFallback (Maybe (IdXMLConverter nsID extraState (a, Content))
Nothing ,Content
content) = (,Content
content) (a -> (a, Content))
-> XMLConverter nsID extraState (a, Content) a
-> ArrowState (XMLConverterState nsID extraState) a a
forall (a :: * -> * -> *) b c d.
Arrow a =>
(b -> c) -> a c d -> a b d
^>> XMLConverter nsID extraState (a, Content) a
fallback
stringToBool' :: Text -> Maybe Bool
stringToBool' :: Text -> Maybe Bool
stringToBool' Text
val | Text
val Text -> [Text] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
trueValues = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True
| Text
val Text -> [Text] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
falseValues = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
| Bool
otherwise = Maybe Bool
forall a. Maybe a
Nothing
where trueValues :: [Text]
trueValues = [Text
"true" ,Text
"on" ,Text
"1"]
falseValues :: [Text]
falseValues = [Text
"false",Text
"off",Text
"0"]
distributeValue :: a -> [b] -> [(a,b)]
distributeValue :: forall a b. a -> [b] -> [(a, b)]
distributeValue = (b -> (a, b)) -> [b] -> [(a, b)]
forall a b. (a -> b) -> [a] -> [b]
map((b -> (a, b)) -> [b] -> [(a, b)])
-> (a -> b -> (a, b)) -> a -> [b] -> [(a, b)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(,)