{-# LANGUAGE ExistentialQuantification #-}
module Text.XML.HaXml.XmlContent.Parser
(
Document(..)
, Element(..)
, ElemTag(..)
, Content(..)
, Attribute()
, AttValue(..)
, Prolog(..)
, Reference(..)
, XmlContent(..)
, XmlAttributes(..)
, XmlAttrType(..)
, module Text.ParserCombinators.Poly
, XMLParser
, content, posnElement, element, interior, inElement, text, attributes
, posnElementWith, elementWith, inElementWith
, choice, definite
, mkElem, mkElemC, mkAttr
, toText, toCData
, maybeToAttr, defaultToAttr
, definiteA, defaultA, possibleA, fromAttrToStr, toAttrFrStr
, Defaultable(..)
, str2attr, attr2str, attval
, catMaybes
, module Text.XML.HaXml.TypeMapping
, List1(..)
, ANYContent(..)
) where
import Control.Monad (void)
import Data.Maybe (catMaybes)
import Data.Char (chr, isSpace)
import Text.XML.HaXml.Types
import Text.XML.HaXml.Namespaces
import Text.XML.HaXml.TypeMapping
import Text.XML.HaXml.Posn (Posn)
import Text.XML.HaXml.Verbatim (Verbatim(verbatim))
import Text.ParserCombinators.Poly
#if defined(DEBUG)
import Debug.Trace(trace)
debug :: a -> String -> a
v `debug` s = trace s v
#else
debug :: t -> t1 -> t
t
v debug :: forall t t1. t -> t1 -> t
`debug` t1
_ = t
v
#endif
attval :: (Read a) => Element i -> a
attval :: forall a i. Read a => Element i -> a
attval (Elem QName
_ [(QName
_,v :: AttValue
v@(AttValue [Either String Reference]
_))] []) = forall a. Read a => String -> a
read (forall a. Show a => a -> String
show AttValue
v)
mkAttr :: String -> String -> Attribute
mkAttr :: String -> String -> Attribute
mkAttr String
n String
v = (String -> QName
N String
n, [Either String Reference] -> AttValue
AttValue [forall a b. a -> Either a b
Left String
v])
mkElem :: XmlContent a => a -> [Content ()] -> Content ()
mkElem :: forall a. XmlContent a => a -> [Content ()] -> Content ()
mkElem a
x [Content ()]
cs = forall i. Element i -> i -> Content i
CElem (forall i. QName -> [Attribute] -> [Content i] -> Element i
Elem (String -> QName
N (HType -> ShowS
showHType (forall a. HTypeable a => a -> HType
toHType a
x) String
"")) [] [Content ()]
cs) ()
mkElemC :: String -> [Content ()] -> Content ()
mkElemC :: String -> [Content ()] -> Content ()
mkElemC String
x [Content ()]
cs = forall i. Element i -> i -> Content i
CElem (forall i. QName -> [Attribute] -> [Content i] -> Element i
Elem (String -> QName
N String
x) [] [Content ()]
cs) ()
toText :: String -> [Content ()]
toText :: String -> [Content ()]
toText String
s = [forall i. Bool -> String -> i -> Content i
CString Bool
False String
s ()]
toCData :: String -> [Content ()]
toCData :: String -> [Content ()]
toCData String
s = [forall i. Bool -> String -> i -> Content i
CString Bool
True String
s ()]
type XMLParser a = Parser (Content Posn) a
content :: String -> XMLParser (Content Posn)
content :: String -> XMLParser (Content Posn)
content String
word = forall t. Parser t t
next forall (p :: * -> *) a. Commitment p => p a -> ShowS -> p a
`adjustErr` (forall a. [a] -> [a] -> [a]
++String
" when expecting "forall a. [a] -> [a] -> [a]
++String
word)
posnElementWith :: (String->String->Bool) -> [String]
-> XMLParser (Posn, Element Posn)
posnElementWith :: (String -> String -> Bool)
-> [String] -> XMLParser (Posn, Element Posn)
posnElementWith String -> String -> Bool
match [String]
tags = do
{ Content Posn
c <- String -> XMLParser (Content Posn)
content ([String] -> String
formatted [String]
tags)
; case Content Posn
c of
CElem e :: Element Posn
e@(Elem QName
t [Attribute]
_ [Content Posn]
_) Posn
pos
| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (String -> String -> Bool
match (QName -> String
localName QName
t)) [String]
tags -> forall (m :: * -> *) a. Monad m => a -> m a
return (Posn
pos, Element Posn
e)
| Bool
otherwise -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Found a <"forall a. [a] -> [a] -> [a]
++QName -> String
printableName QName
t
forall a. [a] -> [a] -> [a]
++String
">, but expected "
forall a. [a] -> [a] -> [a]
++[String] -> String
formatted [String]
tagsforall a. [a] -> [a] -> [a]
++String
"\nat "forall a. [a] -> [a] -> [a]
++forall a. Show a => a -> String
show Posn
pos)
CString Bool
b String
s Posn
pos
| Bool -> Bool
not Bool
b Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
isSpace String
s -> (String -> String -> Bool)
-> [String] -> XMLParser (Posn, Element Posn)
posnElementWith String -> String -> Bool
match [String]
tags
| Bool
otherwise -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Found text content, but expected "
forall a. [a] -> [a] -> [a]
++[String] -> String
formatted [String]
tagsforall a. [a] -> [a] -> [a]
++String
"\ntext is: "forall a. [a] -> [a] -> [a]
++String
s
forall a. [a] -> [a] -> [a]
++String
"\nat "forall a. [a] -> [a] -> [a]
++forall a. Show a => a -> String
show Posn
pos)
CRef Reference
r Posn
pos -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Found reference, but expected "
forall a. [a] -> [a] -> [a]
++[String] -> String
formatted [String]
tagsforall a. [a] -> [a] -> [a]
++String
"\nreference is: "forall a. [a] -> [a] -> [a]
++forall a. Verbatim a => a -> String
verbatim Reference
r
forall a. [a] -> [a] -> [a]
++String
"\nat "forall a. [a] -> [a] -> [a]
++forall a. Show a => a -> String
show Posn
pos)
CMisc Misc
_ Posn
_ -> (String -> String -> Bool)
-> [String] -> XMLParser (Posn, Element Posn)
posnElementWith String -> String -> Bool
match [String]
tags
}
where
formatted :: [String] -> String
formatted [String
t] = String
"a <"forall a. [a] -> [a] -> [a]
++String
tforall a. [a] -> [a] -> [a]
++String
">"
formatted [String]
tgs = String
"one of"forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\String
t->String
" <"forall a. [a] -> [a] -> [a]
++String
tforall a. [a] -> [a] -> [a]
++String
">") [String]
tgs
posnElement :: [String] -> XMLParser (Posn, Element Posn)
posnElement :: [String] -> XMLParser (Posn, Element Posn)
posnElement = (String -> String -> Bool)
-> [String] -> XMLParser (Posn, Element Posn)
posnElementWith forall a. Eq a => a -> a -> Bool
(==)
element :: [String] -> XMLParser (Element Posn)
element :: [String] -> XMLParser (Element Posn)
element [String]
tags = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> b
snd ([String] -> XMLParser (Posn, Element Posn)
posnElement [String]
tags)
forall t t1. t -> t1 -> t
`debug` (String
"Element: "forall a. [a] -> [a] -> [a]
++[String] -> String
unwords [String]
tagsforall a. [a] -> [a] -> [a]
++String
"\n")
elementWith :: (String->String->Bool) -> [String] -> XMLParser (Element Posn)
elementWith :: (String -> String -> Bool) -> [String] -> XMLParser (Element Posn)
elementWith String -> String -> Bool
match [String]
tags = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> b
snd ((String -> String -> Bool)
-> [String] -> XMLParser (Posn, Element Posn)
posnElementWith String -> String -> Bool
match [String]
tags)
forall t t1. t -> t1 -> t
`debug` (String
"Element: "forall a. [a] -> [a] -> [a]
++[String] -> String
unwords [String]
tagsforall a. [a] -> [a] -> [a]
++String
"\n")
interior :: Element Posn -> XMLParser a -> XMLParser a
interior :: forall a. Element Posn -> XMLParser a -> XMLParser a
interior (Elem QName
e [Attribute]
_ [Content Posn]
cs) XMLParser a
p =
case forall t a. Parser t a -> [t] -> (Either String a, [t])
runParser XMLParser a
p [Content Posn]
cs of
(Left String
msg, [Content Posn]
_) -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
msg
(Right a
x, []) -> forall (m :: * -> *) a. Monad m => a -> m a
return a
x
(Right a
x, ds :: [Content Posn]
ds@(Content Posn
d:[Content Posn]
_))
| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all forall {i}. Content i -> Bool
onlyMisc [Content Posn]
ds -> forall (m :: * -> *) a. Monad m => a -> m a
return a
x
| Bool
otherwise -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Too many elements inside <"
forall a. [a] -> [a] -> [a]
++QName -> String
printableName QName
eforall a. [a] -> [a] -> [a]
++String
"> at\n"
forall a. [a] -> [a] -> [a]
++forall a. Show a => a -> String
show (forall t. Content t -> t
info Content Posn
d)forall a. [a] -> [a] -> [a]
++String
"\n"
forall a. [a] -> [a] -> [a]
++String
"Found excess: "
forall a. [a] -> [a] -> [a]
++forall a. Verbatim a => a -> String
verbatim (forall a. Int -> [a] -> [a]
take Int
7 [Content Posn]
ds)
forall a. [a] -> [a] -> [a]
++String
"\n[...]")
where onlyMisc :: Content i -> Bool
onlyMisc (CMisc Misc
_ i
_) = Bool
True
onlyMisc (CString Bool
False String
s i
_) | forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
isSpace String
s = Bool
True
onlyMisc Content i
_ = Bool
False
inElement :: String -> XMLParser a -> XMLParser a
inElement :: forall a. String -> XMLParser a -> XMLParser a
inElement String
tag XMLParser a
p = do { Element Posn
e <- [String] -> XMLParser (Element Posn)
element [String
tag]; forall (p :: * -> *) a. Commitment p => p a -> p a
commit (forall a. Element Posn -> XMLParser a -> XMLParser a
interior Element Posn
e XMLParser a
p) }
inElementWith :: (String->String->Bool) -> String -> XMLParser a -> XMLParser a
inElementWith :: forall a.
(String -> String -> Bool) -> String -> XMLParser a -> XMLParser a
inElementWith String -> String -> Bool
match String
tag XMLParser a
p = do { Element Posn
e <- (String -> String -> Bool) -> [String] -> XMLParser (Element Posn)
elementWith String -> String -> Bool
match [String
tag]
; forall (p :: * -> *) a. Commitment p => p a -> p a
commit (forall a. Element Posn -> XMLParser a -> XMLParser a
interior Element Posn
e XMLParser a
p) }
attributes :: XmlAttributes a => Element Posn -> XMLParser a
attributes :: forall a. XmlAttributes a => Element Posn -> XMLParser a
attributes (Elem QName
_ [Attribute]
as [Content Posn]
_) = forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. XmlAttributes a => [Attribute] -> a
fromAttrs [Attribute]
as)
text :: XMLParser String
text :: XMLParser String
text = [String] -> XMLParser String
text' []
where text' :: [String] -> XMLParser String
text' [String]
acc =
do { Content Posn
c <- String -> XMLParser (Content Posn)
content String
"plain text"
; case Content Posn
c of
CString Bool
_ String
s Posn
_ -> [String] -> XMLParser String
text' (String
sforall a. a -> [a] -> [a]
:[String]
acc)
CRef (RefChar Int
s) Posn
_ -> [String] -> XMLParser String
text' ((String
"&#"forall a. [a] -> [a] -> [a]
++forall a. Show a => a -> String
show Int
sforall a. [a] -> [a] -> [a]
++String
";") forall a. a -> [a] -> [a]
:[String]
acc)
CRef (RefEntity String
s) Posn
_ -> [String] -> XMLParser String
text' ((Char
'&'forall a. a -> [a] -> [a]
:String
sforall a. [a] -> [a] -> [a]
++String
";")forall a. a -> [a] -> [a]
:[String]
acc)
CMisc Misc
_ Posn
_ -> [String] -> XMLParser String
text' [String]
acc
CElem Element Posn
_ Posn
_ -> do { forall t. [t] -> Parser t ()
reparse [Content Posn
c]
; if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
acc then forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"empty string"
else forall (m :: * -> *) a. Monad m => a -> m a
return (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (forall a. [a] -> [a]
reverse [String]
acc))
}
}
forall t a. Parser t a -> Parser t a -> Parser t a
`onFail` ( if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
acc then forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"empty string"
else forall (m :: * -> *) a. Monad m => a -> m a
return (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (forall a. [a] -> [a]
reverse [String]
acc)) )
choice :: XmlContent a => (a -> b) -> XMLParser b -> XMLParser b
choice :: forall a b. XmlContent a => (a -> b) -> XMLParser b -> XMLParser b
choice a -> b
cons (P [Content Posn] -> Result [Content Posn] b
other) =
forall t a. ([t] -> Result [t] a) -> Parser t a
P (\[Content Posn]
cs-> case forall t a. Parser t a -> [t] -> (Either String a, [t])
runParser forall a. XmlContent a => XMLParser a
parseContents [Content Posn]
cs of
(Left String
_, [Content Posn]
_) -> [Content Posn] -> Result [Content Posn] b
other [Content Posn]
cs
(Right a
x, [Content Posn]
cs') -> forall z a. z -> a -> Result z a
Success [Content Posn]
cs' (a -> b
cons a
x) )
definite :: XmlContent a => XMLParser a -> String -> String -> XMLParser a
definite :: forall a.
XmlContent a =>
XMLParser a -> String -> String -> XMLParser a
definite XMLParser a
p String
inner String
tag = forall t a. ([t] -> Result [t] a) -> Parser t a
P (\[Content Posn]
cs-> case forall t a. Parser t a -> [t] -> (Either String a, [t])
runParser XMLParser a
p [Content Posn]
cs of
(Left String
_, [Content Posn]
cs') -> forall z a. z -> String -> Result z a
Failure [Content Posn]
cs' String
msg'
(Right a
x, [Content Posn]
cs') -> forall z a. z -> a -> Result z a
Success [Content Posn]
cs' a
x )
where msg' :: String
msg' = String
"content error: expected "forall a. [a] -> [a] -> [a]
++String
innerforall a. [a] -> [a] -> [a]
++String
" inside <"forall a. [a] -> [a] -> [a]
++String
tag
forall a. [a] -> [a] -> [a]
++String
"> element\n"
class HTypeable a => XmlContent a where
parseContents :: XMLParser a
toContents :: a -> [Content ()]
xToChar :: a -> Char
xFromChar :: Char -> a
xToChar = forall a. HasCallStack => String -> a
error String
"HaXml.XmlContent.xToChar used in error"
xFromChar = forall a. HasCallStack => String -> a
error String
"HaXml.XmlContent.xFromChar used in error"
class XmlAttributes a where
fromAttrs :: [Attribute] -> a
toAttrs :: a -> [Attribute]
class XmlAttrType a where
fromAttrToTyp :: String -> Attribute -> Maybe a
toAttrFrTyp :: String -> a -> Maybe Attribute
instance (XmlContent a, XmlContent b) => XmlContent (a,b) where
toContents :: (a, b) -> [Content ()]
toContents (a
a,b
b) = forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b
parseContents :: XMLParser (a, b)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b)
}
instance (XmlContent a, XmlContent b, XmlContent c) => XmlContent (a,b,c) where
toContents :: (a, b, c) -> [Content ()]
toContents (a
a,b
b,c
c) = forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents c
c
parseContents :: XMLParser (a, b, c)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; c
c <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c)
}
instance (XmlContent a, XmlContent b, XmlContent c, XmlContent d) =>
XmlContent (a,b,c,d) where
toContents :: (a, b, c, d) -> [Content ()]
toContents (a
a,b
b,c
c,d
d) = forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents c
c
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents d
d
parseContents :: XMLParser (a, b, c, d)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; c
c <- forall a. XmlContent a => XMLParser a
parseContents
; d
d <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d)
}
instance ( XmlContent a, XmlContent b, XmlContent c, XmlContent d
, XmlContent e ) =>
XmlContent (a,b,c,d,e) where
toContents :: (a, b, c, d, e) -> [Content ()]
toContents (a
a,b
b,c
c,d
d,e
e) = forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents c
c
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents d
d forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents e
e
parseContents :: XMLParser (a, b, c, d, e)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; c
c <- forall a. XmlContent a => XMLParser a
parseContents
; d
d <- forall a. XmlContent a => XMLParser a
parseContents
; e
e <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e)
}
instance ( XmlContent a, XmlContent b, XmlContent c, XmlContent d
, XmlContent e, XmlContent f ) =>
XmlContent (a,b,c,d,e,f) where
toContents :: (a, b, c, d, e, f) -> [Content ()]
toContents (a
a,b
b,c
c,d
d,e
e,f
f) = forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents c
c
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents d
d forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents e
e forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents f
f
parseContents :: XMLParser (a, b, c, d, e, f)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; c
c <- forall a. XmlContent a => XMLParser a
parseContents
; d
d <- forall a. XmlContent a => XMLParser a
parseContents
; e
e <- forall a. XmlContent a => XMLParser a
parseContents
; f
f <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f)
}
instance ( XmlContent a, XmlContent b, XmlContent c, XmlContent d
, XmlContent e, XmlContent f, XmlContent g ) =>
XmlContent (a,b,c,d,e,f,g) where
toContents :: (a, b, c, d, e, f, g) -> [Content ()]
toContents (a
a,b
b,c
c,d
d,e
e,f
f,g
g)
= forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents c
c forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents d
d
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents e
e forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents f
f forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents g
g
parseContents :: XMLParser (a, b, c, d, e, f, g)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; c
c <- forall a. XmlContent a => XMLParser a
parseContents
; d
d <- forall a. XmlContent a => XMLParser a
parseContents
; e
e <- forall a. XmlContent a => XMLParser a
parseContents
; f
f <- forall a. XmlContent a => XMLParser a
parseContents
; g
g <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g)
}
instance ( XmlContent a, XmlContent b, XmlContent c, XmlContent d
, XmlContent e, XmlContent f, XmlContent g, XmlContent h ) =>
XmlContent (a,b,c,d,e,f,g,h) where
toContents :: (a, b, c, d, e, f, g, h) -> [Content ()]
toContents (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h)
= forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents c
c forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents d
d
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents e
e forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents f
f forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents g
g forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents h
h
parseContents :: XMLParser (a, b, c, d, e, f, g, h)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; c
c <- forall a. XmlContent a => XMLParser a
parseContents
; d
d <- forall a. XmlContent a => XMLParser a
parseContents
; e
e <- forall a. XmlContent a => XMLParser a
parseContents
; f
f <- forall a. XmlContent a => XMLParser a
parseContents
; g
g <- forall a. XmlContent a => XMLParser a
parseContents
; h
h <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h)
}
instance ( XmlContent a, XmlContent b, XmlContent c, XmlContent d
, XmlContent e, XmlContent f, XmlContent g, XmlContent h
, XmlContent i ) =>
XmlContent (a,b,c,d,e,f,g,h,i) where
toContents :: (a, b, c, d, e, f, g, h, i) -> [Content ()]
toContents (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i)
= forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents c
c forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents d
d
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents e
e forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents f
f forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents g
g forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents h
h
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents i
i
parseContents :: XMLParser (a, b, c, d, e, f, g, h, i)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; c
c <- forall a. XmlContent a => XMLParser a
parseContents
; d
d <- forall a. XmlContent a => XMLParser a
parseContents
; e
e <- forall a. XmlContent a => XMLParser a
parseContents
; f
f <- forall a. XmlContent a => XMLParser a
parseContents
; g
g <- forall a. XmlContent a => XMLParser a
parseContents
; h
h <- forall a. XmlContent a => XMLParser a
parseContents
; i
i <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i)
}
instance ( XmlContent a, XmlContent b, XmlContent c, XmlContent d
, XmlContent e, XmlContent f, XmlContent g, XmlContent h
, XmlContent i, XmlContent j ) =>
XmlContent (a,b,c,d,e,f,g,h,i,j) where
toContents :: (a, b, c, d, e, f, g, h, i, j) -> [Content ()]
toContents (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j)
= forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents c
c forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents d
d
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents e
e forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents f
f forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents g
g forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents h
h
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents i
i forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents j
j
parseContents :: XMLParser (a, b, c, d, e, f, g, h, i, j)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; c
c <- forall a. XmlContent a => XMLParser a
parseContents
; d
d <- forall a. XmlContent a => XMLParser a
parseContents
; e
e <- forall a. XmlContent a => XMLParser a
parseContents
; f
f <- forall a. XmlContent a => XMLParser a
parseContents
; g
g <- forall a. XmlContent a => XMLParser a
parseContents
; h
h <- forall a. XmlContent a => XMLParser a
parseContents
; i
i <- forall a. XmlContent a => XMLParser a
parseContents
; j
j <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j)
}
instance ( XmlContent a, XmlContent b, XmlContent c, XmlContent d
, XmlContent e, XmlContent f, XmlContent g, XmlContent h
, XmlContent i, XmlContent j, XmlContent k ) =>
XmlContent (a,b,c,d,e,f,g,h,i,j,k) where
toContents :: (a, b, c, d, e, f, g, h, i, j, k) -> [Content ()]
toContents (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k)
= forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents c
c forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents d
d
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents e
e forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents f
f forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents g
g forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents h
h
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents i
i forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents j
j forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents k
k
parseContents :: XMLParser (a, b, c, d, e, f, g, h, i, j, k)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; c
c <- forall a. XmlContent a => XMLParser a
parseContents
; d
d <- forall a. XmlContent a => XMLParser a
parseContents
; e
e <- forall a. XmlContent a => XMLParser a
parseContents
; f
f <- forall a. XmlContent a => XMLParser a
parseContents
; g
g <- forall a. XmlContent a => XMLParser a
parseContents
; h
h <- forall a. XmlContent a => XMLParser a
parseContents
; i
i <- forall a. XmlContent a => XMLParser a
parseContents
; j
j <- forall a. XmlContent a => XMLParser a
parseContents
; k
k <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k)
}
instance ( XmlContent a, XmlContent b, XmlContent c, XmlContent d
, XmlContent e, XmlContent f, XmlContent g, XmlContent h
, XmlContent i, XmlContent j, XmlContent k, XmlContent l ) =>
XmlContent (a,b,c,d,e,f,g,h,i,j,k,l) where
toContents :: (a, b, c, d, e, f, g, h, i, j, k, l) -> [Content ()]
toContents (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l)
= forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents c
c forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents d
d
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents e
e forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents f
f forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents g
g forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents h
h
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents i
i forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents j
j forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents k
k forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents l
l
parseContents :: XMLParser (a, b, c, d, e, f, g, h, i, j, k, l)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; c
c <- forall a. XmlContent a => XMLParser a
parseContents
; d
d <- forall a. XmlContent a => XMLParser a
parseContents
; e
e <- forall a. XmlContent a => XMLParser a
parseContents
; f
f <- forall a. XmlContent a => XMLParser a
parseContents
; g
g <- forall a. XmlContent a => XMLParser a
parseContents
; h
h <- forall a. XmlContent a => XMLParser a
parseContents
; i
i <- forall a. XmlContent a => XMLParser a
parseContents
; j
j <- forall a. XmlContent a => XMLParser a
parseContents
; k
k <- forall a. XmlContent a => XMLParser a
parseContents
; l
l <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l)
}
instance ( XmlContent a, XmlContent b, XmlContent c, XmlContent d
, XmlContent e, XmlContent f, XmlContent g, XmlContent h
, XmlContent i, XmlContent j, XmlContent k, XmlContent l
, XmlContent m ) =>
XmlContent (a,b,c,d,e,f,g,h,i,j,k,l,m) where
toContents :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> [Content ()]
toContents (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m)
= forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents c
c forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents d
d
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents e
e forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents f
f forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents g
g forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents h
h
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents i
i forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents j
j forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents k
k forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents l
l
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents m
m
parseContents :: XMLParser (a, b, c, d, e, f, g, h, i, j, k, l, m)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; c
c <- forall a. XmlContent a => XMLParser a
parseContents
; d
d <- forall a. XmlContent a => XMLParser a
parseContents
; e
e <- forall a. XmlContent a => XMLParser a
parseContents
; f
f <- forall a. XmlContent a => XMLParser a
parseContents
; g
g <- forall a. XmlContent a => XMLParser a
parseContents
; h
h <- forall a. XmlContent a => XMLParser a
parseContents
; i
i <- forall a. XmlContent a => XMLParser a
parseContents
; j
j <- forall a. XmlContent a => XMLParser a
parseContents
; k
k <- forall a. XmlContent a => XMLParser a
parseContents
; l
l <- forall a. XmlContent a => XMLParser a
parseContents
; m
m <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m)
}
instance ( XmlContent a, XmlContent b, XmlContent c, XmlContent d
, XmlContent e, XmlContent f, XmlContent g, XmlContent h
, XmlContent i, XmlContent j, XmlContent k, XmlContent l
, XmlContent m, XmlContent n ) =>
XmlContent (a,b,c,d,e,f,g,h,i,j,k,l,m,n) where
toContents :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> [Content ()]
toContents (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m,n
n)
= forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents c
c forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents d
d
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents e
e forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents f
f forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents g
g forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents h
h
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents i
i forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents j
j forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents k
k forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents l
l
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents m
m forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents n
n
parseContents :: XMLParser (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; c
c <- forall a. XmlContent a => XMLParser a
parseContents
; d
d <- forall a. XmlContent a => XMLParser a
parseContents
; e
e <- forall a. XmlContent a => XMLParser a
parseContents
; f
f <- forall a. XmlContent a => XMLParser a
parseContents
; g
g <- forall a. XmlContent a => XMLParser a
parseContents
; h
h <- forall a. XmlContent a => XMLParser a
parseContents
; i
i <- forall a. XmlContent a => XMLParser a
parseContents
; j
j <- forall a. XmlContent a => XMLParser a
parseContents
; k
k <- forall a. XmlContent a => XMLParser a
parseContents
; l
l <- forall a. XmlContent a => XMLParser a
parseContents
; m
m <- forall a. XmlContent a => XMLParser a
parseContents
; n
n <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m,n
n)
}
instance ( XmlContent a, XmlContent b, XmlContent c, XmlContent d
, XmlContent e, XmlContent f, XmlContent g, XmlContent h
, XmlContent i, XmlContent j, XmlContent k, XmlContent l
, XmlContent m, XmlContent n, XmlContent o ) =>
XmlContent (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) where
toContents :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> [Content ()]
toContents (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m,n
n,o
o)
= forall a. XmlContent a => a -> [Content ()]
toContents a
a forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents b
b forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents c
c forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents d
d
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents e
e forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents f
f forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents g
g forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents h
h
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents i
i forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents j
j forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents k
k forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents l
l
forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents m
m forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents n
n forall a. [a] -> [a] -> [a]
++ forall a. XmlContent a => a -> [Content ()]
toContents o
o
parseContents :: XMLParser (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
parseContents = do
{ a
a <- forall a. XmlContent a => XMLParser a
parseContents
; b
b <- forall a. XmlContent a => XMLParser a
parseContents
; c
c <- forall a. XmlContent a => XMLParser a
parseContents
; d
d <- forall a. XmlContent a => XMLParser a
parseContents
; e
e <- forall a. XmlContent a => XMLParser a
parseContents
; f
f <- forall a. XmlContent a => XMLParser a
parseContents
; g
g <- forall a. XmlContent a => XMLParser a
parseContents
; h
h <- forall a. XmlContent a => XMLParser a
parseContents
; i
i <- forall a. XmlContent a => XMLParser a
parseContents
; j
j <- forall a. XmlContent a => XMLParser a
parseContents
; k
k <- forall a. XmlContent a => XMLParser a
parseContents
; l
l <- forall a. XmlContent a => XMLParser a
parseContents
; m
m <- forall a. XmlContent a => XMLParser a
parseContents
; n
n <- forall a. XmlContent a => XMLParser a
parseContents
; o
o <- forall a. XmlContent a => XMLParser a
parseContents
; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m,n
n,o
o)
}
data Defaultable a = Default a | NonDefault a deriving (Defaultable a -> Defaultable a -> Bool
forall a. Eq a => Defaultable a -> Defaultable a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Defaultable a -> Defaultable a -> Bool
$c/= :: forall a. Eq a => Defaultable a -> Defaultable a -> Bool
== :: Defaultable a -> Defaultable a -> Bool
$c== :: forall a. Eq a => Defaultable a -> Defaultable a -> Bool
Eq,Int -> Defaultable a -> ShowS
forall a. Show a => Int -> Defaultable a -> ShowS
forall a. Show a => [Defaultable a] -> ShowS
forall a. Show a => Defaultable a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Defaultable a] -> ShowS
$cshowList :: forall a. Show a => [Defaultable a] -> ShowS
show :: Defaultable a -> String
$cshow :: forall a. Show a => Defaultable a -> String
showsPrec :: Int -> Defaultable a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Defaultable a -> ShowS
Show)
searchMaybe :: (a -> Maybe b) -> [a] -> Maybe b
searchMaybe :: forall a b. (a -> Maybe b) -> [a] -> Maybe b
searchMaybe a -> Maybe b
_ [] = forall a. Maybe a
Nothing
searchMaybe a -> Maybe b
f (a
x:[a]
xs) =
let fx :: Maybe b
fx = a -> Maybe b
f a
x in
case Maybe b
fx of
Maybe b
Nothing -> forall a b. (a -> Maybe b) -> [a] -> Maybe b
searchMaybe a -> Maybe b
f [a]
xs
(Just b
_) -> Maybe b
fx
maybeToAttr :: (String->a->Maybe Attribute) -> String -> Maybe a
-> Maybe Attribute
maybeToAttr :: forall a.
(String -> a -> Maybe Attribute)
-> String -> Maybe a -> Maybe Attribute
maybeToAttr String -> a -> Maybe Attribute
_ String
_ Maybe a
Nothing = forall a. Maybe a
Nothing
maybeToAttr String -> a -> Maybe Attribute
to String
n (Just a
v) = String -> a -> Maybe Attribute
to String
n a
v
defaultToAttr :: (String->a->Maybe Attribute) -> String -> Defaultable a
-> Maybe Attribute
defaultToAttr :: forall a.
(String -> a -> Maybe Attribute)
-> String -> Defaultable a -> Maybe Attribute
defaultToAttr String -> a -> Maybe Attribute
_ String
_ (Default a
_) = forall a. Maybe a
Nothing
defaultToAttr String -> a -> Maybe Attribute
to String
n (NonDefault a
v) = String -> a -> Maybe Attribute
to String
n a
v
definiteA :: (String->Attribute->Maybe a) -> String -> String
-> [Attribute] -> a
definiteA :: forall a.
(String -> Attribute -> Maybe a)
-> String -> String -> [Attribute] -> a
definiteA String -> Attribute -> Maybe a
from String
tag String
at [Attribute]
as =
case forall a b. (a -> Maybe b) -> [a] -> Maybe b
searchMaybe (String -> Attribute -> Maybe a
from String
at) [Attribute]
as of
Maybe a
Nothing -> forall a. HasCallStack => String -> a
error (String
"missing attribute "forall a. [a] -> [a] -> [a]
++String
atforall a. [a] -> [a] -> [a]
++String
" in tag <"forall a. [a] -> [a] -> [a]
++String
tagforall a. [a] -> [a] -> [a]
++String
">")
(Just a
a) -> a
a
defaultA :: (String->Attribute->Maybe a) -> a -> String
-> [Attribute] -> Defaultable a
defaultA :: forall a.
(String -> Attribute -> Maybe a)
-> a -> String -> [Attribute] -> Defaultable a
defaultA String -> Attribute -> Maybe a
from a
def String
at [Attribute]
as =
case forall a b. (a -> Maybe b) -> [a] -> Maybe b
searchMaybe (String -> Attribute -> Maybe a
from String
at) [Attribute]
as of
Maybe a
Nothing -> forall a. a -> Defaultable a
Default a
def
(Just a
a) -> forall a. a -> Defaultable a
NonDefault a
a
possibleA :: (String->Attribute->Maybe a) -> String -> [Attribute] -> Maybe a
possibleA :: forall a.
(String -> Attribute -> Maybe a)
-> String -> [Attribute] -> Maybe a
possibleA String -> Attribute -> Maybe a
from String
at [Attribute]
as = forall a b. (a -> Maybe b) -> [a] -> Maybe b
searchMaybe (String -> Attribute -> Maybe a
from String
at) [Attribute]
as
fromAttrToStr :: String -> Attribute -> Maybe String
fromAttrToStr :: String -> Attribute -> Maybe String
fromAttrToStr String
n (QName
n0,AttValue
v)
| String
n forall a. Eq a => a -> a -> Bool
== QName -> String
localName QName
n0 = forall a. a -> Maybe a
Just (AttValue -> String
attr2str AttValue
v)
| Bool
otherwise = forall a. Maybe a
Nothing
toAttrFrStr :: String -> String -> Maybe Attribute
toAttrFrStr :: String -> String -> Maybe Attribute
toAttrFrStr String
n String
v = forall a. a -> Maybe a
Just (String -> QName
N String
n, String -> AttValue
str2attr String
v)
str2attr :: String -> AttValue
str2attr :: String -> AttValue
str2attr String
s =
let f :: String -> [Either String Reference]
f String
t =
let (String
l,String
r) = forall a. (a -> Bool) -> [a] -> ([a], [a])
span (forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` String
"\"&<>'") String
t
in if forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
r then [forall a b. a -> Either a b
Left String
l]
else forall a b. a -> Either a b
Left String
lforall a. a -> [a] -> [a]
: forall a b. b -> Either a b
Right (Char -> Reference
g (forall a. [a] -> a
head String
r))forall a. a -> [a] -> [a]
: String -> [Either String Reference]
f (forall a. [a] -> [a]
tail String
r)
g :: Char -> Reference
g Char
'"' = String -> Reference
RefEntity String
"quot"
g Char
'&' = String -> Reference
RefEntity String
"amp"
g Char
'<' = String -> Reference
RefEntity String
"lt"
g Char
'>' = String -> Reference
RefEntity String
"gt"
g Char
'\'' = String -> Reference
RefEntity String
"apos"
in [Either String Reference] -> AttValue
AttValue (String -> [Either String Reference]
f String
s)
attr2str :: AttValue -> String
attr2str :: AttValue -> String
attr2str (AttValue [Either String Reference]
xs) =
let f :: Either String Reference -> String
f (Left String
s) = String
s
f (Right (RefChar Int
i)) = [Int -> Char
chr Int
i]
f (Right (RefEntity String
"quot")) = String
"\""
f (Right (RefEntity String
"amp")) = String
"&"
f (Right (RefEntity String
"lt")) = String
"<"
f (Right (RefEntity String
"gt")) = String
">"
f (Right (RefEntity String
"apos")) = String
"'"
f (Right Reference
_) = String
"*"
in forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Either String Reference -> String
f [Either String Reference]
xs
data ANYContent = forall a . (XmlContent a, Show a) => ANYContent a
| UnConverted [Content Posn]
instance Show ANYContent where
show :: ANYContent -> String
show (UnConverted [Content Posn]
c) = String
"UnConverted " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show (forall a b. (a -> b) -> [a] -> [b]
map forall a. Verbatim a => a -> String
verbatim [Content Posn]
c)
show (ANYContent a
a) = String
"ANYContent " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show a
a
instance Eq ANYContent where
ANYContent
a == :: ANYContent -> ANYContent -> Bool
== ANYContent
b = forall a. Show a => a -> String
show ANYContent
a forall a. Eq a => a -> a -> Bool
== forall a. Show a => a -> String
show ANYContent
b
data List1 a = NonEmpty [a] deriving (List1 a -> List1 a -> Bool
forall a. Eq a => List1 a -> List1 a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: List1 a -> List1 a -> Bool
$c/= :: forall a. Eq a => List1 a -> List1 a -> Bool
== :: List1 a -> List1 a -> Bool
$c== :: forall a. Eq a => List1 a -> List1 a -> Bool
Eq, Int -> List1 a -> ShowS
forall a. Show a => Int -> List1 a -> ShowS
forall a. Show a => [List1 a] -> ShowS
forall a. Show a => List1 a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [List1 a] -> ShowS
$cshowList :: forall a. Show a => [List1 a] -> ShowS
show :: List1 a -> String
$cshow :: forall a. Show a => List1 a -> String
showsPrec :: Int -> List1 a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> List1 a -> ShowS
Show)
instance (HTypeable a) => HTypeable (List1 a) where
toHType :: List1 a -> HType
toHType List1 a
m = String -> [HType] -> [Constr] -> HType
Defined String
"List1" [HType
hx]
[String -> [HType] -> [HType] -> Constr
Constr String
"NonEmpty" [HType
hx] [HType -> HType
List HType
hx] ]
where (NonEmpty [a]
x) = List1 a
m
hx :: HType
hx = forall a. HTypeable a => a -> HType
toHType [a]
x
instance (XmlContent a) => XmlContent (List1 a) where
toContents :: List1 a -> [Content ()]
toContents (NonEmpty [a]
xs) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall a. XmlContent a => a -> [Content ()]
toContents [a]
xs
parseContents :: XMLParser (List1 a)
parseContents = forall a. [a] -> List1 a
NonEmpty forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (p :: * -> *) a. PolyParse p => p a -> p [a]
many1 forall a. XmlContent a => XMLParser a
parseContents
instance HTypeable ANYContent where
toHType :: ANYContent -> HType
toHType ANYContent
_ = String -> String -> HType
Prim String
"ANYContent" String
"ANY"
instance XmlContent ANYContent where
toContents :: ANYContent -> [Content ()]
toContents (ANYContent a
a) = forall a. XmlContent a => a -> [Content ()]
toContents a
a
toContents (UnConverted [Content Posn]
s) = forall a b. (a -> b) -> [a] -> [b]
map forall (f :: * -> *) a. Functor f => f a -> f ()
void [Content Posn]
s
parseContents :: XMLParser ANYContent
parseContents = forall t a. ([t] -> Result [t] a) -> Parser t a
P (forall z a. z -> a -> Result z a
Success [] forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Content Posn] -> ANYContent
UnConverted)