{-# LANGUAGE CPP #-}
module Text.XML.HaXml.ByteStringPP
(
document
, content
, element
, doctypedecl
, prolog
, cp
) where
#if MIN_VERSION_base(4,11,0)
import Prelude hiding (maybe,either,elem,concat,(<>))
#else
import Prelude hiding (maybe,either,elem,concat)
#endif
import Data.Maybe hiding (maybe)
import Data.List (intersperse)
import Data.ByteString.Lazy.Char8 (ByteString(), concat, pack, singleton
, intercalate, append, elem, empty)
import Text.XML.HaXml.Types
import Text.XML.HaXml.Namespaces
either :: (t -> t1) -> (t2 -> t1) -> Either t t2 -> t1
either :: (t -> t1) -> (t2 -> t1) -> Either t t2 -> t1
either f :: t -> t1
f _ (Left x :: t
x) = t -> t1
f t
x
either _ g :: t2 -> t1
g (Right x :: t2
x) = t2 -> t1
g t2
x
maybe :: (t -> ByteString) -> Maybe t -> ByteString
maybe :: (t -> ByteString) -> Maybe t -> ByteString
maybe _ Nothing = ByteString
empty
maybe f :: t -> ByteString
f (Just x :: t
x) = t -> ByteString
f t
x
infixl 6 <>
infixl 6 <+>
infixl 5 $$
(<>) :: ByteString -> ByteString -> ByteString
hcat :: [ByteString] -> ByteString
(<+>) :: ByteString -> ByteString -> ByteString
hsep :: [ByteString] -> ByteString
($$) :: ByteString -> ByteString -> ByteString
vcat :: [ByteString] -> ByteString
sep :: [ByteString] -> ByteString
fsep :: [ByteString] -> ByteString
nest :: Int -> ByteString -> ByteString
<> :: ByteString -> ByteString -> ByteString
(<>) b1 :: ByteString
b1 b2 :: ByteString
b2 = ByteString
b1 ByteString -> ByteString -> ByteString
`append` ByteString
b2
<+> :: ByteString -> ByteString -> ByteString
(<+>) b1 :: ByteString
b1 b2 :: ByteString
b2 = ByteString
b1 ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
pack " " ByteString -> ByteString -> ByteString
<> ByteString
b2
$$ :: ByteString -> ByteString -> ByteString
($$) b1 :: ByteString
b1 b2 :: ByteString
b2 = ByteString
b1 ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
pack "\n" ByteString -> ByteString -> ByteString
<> ByteString
b2
hcat :: [ByteString] -> ByteString
hcat = [ByteString] -> ByteString
Data.ByteString.Lazy.Char8.concat
hsep :: [ByteString] -> ByteString
hsep = ByteString -> [ByteString] -> ByteString
Data.ByteString.Lazy.Char8.intercalate (Char -> ByteString
singleton ' ')
vcat :: [ByteString] -> ByteString
vcat = ByteString -> [ByteString] -> ByteString
Data.ByteString.Lazy.Char8.intercalate (Char -> ByteString
singleton '\n')
sep :: [ByteString] -> ByteString
sep = [ByteString] -> ByteString
hsep
text :: [Char] -> ByteString
text :: [Char] -> ByteString
text = [Char] -> ByteString
pack
fsep :: [ByteString] -> ByteString
fsep = [ByteString] -> ByteString
sep
nest :: Int -> ByteString -> ByteString
nest _ b :: ByteString
b = [Char] -> ByteString
pack " " ByteString -> ByteString -> ByteString
<> ByteString
b
parens :: ByteString -> ByteString
parens :: ByteString -> ByteString
parens p :: ByteString
p = [Char] -> ByteString
pack "(" ByteString -> ByteString -> ByteString
<> ByteString
p ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
pack ")"
document :: Document i -> ByteString
prolog :: Prolog -> ByteString
xmldecl :: XMLDecl -> ByteString
misc :: Misc -> ByteString
sddecl :: Bool -> ByteString
doctypedecl :: DocTypeDecl -> ByteString
markupdecl :: MarkupDecl -> ByteString
cp :: CP -> ByteString
element :: Element i -> ByteString
attribute :: Attribute -> ByteString
content :: Content i -> ByteString
document :: Document i -> ByteString
document (Document p :: Prolog
p _ e :: Element i
e m :: [Misc]
m)= Prolog -> ByteString
prolog Prolog
p ByteString -> ByteString -> ByteString
$$ Element i -> ByteString
forall i. Element i -> ByteString
element Element i
e ByteString -> ByteString -> ByteString
$$ [ByteString] -> ByteString
vcat ((Misc -> ByteString) -> [Misc] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map Misc -> ByteString
misc [Misc]
m)
prolog :: Prolog -> ByteString
prolog (Prolog x :: Maybe XMLDecl
x m1 :: [Misc]
m1 dtd :: Maybe DocTypeDecl
dtd m2 :: [Misc]
m2)= (XMLDecl -> ByteString) -> Maybe XMLDecl -> ByteString
forall t. (t -> ByteString) -> Maybe t -> ByteString
maybe XMLDecl -> ByteString
xmldecl Maybe XMLDecl
x ByteString -> ByteString -> ByteString
$$
[ByteString] -> ByteString
vcat ((Misc -> ByteString) -> [Misc] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map Misc -> ByteString
misc [Misc]
m1) ByteString -> ByteString -> ByteString
$$
(DocTypeDecl -> ByteString) -> Maybe DocTypeDecl -> ByteString
forall t. (t -> ByteString) -> Maybe t -> ByteString
maybe DocTypeDecl -> ByteString
doctypedecl Maybe DocTypeDecl
dtd ByteString -> ByteString -> ByteString
$$
[ByteString] -> ByteString
vcat ((Misc -> ByteString) -> [Misc] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map Misc -> ByteString
misc [Misc]
m2)
xmldecl :: XMLDecl -> ByteString
xmldecl (XMLDecl v :: [Char]
v e :: Maybe EncodingDecl
e sd :: Maybe SDDecl
sd) = [Char] -> ByteString
text "<?xml version='" ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text [Char]
v ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text "'" ByteString -> ByteString -> ByteString
<+>
(EncodingDecl -> ByteString) -> Maybe EncodingDecl -> ByteString
forall t. (t -> ByteString) -> Maybe t -> ByteString
maybe EncodingDecl -> ByteString
encodingdecl Maybe EncodingDecl
e ByteString -> ByteString -> ByteString
<+>
(SDDecl -> ByteString) -> Maybe SDDecl -> ByteString
forall t. (t -> ByteString) -> Maybe t -> ByteString
maybe SDDecl -> ByteString
sddecl Maybe SDDecl
sd ByteString -> ByteString -> ByteString
<+>
[Char] -> ByteString
text "?>"
misc :: Misc -> ByteString
misc (Comment s :: [Char]
s) = [Char] -> ByteString
text "<!--" ByteString -> ByteString -> ByteString
<+> [Char] -> ByteString
text [Char]
s ByteString -> ByteString -> ByteString
<+> [Char] -> ByteString
text "-->"
misc (PI (n :: [Char]
n,s :: [Char]
s)) = [Char] -> ByteString
text "<?" ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text [Char]
n ByteString -> ByteString -> ByteString
<+> [Char] -> ByteString
text [Char]
s ByteString -> ByteString -> ByteString
<+> [Char] -> ByteString
text "?>"
sddecl :: SDDecl -> ByteString
sddecl sd :: SDDecl
sd | SDDecl
sd = [Char] -> ByteString
text "standalone='yes'"
| SDDecl
otherwise = [Char] -> ByteString
text "standalone='no'"
doctypedecl :: DocTypeDecl -> ByteString
doctypedecl (DTD n :: QName
n eid :: Maybe ExternalID
eid ds :: [MarkupDecl]
ds) = if [MarkupDecl] -> SDDecl
forall (t :: * -> *) a. Foldable t => t a -> SDDecl
Prelude.null [MarkupDecl]
ds then
ByteString
hd ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text ">"
else ByteString
hd ByteString -> ByteString -> ByteString
<+> [Char] -> ByteString
text " [" ByteString -> ByteString -> ByteString
$$
[ByteString] -> ByteString
vcat ((MarkupDecl -> ByteString) -> [MarkupDecl] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map MarkupDecl -> ByteString
markupdecl [MarkupDecl]
ds) ByteString -> ByteString -> ByteString
$$ [Char] -> ByteString
text "]>"
where hd :: ByteString
hd = [Char] -> ByteString
text "<!DOCTYPE" ByteString -> ByteString -> ByteString
<+> QName -> ByteString
qname QName
n ByteString -> ByteString -> ByteString
<+>
(ExternalID -> ByteString) -> Maybe ExternalID -> ByteString
forall t. (t -> ByteString) -> Maybe t -> ByteString
maybe ExternalID -> ByteString
externalid Maybe ExternalID
eid
markupdecl :: MarkupDecl -> ByteString
markupdecl (Element e :: ElementDecl
e) = ElementDecl -> ByteString
elementdecl ElementDecl
e
markupdecl (AttList a :: AttListDecl
a) = AttListDecl -> ByteString
attlistdecl AttListDecl
a
markupdecl (Entity e :: EntityDecl
e) = EntityDecl -> ByteString
entitydecl EntityDecl
e
markupdecl (Notation n :: NotationDecl
n) = NotationDecl -> ByteString
notationdecl NotationDecl
n
markupdecl (MarkupMisc m :: Misc
m) = Misc -> ByteString
misc Misc
m
element :: Element i -> ByteString
element (Elem n :: QName
n as :: [Attribute]
as []) = [Char] -> ByteString
text "<" ByteString -> ByteString -> ByteString
<> QName -> ByteString
qname QName
n ByteString -> ByteString -> ByteString
<+>
[ByteString] -> ByteString
fsep ((Attribute -> ByteString) -> [Attribute] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map Attribute -> ByteString
attribute [Attribute]
as) ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text "/>"
element e :: Element i
e@(Elem n :: QName
n as :: [Attribute]
as cs :: [Content i]
cs)
| Content i -> SDDecl
forall t. Content t -> SDDecl
isText ([Content i] -> Content i
forall a. [a] -> a
head [Content i]
cs) = [Char] -> ByteString
text "<" ByteString -> ByteString -> ByteString
<> QName -> ByteString
qname QName
n ByteString -> ByteString -> ByteString
<+> [ByteString] -> ByteString
fsep ((Attribute -> ByteString) -> [Attribute] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map Attribute -> ByteString
attribute [Attribute]
as) ByteString -> ByteString -> ByteString
<>
[Char] -> ByteString
text ">" ByteString -> ByteString -> ByteString
<> [ByteString] -> ByteString
hcat ((Content i -> ByteString) -> [Content i] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map Content i -> ByteString
forall i. Content i -> ByteString
content [Content i]
cs) ByteString -> ByteString -> ByteString
<>
[Char] -> ByteString
text "</" ByteString -> ByteString -> ByteString
<> QName -> ByteString
qname QName
n ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text ">"
| SDDecl
otherwise = let (d :: ByteString
d,c :: ByteString
c) = Element i -> ByteString -> (ByteString, ByteString)
forall t. Element t -> ByteString -> (ByteString, ByteString)
carryelem Element i
e ByteString
empty
in ByteString
d ByteString -> ByteString -> ByteString
<> ByteString
c
isText :: Content t -> Bool
isText :: Content t -> SDDecl
isText (CString _ _ _) = SDDecl
True
isText (CRef _ _) = SDDecl
True
isText _ = SDDecl
False
carryelem :: Element t -> ByteString -> (ByteString, ByteString)
carryelem :: Element t -> ByteString -> (ByteString, ByteString)
carryelem (Elem n :: QName
n as :: [Attribute]
as []) c :: ByteString
c
= ( ByteString
c ByteString -> ByteString -> ByteString
<>
[Char] -> ByteString
text "<" ByteString -> ByteString -> ByteString
<> QName -> ByteString
qname QName
n ByteString -> ByteString -> ByteString
<+> [ByteString] -> ByteString
fsep ((Attribute -> ByteString) -> [Attribute] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map Attribute -> ByteString
attribute [Attribute]
as)
, [Char] -> ByteString
text "/>")
carryelem (Elem n :: QName
n as :: [Attribute]
as cs :: [Content t]
cs) c :: ByteString
c
| SDDecl
otherwise = let (cs0 :: [ByteString]
cs0,d0 :: ByteString
d0) = (Content t -> ByteString -> (ByteString, ByteString))
-> [Content t] -> ByteString -> ([ByteString], ByteString)
forall a c b. (a -> c -> (b, c)) -> [a] -> c -> ([b], c)
carryscan Content t -> ByteString -> (ByteString, ByteString)
forall t. Content t -> ByteString -> (ByteString, ByteString)
carrycontent [Content t]
cs ([Char] -> ByteString
text ">")
in
( ByteString
c ByteString -> ByteString -> ByteString
<>
[Char] -> ByteString
text "<" ByteString -> ByteString -> ByteString
<> QName -> ByteString
qname QName
n ByteString -> ByteString -> ByteString
<+> [ByteString] -> ByteString
fsep ((Attribute -> ByteString) -> [Attribute] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map Attribute -> ByteString
attribute [Attribute]
as) ByteString -> ByteString -> ByteString
$$
Int -> ByteString -> ByteString
nest 2 ([ByteString] -> ByteString
vcat [ByteString]
cs0) ByteString -> ByteString -> ByteString
<>
ByteString
d0 ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text "</" ByteString -> ByteString -> ByteString
<> QName -> ByteString
qname QName
n
, [Char] -> ByteString
text ">")
carrycontent :: Content t -> ByteString -> (ByteString, ByteString)
carrycontent :: Content t -> ByteString -> (ByteString, ByteString)
carrycontent (CElem e :: Element t
e _) c :: ByteString
c = Element t -> ByteString -> (ByteString, ByteString)
forall t. Element t -> ByteString -> (ByteString, ByteString)
carryelem Element t
e ByteString
c
carrycontent (CString False s :: [Char]
s _) c :: ByteString
c = (ByteString
c ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
chardata [Char]
s, ByteString
empty)
carrycontent (CString True s :: [Char]
s _) c :: ByteString
c = (ByteString
c ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
cdsect [Char]
s, ByteString
empty)
carrycontent (CRef r :: Reference
r _) c :: ByteString
c = (ByteString
c ByteString -> ByteString -> ByteString
<> Reference -> ByteString
reference Reference
r, ByteString
empty)
carrycontent (CMisc m :: Misc
m _) c :: ByteString
c = (ByteString
c ByteString -> ByteString -> ByteString
<> Misc -> ByteString
misc Misc
m, ByteString
empty)
carryscan :: (a->c->(b,c)) -> [a] -> c -> ([b],c)
carryscan :: (a -> c -> (b, c)) -> [a] -> c -> ([b], c)
carryscan _ [] c :: c
c = ([],c
c)
carryscan f :: a -> c -> (b, c)
f (a :: a
a:as :: [a]
as) c :: c
c = let (b :: b
b, c0 :: c
c0) = a -> c -> (b, c)
f a
a c
c
(bs :: [b]
bs,c1 :: c
c1) = (a -> c -> (b, c)) -> [a] -> c -> ([b], c)
forall a c b. (a -> c -> (b, c)) -> [a] -> c -> ([b], c)
carryscan a -> c -> (b, c)
f [a]
as c
c0
in (b
bb -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
bs, c
c1)
attribute :: Attribute -> ByteString
attribute (n :: QName
n,v :: AttValue
v) = [Char] -> ByteString
text (QName -> [Char]
printableName QName
n) ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text "=" ByteString -> ByteString -> ByteString
<> AttValue -> ByteString
attvalue AttValue
v
content :: Content i -> ByteString
content (CElem e :: Element i
e _) = Element i -> ByteString
forall i. Element i -> ByteString
element Element i
e
content (CString False s :: [Char]
s _) = [Char] -> ByteString
chardata [Char]
s
content (CString True s :: [Char]
s _) = [Char] -> ByteString
cdsect [Char]
s
content (CRef r :: Reference
r _) = Reference -> ByteString
reference Reference
r
content (CMisc m :: Misc
m _) = Misc -> ByteString
misc Misc
m
elementdecl :: ElementDecl -> ByteString
elementdecl :: ElementDecl -> ByteString
elementdecl (ElementDecl n :: QName
n cs :: ContentSpec
cs) = [Char] -> ByteString
text "<!ELEMENT" ByteString -> ByteString -> ByteString
<+> QName -> ByteString
qname QName
n ByteString -> ByteString -> ByteString
<+>
ContentSpec -> ByteString
contentspec ContentSpec
cs ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text ">"
contentspec :: ContentSpec -> ByteString
contentspec :: ContentSpec -> ByteString
contentspec EMPTY = [Char] -> ByteString
text "EMPTY"
contentspec ANY = [Char] -> ByteString
text "ANY"
contentspec (Mixed m :: Mixed
m) = Mixed -> ByteString
mixed Mixed
m
contentspec (ContentSpec c :: CP
c) = CP -> ByteString
cp CP
c
cp :: CP -> ByteString
cp (TagName n :: QName
n m :: Modifier
m) = QName -> ByteString
qname QName
n ByteString -> ByteString -> ByteString
<> Modifier -> ByteString
modifier Modifier
m
cp (Choice cs :: [CP]
cs m :: Modifier
m) = ByteString -> ByteString
parens ([ByteString] -> ByteString
hcat (ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
intersperse ([Char] -> ByteString
text "|") ((CP -> ByteString) -> [CP] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map CP -> ByteString
cp [CP]
cs))) ByteString -> ByteString -> ByteString
<>
Modifier -> ByteString
modifier Modifier
m
cp (Seq cs :: [CP]
cs m :: Modifier
m) = ByteString -> ByteString
parens ([ByteString] -> ByteString
hcat (ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
intersperse ([Char] -> ByteString
text ",") ((CP -> ByteString) -> [CP] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map CP -> ByteString
cp [CP]
cs))) ByteString -> ByteString -> ByteString
<>
Modifier -> ByteString
modifier Modifier
m
modifier :: Modifier -> ByteString
modifier :: Modifier -> ByteString
modifier None = ByteString
empty
modifier Query = [Char] -> ByteString
text "?"
modifier Star = [Char] -> ByteString
text "*"
modifier Plus = [Char] -> ByteString
text "+"
mixed :: Mixed -> ByteString
mixed :: Mixed -> ByteString
mixed PCDATA = [Char] -> ByteString
text "(#PCDATA)"
mixed (PCDATAplus ns :: [QName]
ns) = [Char] -> ByteString
text "(#PCDATA |" ByteString -> ByteString -> ByteString
<+>
[ByteString] -> ByteString
hcat (ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
intersperse ([Char] -> ByteString
text "|") ((QName -> ByteString) -> [QName] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map QName -> ByteString
qname [QName]
ns)) ByteString -> ByteString -> ByteString
<>
[Char] -> ByteString
text ")*"
attlistdecl :: AttListDecl -> ByteString
attlistdecl :: AttListDecl -> ByteString
attlistdecl (AttListDecl n :: QName
n ds :: [AttDef]
ds) = [Char] -> ByteString
text "<!ATTLIST" ByteString -> ByteString -> ByteString
<+> QName -> ByteString
qname QName
n ByteString -> ByteString -> ByteString
<+>
[ByteString] -> ByteString
fsep ((AttDef -> ByteString) -> [AttDef] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map AttDef -> ByteString
attdef [AttDef]
ds) ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text ">"
attdef :: AttDef -> ByteString
attdef :: AttDef -> ByteString
attdef (AttDef n :: QName
n t :: AttType
t d :: DefaultDecl
d) = QName -> ByteString
qname QName
n ByteString -> ByteString -> ByteString
<+> AttType -> ByteString
atttype AttType
t ByteString -> ByteString -> ByteString
<+> DefaultDecl -> ByteString
defaultdecl DefaultDecl
d
atttype :: AttType -> ByteString
atttype :: AttType -> ByteString
atttype StringType = [Char] -> ByteString
text "CDATA"
atttype (TokenizedType t :: TokenizedType
t) = TokenizedType -> ByteString
tokenizedtype TokenizedType
t
atttype (EnumeratedType t :: EnumeratedType
t) = EnumeratedType -> ByteString
enumeratedtype EnumeratedType
t
tokenizedtype :: TokenizedType -> ByteString
tokenizedtype :: TokenizedType -> ByteString
tokenizedtype ID = [Char] -> ByteString
text "ID"
tokenizedtype IDREF = [Char] -> ByteString
text "IDREF"
tokenizedtype IDREFS = [Char] -> ByteString
text "IDREFS"
tokenizedtype ENTITY = [Char] -> ByteString
text "ENTITY"
tokenizedtype ENTITIES = [Char] -> ByteString
text "ENTITIES"
tokenizedtype NMTOKEN = [Char] -> ByteString
text "NMTOKEN"
tokenizedtype NMTOKENS = [Char] -> ByteString
text "NMTOKENS"
enumeratedtype :: EnumeratedType -> ByteString
enumeratedtype :: EnumeratedType -> ByteString
enumeratedtype (NotationType n :: NotationType
n)= NotationType -> ByteString
notationtype NotationType
n
enumeratedtype (Enumeration e :: NotationType
e) = NotationType -> ByteString
enumeration NotationType
e
notationtype :: [[Char]] -> ByteString
notationtype :: NotationType -> ByteString
notationtype ns :: NotationType
ns = [Char] -> ByteString
text "NOTATION" ByteString -> ByteString -> ByteString
<+>
ByteString -> ByteString
parens ([ByteString] -> ByteString
hcat (ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
intersperse ([Char] -> ByteString
text "|") (([Char] -> ByteString) -> NotationType -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map [Char] -> ByteString
text NotationType
ns)))
enumeration :: [[Char]] -> ByteString
enumeration :: NotationType -> ByteString
enumeration ns :: NotationType
ns = ByteString -> ByteString
parens ([ByteString] -> ByteString
hcat (ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
intersperse ([Char] -> ByteString
text "|") (([Char] -> ByteString) -> NotationType -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map [Char] -> ByteString
nmtoken NotationType
ns)))
defaultdecl :: DefaultDecl -> ByteString
defaultdecl :: DefaultDecl -> ByteString
defaultdecl REQUIRED = [Char] -> ByteString
text "#REQUIRED"
defaultdecl IMPLIED = [Char] -> ByteString
text "#IMPLIED"
defaultdecl (DefaultTo a :: AttValue
a f :: Maybe FIXED
f) = (FIXED -> ByteString) -> Maybe FIXED -> ByteString
forall t. (t -> ByteString) -> Maybe t -> ByteString
maybe (ByteString -> FIXED -> ByteString
forall a b. a -> b -> a
const ([Char] -> ByteString
text "#FIXED")) Maybe FIXED
f ByteString -> ByteString -> ByteString
<+> AttValue -> ByteString
attvalue AttValue
a
reference :: Reference -> ByteString
reference :: Reference -> ByteString
reference (RefEntity er :: [Char]
er) = [Char] -> ByteString
entityref [Char]
er
reference (RefChar cr :: Int
cr) = Int -> ByteString
forall a. Show a => a -> ByteString
charref Int
cr
entityref :: [Char] -> ByteString
entityref :: [Char] -> ByteString
entityref n :: [Char]
n = [Char] -> ByteString
text "&" ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text [Char]
n ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text ";"
charref :: (Show a) => a -> ByteString
charref :: a -> ByteString
charref c :: a
c = [Char] -> ByteString
text "&#" ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text (a -> [Char]
forall a. Show a => a -> [Char]
show a
c) ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text ";"
entitydecl :: EntityDecl -> ByteString
entitydecl :: EntityDecl -> ByteString
entitydecl (EntityGEDecl d :: GEDecl
d) = GEDecl -> ByteString
gedecl GEDecl
d
entitydecl (EntityPEDecl d :: PEDecl
d) = PEDecl -> ByteString
pedecl PEDecl
d
gedecl :: GEDecl -> ByteString
gedecl :: GEDecl -> ByteString
gedecl (GEDecl n :: [Char]
n ed :: EntityDef
ed) = [Char] -> ByteString
text "<!ENTITY" ByteString -> ByteString -> ByteString
<+> [Char] -> ByteString
text [Char]
n ByteString -> ByteString -> ByteString
<+> EntityDef -> ByteString
entitydef EntityDef
ed ByteString -> ByteString -> ByteString
<>
[Char] -> ByteString
text ">"
pedecl :: PEDecl -> ByteString
pedecl :: PEDecl -> ByteString
pedecl (PEDecl n :: [Char]
n pd :: PEDef
pd) = [Char] -> ByteString
text "<!ENTITY %" ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text [Char]
n ByteString -> ByteString -> ByteString
<+> PEDef -> ByteString
pedef PEDef
pd ByteString -> ByteString -> ByteString
<>
[Char] -> ByteString
text ">"
entitydef :: EntityDef -> ByteString
entitydef :: EntityDef -> ByteString
entitydef (DefEntityValue ew :: EntityValue
ew) = EntityValue -> ByteString
entityvalue EntityValue
ew
entitydef (DefExternalID i :: ExternalID
i nd :: Maybe NDataDecl
nd) = ExternalID -> ByteString
externalid ExternalID
i ByteString -> ByteString -> ByteString
<+> (NDataDecl -> ByteString) -> Maybe NDataDecl -> ByteString
forall t. (t -> ByteString) -> Maybe t -> ByteString
maybe NDataDecl -> ByteString
ndatadecl Maybe NDataDecl
nd
pedef :: PEDef -> ByteString
pedef :: PEDef -> ByteString
pedef (PEDefEntityValue ew :: EntityValue
ew) = EntityValue -> ByteString
entityvalue EntityValue
ew
pedef (PEDefExternalID eid :: ExternalID
eid) = ExternalID -> ByteString
externalid ExternalID
eid
externalid :: ExternalID -> ByteString
externalid :: ExternalID -> ByteString
externalid (SYSTEM sl :: SystemLiteral
sl) = [Char] -> ByteString
text "SYSTEM" ByteString -> ByteString -> ByteString
<+> SystemLiteral -> ByteString
systemliteral SystemLiteral
sl
externalid (PUBLIC i :: PubidLiteral
i sl :: SystemLiteral
sl) = [Char] -> ByteString
text "PUBLIC" ByteString -> ByteString -> ByteString
<+> PubidLiteral -> ByteString
pubidliteral PubidLiteral
i ByteString -> ByteString -> ByteString
<+>
SystemLiteral -> ByteString
systemliteral SystemLiteral
sl
ndatadecl :: NDataDecl -> ByteString
ndatadecl :: NDataDecl -> ByteString
ndatadecl (NDATA n :: [Char]
n) = [Char] -> ByteString
text "NDATA" ByteString -> ByteString -> ByteString
<+> [Char] -> ByteString
text [Char]
n
notationdecl :: NotationDecl -> ByteString
notationdecl :: NotationDecl -> ByteString
notationdecl (NOTATION n :: [Char]
n e :: Either ExternalID PublicID
e) = [Char] -> ByteString
text "<!NOTATION" ByteString -> ByteString -> ByteString
<+> [Char] -> ByteString
text [Char]
n ByteString -> ByteString -> ByteString
<+>
(ExternalID -> ByteString)
-> (PublicID -> ByteString)
-> Either ExternalID PublicID
-> ByteString
forall t t1 t2. (t -> t1) -> (t2 -> t1) -> Either t t2 -> t1
either ExternalID -> ByteString
externalid PublicID -> ByteString
publicid Either ExternalID PublicID
e ByteString -> ByteString -> ByteString
<>
[Char] -> ByteString
text ">"
publicid :: PublicID -> ByteString
publicid :: PublicID -> ByteString
publicid (PUBLICID p :: PubidLiteral
p) = [Char] -> ByteString
text "PUBLICID" ByteString -> ByteString -> ByteString
<+> PubidLiteral -> ByteString
pubidliteral PubidLiteral
p
encodingdecl :: EncodingDecl -> ByteString
encodingdecl :: EncodingDecl -> ByteString
encodingdecl (EncodingDecl s :: [Char]
s) = [Char] -> ByteString
text "encoding='" ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text [Char]
s ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text "'"
nmtoken :: [Char] -> ByteString
nmtoken :: [Char] -> ByteString
nmtoken s :: [Char]
s = [Char] -> ByteString
text [Char]
s
attvalue :: AttValue -> ByteString
attvalue :: AttValue -> ByteString
attvalue (AttValue esr :: [Either [Char] Reference]
esr) = [Char] -> ByteString
text "\"" ByteString -> ByteString -> ByteString
<>
[ByteString] -> ByteString
hcat ((Either [Char] Reference -> ByteString)
-> [Either [Char] Reference] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map (([Char] -> ByteString)
-> (Reference -> ByteString)
-> Either [Char] Reference
-> ByteString
forall t t1 t2. (t -> t1) -> (t2 -> t1) -> Either t t2 -> t1
either [Char] -> ByteString
text Reference -> ByteString
reference) [Either [Char] Reference]
esr) ByteString -> ByteString -> ByteString
<>
[Char] -> ByteString
text "\""
entityvalue :: EntityValue -> ByteString
entityvalue :: EntityValue -> ByteString
entityvalue (EntityValue evs :: [EV]
evs)
| [EV] -> SDDecl
containsDoubleQuote [EV]
evs = [Char] -> ByteString
text "'" ByteString -> ByteString -> ByteString
<> [ByteString] -> ByteString
hcat ((EV -> ByteString) -> [EV] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map EV -> ByteString
ev [EV]
evs) ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text "'"
| SDDecl
otherwise = [Char] -> ByteString
text "\"" ByteString -> ByteString -> ByteString
<> [ByteString] -> ByteString
hcat ((EV -> ByteString) -> [EV] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map EV -> ByteString
ev [EV]
evs) ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text "\""
ev :: EV -> ByteString
ev :: EV -> ByteString
ev (EVString s :: [Char]
s) = [Char] -> ByteString
text [Char]
s
ev (EVRef r :: Reference
r) = Reference -> ByteString
reference Reference
r
pubidliteral :: PubidLiteral -> ByteString
pubidliteral :: PubidLiteral -> ByteString
pubidliteral (PubidLiteral s :: [Char]
s)
| Char -> Char
forall a a1. (Enum a, Enum a1) => a1 -> a
toWord8 '"' Char -> ByteString -> SDDecl
`elem` ([Char] -> ByteString
pack [Char]
s) = [Char] -> ByteString
text "'" ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text [Char]
s ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text "'"
| SDDecl
otherwise = [Char] -> ByteString
text "\"" ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text [Char]
s ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text "\""
systemliteral :: SystemLiteral -> ByteString
systemliteral :: SystemLiteral -> ByteString
systemliteral (SystemLiteral s :: [Char]
s)
| Char -> Char
forall a a1. (Enum a, Enum a1) => a1 -> a
toWord8 '"' Char -> ByteString -> SDDecl
`elem` ([Char] -> ByteString
pack [Char]
s) = [Char] -> ByteString
text "'" ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text [Char]
s ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text "'"
| SDDecl
otherwise = [Char] -> ByteString
text "\"" ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text [Char]
s ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text "\""
chardata, cdsect :: [Char] -> ByteString
chardata :: [Char] -> ByteString
chardata s :: [Char]
s = [Char] -> ByteString
text [Char]
s
cdsect :: [Char] -> ByteString
cdsect c :: [Char]
c = [Char] -> ByteString
text "<![CDATA[" ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
chardata [Char]
c ByteString -> ByteString -> ByteString
<> [Char] -> ByteString
text "]]>"
qname :: QName -> ByteString
qname n :: QName
n = [Char] -> ByteString
text (QName -> [Char]
printableName QName
n)
toWord8 :: (Enum a, Enum a1) => a1 -> a
toWord8 :: a1 -> a
toWord8 = Int -> a
forall a. Enum a => Int -> a
toEnum (Int -> a) -> (a1 -> Int) -> a1 -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a1 -> Int
forall a. Enum a => a -> Int
fromEnum
containsDoubleQuote :: [EV] -> Bool
containsDoubleQuote :: [EV] -> SDDecl
containsDoubleQuote evs :: [EV]
evs = (EV -> SDDecl) -> [EV] -> SDDecl
forall (t :: * -> *) a.
Foldable t =>
(a -> SDDecl) -> t a -> SDDecl
any EV -> SDDecl
csq [EV]
evs
where csq :: EV -> SDDecl
csq (EVString s :: [Char]
s) = Char -> Char
forall a a1. (Enum a, Enum a1) => a1 -> a
toWord8 '"' Char -> ByteString -> SDDecl
`elem` ([Char] -> ByteString
pack [Char]
s)
csq _ = SDDecl
False