-- ------------------------------------------------------------

{- |
   Module     : Text.XML.HXT.Parser.XmlDTDParser
   Copyright  : Copyright (C) 2005 Uwe Schmidt
   License    : MIT

   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
   Stability  : experimental
   Portability: portable

   Parsec parser for DTD declarations for ELEMENT, ATTLIST, ENTITY and NOTATION declarations

-}

-- ------------------------------------------------------------

module Text.XML.HXT.Parser.XmlDTDParser
    ( parseXmlDTDdecl
    , parseXmlDTDdeclPart
    , parseXmlDTDEntityValue
    , elementDecl
    , attlistDecl
    , entityDecl
    , notationDecl
    )
where

import Data.Maybe

import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Pos

import Text.XML.HXT.DOM.Interface

import Text.XML.HXT.DOM.ShowXml
    ( xshow
    )
import Text.XML.HXT.DOM.XmlNode                        ( mkDTDElem'
                                                       , mkText'
                                                       , mkError'
                                                       , isText
                                                       , isDTD
                                                       , getText
                                                       , getDTDPart
                                                       , getDTDAttrl
                                                       , getChildren
                                                       , setChildren
                                                       )
import qualified Text.XML.HXT.Parser.XmlTokenParser    as XT

import           Text.XML.HXT.Parser.XmlCharParser     ( XParser
                                                       , XPState(..)
                                                       , withoutNormNewline
                                                       )

import qualified Text.XML.HXT.Parser.XmlCharParser     as XC
                                                       ( xmlSpaceChar )

import qualified Text.XML.HXT.Parser.XmlDTDTokenParser as XD
                                                       ( dtdToken )

-----------------------------------------------------------
--
-- all parsers dealing with whitespace will be redefined
-- to handle parameter entity substitution

type LocalState = (Int, [(Int, String, SourcePos)])

type SParser a  = XParser LocalState a

initialState    :: SourcePos -> XPState LocalState
initialState :: SourcePos -> XPState LocalState
initialState SourcePos
p  = LocalState -> XPState LocalState
forall a. a -> XPState a
withoutNormNewline (Int
0, [(Int
0, SourcePos -> [Char]
sourceName SourcePos
p, SourcePos
p)])

updateLocalState :: (LocalState -> LocalState) -> SParser ()
updateLocalState :: (LocalState -> LocalState) -> SParser ()
updateLocalState LocalState -> LocalState
upd
                = (XPState LocalState -> XPState LocalState) -> SParser ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((XPState LocalState -> XPState LocalState) -> SParser ())
-> (XPState LocalState -> XPState LocalState) -> SParser ()
forall a b. (a -> b) -> a -> b
$ \ XPState LocalState
xps -> XPState LocalState
xps { xps_userState = upd $ xps_userState xps }

pushPar         :: String -> SParser ()
pushPar :: [Char] -> SParser ()
pushPar [Char]
n       = do
                  SourcePos
p <- ParsecT [Char] (XPState LocalState) Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
                  (LocalState -> LocalState) -> SParser ()
updateLocalState (\ (Int
i, [(Int, [Char], SourcePos)]
s) -> (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1, (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1, [Char]
n, SourcePos
p) (Int, [Char], SourcePos)
-> [(Int, [Char], SourcePos)] -> [(Int, [Char], SourcePos)]
forall a. a -> [a] -> [a]
: [(Int, [Char], SourcePos)]
s))
                  SourcePos -> SParser ()
forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
setPosition ( [Char] -> Int -> Int -> SourcePos
newPos (SourcePos -> [Char]
sourceName SourcePos
p [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" (line " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show (SourcePos -> Int
sourceLine SourcePos
p) [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
", column " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show (SourcePos -> Int
sourceColumn SourcePos
p) [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
") in content of parameter entity ref %" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
n [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
";") Int
1 Int
1)

popPar          :: SParser ()
popPar :: SParser ()
popPar          = do
                  SourcePos
oldPos <- ParsecT [Char] (XPState LocalState) Identity SourcePos
getPos
                  (LocalState -> LocalState) -> SParser ()
updateLocalState LocalState -> LocalState
forall {a} {b} {c}. Num a => (a, [(a, b, c)]) -> (a, [(a, b, c)])
pop
                  SourcePos -> SParser ()
forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
setPosition SourcePos
oldPos
                where
                pop :: (a, [(a, b, c)]) -> (a, [(a, b, c)])
pop (a
i, [(a
_, b
s, c
p)]) = (a
ia -> a -> a
forall a. Num a => a -> a -> a
+a
1, [(a
ia -> a -> a
forall a. Num a => a -> a -> a
+a
1, b
s, c
p)])     -- if param entity substitution is correctly implemented, this case does not occur
                pop (a
i, (a, b, c)
_t:[(a, b, c)]
s)        = (a
i, [(a, b, c)]
s)
                pop (a
_i, [])         = (a, [(a, b, c)])
forall a. HasCallStack => a
undefined                -- stack is never empty

getParNo        :: SParser Int
getParNo :: SParser Int
getParNo        = do
                  XPState LocalState
s <- ParsecT [Char] (XPState LocalState) Identity (XPState LocalState)
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
                  let (Int
_i, (Int
top, [Char]
_n, SourcePos
_p) : [(Int, [Char], SourcePos)]
_s) = XPState LocalState -> LocalState
forall s. XPState s -> s
xps_userState XPState LocalState
s
                  Int -> SParser Int
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return Int
top

getPos          :: SParser SourcePos
getPos :: ParsecT [Char] (XPState LocalState) Identity SourcePos
getPos          = do
                  XPState LocalState
s <- ParsecT [Char] (XPState LocalState) Identity (XPState LocalState)
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
                  let (Int
_i, (Int
_top, [Char]
_n, SourcePos
p) : [(Int, [Char], SourcePos)]
_s) = XPState LocalState -> LocalState
forall s. XPState s -> s
xps_userState XPState LocalState
s
                  SourcePos -> ParsecT [Char] (XPState LocalState) Identity SourcePos
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return SourcePos
p

delPE   :: SParser ()
delPE :: SParser ()
delPE   = do
          Char
_ <- Char -> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\0'
          () -> SParser ()
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

startPE :: SParser ()
startPE :: SParser ()
startPE
    = do
      SParser () -> SParser ()
forall tok st a. GenParser tok st a -> GenParser tok st a
try ( do
            SParser ()
delPE
            [Char]
n <- ParsecT [Char] (XPState LocalState) Identity Char
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ((Char -> Bool) -> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\0'))
            SParser ()
delPE
            [Char] -> SParser ()
pushPar [Char]
n
          )

endPE   :: SParser ()
endPE :: SParser ()
endPE
    = do
      SParser () -> SParser ()
forall tok st a. GenParser tok st a -> GenParser tok st a
try (do
           SParser ()
delPE
           SParser ()
delPE
           SParser ()
popPar
          )

inSamePE        :: SParser a -> SParser a
inSamePE :: forall a. SParser a -> SParser a
inSamePE SParser a
p
    = do
      Int
i <- SParser Int
getParNo
      a
r <- SParser a
p
      Int
j <- SParser Int
getParNo
      if (Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
j)
         then a -> SParser a
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return a
r
         else [Char] -> SParser a
forall a. [Char] -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char] -> SParser a) -> [Char] -> SParser a
forall a b. (a -> b) -> a -> b
$ [Char]
"parameter entity contents does not fit into the structure of a DTD declarations"

-- ------------------------------------------------------------

xmlSpaceChar    :: SParser ()
xmlSpaceChar :: SParser ()
xmlSpaceChar    = ( ParsecT [Char] (XPState LocalState) Identity Char
forall s. XParser s Char
XC.xmlSpaceChar
                    ParsecT [Char] (XPState LocalState) Identity Char
-> SParser () -> SParser ()
forall a b.
ParsecT [Char] (XPState LocalState) Identity a
-> ParsecT [Char] (XPState LocalState) Identity b
-> ParsecT [Char] (XPState LocalState) Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
                    () -> SParser ()
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
                  )
                  SParser () -> SParser () -> SParser ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                  SParser ()
startPE
                  SParser () -> SParser () -> SParser ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                  SParser ()
endPE
                  SParser () -> [Char] -> SParser ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"white space"

skipS           :: SParser ()
skipS :: SParser ()
skipS
    = SParser () -> SParser ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 SParser ()
xmlSpaceChar
      SParser () -> SParser () -> SParser ()
forall a b.
ParsecT [Char] (XPState LocalState) Identity a
-> ParsecT [Char] (XPState LocalState) Identity b
-> ParsecT [Char] (XPState LocalState) Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
      () -> SParser ()
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

skipS0          :: SParser ()
skipS0 :: SParser ()
skipS0
    = SParser () -> SParser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany SParser ()
xmlSpaceChar
      SParser () -> SParser () -> SParser ()
forall a b.
ParsecT [Char] (XPState LocalState) Identity a
-> ParsecT [Char] (XPState LocalState) Identity b
-> ParsecT [Char] (XPState LocalState) Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
      () -> SParser ()
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

name            :: SParser XmlTree
name :: SParser XmlTree
name
    = do
      [Char]
n <- ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.name
      XmlTree -> SParser XmlTree
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (DTDElem -> Attributes -> XmlTrees -> XmlTree
mkDTDElem' DTDElem
NAME [([Char]
a_name, [Char]
n)] [])

nmtoken         :: SParser XmlTree
nmtoken :: SParser XmlTree
nmtoken
    = do
      [Char]
n <- ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.nmtoken
      XmlTree -> SParser XmlTree
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (DTDElem -> Attributes -> XmlTrees -> XmlTree
mkDTDElem' DTDElem
NAME [([Char]
a_name, [Char]
n)] [])

-- ------------------------------------------------------------
--
-- Element Type Declarations (3.2)

elementDecl     :: SParser XmlTrees
elementDecl :: SParser XmlTrees
elementDecl
    = ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity Char
-> SParser XmlTrees
-> SParser XmlTrees
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT [Char] (XPState LocalState) Identity [Char]
 -> ParsecT [Char] (XPState LocalState) Identity [Char])
-> ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"<!ELEMENT") (Char -> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>') SParser XmlTrees
elementDeclBody

elementDeclBody :: SParser XmlTrees
elementDeclBody :: SParser XmlTrees
elementDeclBody
    = do
      SParser ()
skipS
      [Char]
n <- ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.name
      SParser ()
skipS
      (Attributes
al, XmlTrees
cl) <- SParser (Attributes, XmlTrees)
contentspec
      SParser ()
skipS0
      XmlTrees -> SParser XmlTrees
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [DTDElem -> Attributes -> XmlTrees -> XmlTree
mkDTDElem' DTDElem
ELEMENT (([Char]
a_name, [Char]
n) ([Char], [Char]) -> Attributes -> Attributes
forall a. a -> [a] -> [a]
: Attributes
al) XmlTrees
cl]

contentspec     :: SParser (Attributes, XmlTrees)
contentspec :: SParser (Attributes, XmlTrees)
contentspec
    = [Char] -> [Char] -> SParser (Attributes, XmlTrees)
forall {b} {s} {a}.
[Char]
-> b -> ParsecT [Char] (XPState s) Identity ([([Char], b)], [a])
simplespec [Char]
k_empty [Char]
v_empty
      SParser (Attributes, XmlTrees)
-> SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
      [Char] -> [Char] -> SParser (Attributes, XmlTrees)
forall {b} {s} {a}.
[Char]
-> b -> ParsecT [Char] (XPState s) Identity ([([Char], b)], [a])
simplespec [Char]
k_any [Char]
v_any
      SParser (Attributes, XmlTrees)
-> SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
      SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. SParser a -> SParser a
inSamePE SParser (Attributes, XmlTrees)
mixed
      SParser (Attributes, XmlTrees)
-> SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
      SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. SParser a -> SParser a
inSamePE SParser (Attributes, XmlTrees)
children
      SParser (Attributes, XmlTrees)
-> [Char] -> SParser (Attributes, XmlTrees)
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"content specification"
    where
    simplespec :: [Char]
-> b -> ParsecT [Char] (XPState s) Identity ([([Char], b)], [a])
simplespec [Char]
kw b
v
        = do
          [Char]
_ <- [Char] -> XParser s [Char]
forall s. [Char] -> XParser s [Char]
XT.keyword [Char]
kw
          ([([Char], b)], [a])
-> ParsecT [Char] (XPState s) Identity ([([Char], b)], [a])
forall a. a -> ParsecT [Char] (XPState s) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ([([Char]
a_type, b
v)], [])

-- ------------------------------------------------------------
--
-- Element Content (3.2.1)

children        :: SParser (Attributes, XmlTrees)
children :: SParser (Attributes, XmlTrees)
children
    = ( do
        (Attributes
al, XmlTrees
cl) <- SParser (Attributes, XmlTrees)
choiceOrSeq
        Attributes
modifier <- SParser Attributes
optOrRep
        (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ([([Char]
a_type, [Char]
v_children)], [DTDElem -> Attributes -> XmlTrees -> XmlTree
mkDTDElem' DTDElem
CONTENT (Attributes
modifier Attributes -> Attributes -> Attributes
forall a. [a] -> [a] -> [a]
++ Attributes
al) XmlTrees
cl])
      )
      SParser (Attributes, XmlTrees)
-> [Char] -> SParser (Attributes, XmlTrees)
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"element content"

optOrRep        :: SParser Attributes
optOrRep :: SParser Attributes
optOrRep
    = do
      [Char]
m <- [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [Char]
"" (ParsecT [Char] (XPState LocalState) Identity Char
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s a. XParser s a -> XParser s [a]
XT.mkList ([Char] -> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
oneOf [Char]
"?*+"))
      Attributes -> SParser Attributes
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [([Char]
a_modifier, [Char]
m)]

choiceOrSeq     :: SParser (Attributes, XmlTrees)
choiceOrSeq :: SParser (Attributes, XmlTrees)
choiceOrSeq
    = SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. SParser a -> SParser a
inSamePE (SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees))
-> SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a b. (a -> b) -> a -> b
$
      do
      (Attributes, XmlTrees)
cl <- SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall tok st a. GenParser tok st a -> GenParser tok st a
try ( do
                  SParser ()
lpar
                  SParser (Attributes, XmlTrees)
choiceOrSeqBody
                )
      SParser ()
rpar
      (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Attributes, XmlTrees)
cl

choiceOrSeqBody :: SParser (Attributes, XmlTrees)
choiceOrSeqBody :: SParser (Attributes, XmlTrees)
choiceOrSeqBody
    = do
      XmlTree
cp1 <- SParser XmlTree
cp
      XmlTree -> SParser (Attributes, XmlTrees)
choiceOrSeq1 XmlTree
cp1
    where
    choiceOrSeq1        :: XmlTree -> SParser (Attributes, XmlTrees)
    choiceOrSeq1 :: XmlTree -> SParser (Attributes, XmlTrees)
choiceOrSeq1 XmlTree
c1
        = ( do
            SParser ()
bar
            XmlTree
c2 <- SParser XmlTree
cp
            XmlTrees
cl <- SParser XmlTree -> SParser XmlTrees
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ( do
                         SParser ()
bar
                         SParser XmlTree
cp
                       )
            (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ([([Char]
a_kind, [Char]
v_choice)], (XmlTree
c1 XmlTree -> XmlTrees -> XmlTrees
forall a. a -> [a] -> [a]
: XmlTree
c2 XmlTree -> XmlTrees -> XmlTrees
forall a. a -> [a] -> [a]
: XmlTrees
cl))
          )
          SParser (Attributes, XmlTrees)
-> SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
          ( do
            XmlTrees
cl <- SParser XmlTree -> SParser XmlTrees
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ( do
                         SParser ()
comma
                         SParser XmlTree
cp
                       )
            (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ([([Char]
a_kind, [Char]
v_seq)], (XmlTree
c1 XmlTree -> XmlTrees -> XmlTrees
forall a. a -> [a] -> [a]
: XmlTrees
cl))
          )
          SParser (Attributes, XmlTrees)
-> [Char] -> SParser (Attributes, XmlTrees)
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"sequence or choice"

cp              :: SParser XmlTree
cp :: SParser XmlTree
cp
    = ( do
        XmlTree
n <- SParser XmlTree
name
        Attributes
m <- SParser Attributes
optOrRep
        XmlTree -> SParser XmlTree
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ( case Attributes
m of
                 [([Char]
_, [Char]
"")] -> XmlTree
n
                 Attributes
_         -> DTDElem -> Attributes -> XmlTrees -> XmlTree
mkDTDElem' DTDElem
CONTENT (Attributes
m Attributes -> Attributes -> Attributes
forall a. [a] -> [a] -> [a]
++ [([Char]
a_kind, [Char]
v_seq)]) [XmlTree
n]
               )
      )
      SParser XmlTree -> SParser XmlTree -> SParser XmlTree
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
      ( do
        (Attributes
al, XmlTrees
cl) <- SParser (Attributes, XmlTrees)
choiceOrSeq
        Attributes
m <- SParser Attributes
optOrRep
        XmlTree -> SParser XmlTree
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (DTDElem -> Attributes -> XmlTrees -> XmlTree
mkDTDElem' DTDElem
CONTENT (Attributes
m Attributes -> Attributes -> Attributes
forall a. [a] -> [a] -> [a]
++ Attributes
al) XmlTrees
cl)
      )

-- ------------------------------------------------------------
--
-- Mixed Content (3.2.2)

mixed           :: SParser (Attributes, XmlTrees)
mixed :: SParser (Attributes, XmlTrees)
mixed
    = ( do
        [Char]
_ <- ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall tok st a. GenParser tok st a -> GenParser tok st a
try ( do
                   SParser ()
lpar
                   [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
k_pcdata
                 )
        XmlTrees
nl <- SParser XmlTree -> SParser XmlTrees
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ( do
                     SParser ()
bar
                     SParser XmlTree
name
                   )
        SParser ()
rpar
        if XmlTrees -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null XmlTrees
nl
          then do
               Char
_ <- Char
-> ParsecT [Char] (XPState LocalState) Identity Char
-> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Char
' ' (Char -> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'*')               -- (#PCDATA) or (#PCDATA)* , both are legal
               (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ( [ ([Char]
a_type, [Char]
v_pcdata) ]
                      , []
                      )
          else do
               Char
_ <- Char -> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'*' ParsecT [Char] (XPState LocalState) Identity Char
-> [Char] -> ParsecT [Char] (XPState LocalState) Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"closing parent for mixed content (\")*\")"
               (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ( [ ([Char]
a_type, [Char]
v_mixed) ]
                      , [ DTDElem -> Attributes -> XmlTrees -> XmlTree
mkDTDElem' DTDElem
CONTENT [ ([Char]
a_modifier, [Char]
"*")
                                             , ([Char]
a_kind, [Char]
v_choice)
                                             ] XmlTrees
nl
                        ]
                      )
      )
      SParser (Attributes, XmlTrees)
-> [Char] -> SParser (Attributes, XmlTrees)
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"mixed content"

-- ------------------------------------------------------------
--
-- Attribute-List Declarations (3.3)

attlistDecl             :: SParser XmlTrees
attlistDecl :: SParser XmlTrees
attlistDecl
    = ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity Char
-> SParser XmlTrees
-> SParser XmlTrees
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT [Char] (XPState LocalState) Identity [Char]
 -> ParsecT [Char] (XPState LocalState) Identity [Char])
-> ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"<!ATTLIST") (Char -> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>') SParser XmlTrees
attlistDeclBody

attlistDeclBody         :: SParser XmlTrees
attlistDeclBody :: SParser XmlTrees
attlistDeclBody
    = do
      SParser ()
skipS
      [Char]
n <- ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.name
      [(Attributes, XmlTrees)]
al <- SParser (Attributes, XmlTrees)
-> ParsecT
     [Char] (XPState LocalState) Identity [(Attributes, XmlTrees)]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many SParser (Attributes, XmlTrees)
attDef
      SParser ()
skipS0
      XmlTrees -> SParser XmlTrees
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (((Attributes, XmlTrees) -> XmlTree)
-> [(Attributes, XmlTrees)] -> XmlTrees
forall a b. (a -> b) -> [a] -> [b]
map ([Char] -> (Attributes, XmlTrees) -> XmlTree
mkDTree [Char]
n) [(Attributes, XmlTrees)]
al)
    where
    mkDTree :: [Char] -> (Attributes, XmlTrees) -> XmlTree
mkDTree [Char]
n' (Attributes
al, XmlTrees
cl)
        = DTDElem -> Attributes -> XmlTrees -> XmlTree
mkDTDElem' DTDElem
ATTLIST (([Char]
a_name, [Char]
n') ([Char], [Char]) -> Attributes -> Attributes
forall a. a -> [a] -> [a]
: Attributes
al) XmlTrees
cl

attDef          :: SParser (Attributes, XmlTrees)
attDef :: SParser (Attributes, XmlTrees)
attDef
    = do
      [Char]
n <- ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall tok st a. GenParser tok st a -> GenParser tok st a
try ( do
                 SParser ()
skipS
                 ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.name
               ) ParsecT [Char] (XPState LocalState) Identity [Char]
-> [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"attribute name"
      SParser ()
skipS
      (Attributes
t, XmlTrees
cl) <- SParser (Attributes, XmlTrees)
attType
      SParser ()
skipS
      Attributes
d <- SParser Attributes
defaultDecl
      (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ((([Char]
a_value, [Char]
n) ([Char], [Char]) -> Attributes -> Attributes
forall a. a -> [a] -> [a]
: Attributes
d) Attributes -> Attributes -> Attributes
forall a. [a] -> [a] -> [a]
++ Attributes
t, XmlTrees
cl)

attType :: SParser (Attributes, XmlTrees)
attType :: SParser (Attributes, XmlTrees)
attType
    = SParser (Attributes, XmlTrees)
tokenizedOrStringType
      SParser (Attributes, XmlTrees)
-> SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
      SParser (Attributes, XmlTrees)
enumeration
      SParser (Attributes, XmlTrees)
-> SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
      SParser (Attributes, XmlTrees)
notationType
      SParser (Attributes, XmlTrees)
-> [Char] -> SParser (Attributes, XmlTrees)
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"attribute type"

tokenizedOrStringType   :: SParser (Attributes, XmlTrees)
tokenizedOrStringType :: SParser (Attributes, XmlTrees)
tokenizedOrStringType
    = do
      [Char]
n <- [ParsecT [Char] (XPState LocalState) Identity [Char]]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([ParsecT [Char] (XPState LocalState) Identity [Char]]
 -> ParsecT [Char] (XPState LocalState) Identity [Char])
-> [ParsecT [Char] (XPState LocalState) Identity [Char]]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall a b. (a -> b) -> a -> b
$ ([Char] -> ParsecT [Char] (XPState LocalState) Identity [Char])
-> [[Char]]
-> [ParsecT [Char] (XPState LocalState) Identity [Char]]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. [Char] -> XParser s [Char]
XT.keyword [[Char]]
typl
      (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ([([Char]
a_type, [Char]
n)], [])
      where
      typl :: [[Char]]
typl      = [ [Char]
k_cdata
                  , [Char]
k_idrefs
                  , [Char]
k_idref
                  , [Char]
k_id
                  , [Char]
k_entity
                  , [Char]
k_entities
                  , [Char]
k_nmtokens
                  , [Char]
k_nmtoken
                  ]

enumeration     :: SParser (Attributes, XmlTrees)
enumeration :: SParser (Attributes, XmlTrees)
enumeration
    = do
      XmlTrees
nl <- SParser XmlTrees -> SParser XmlTrees
forall a. SParser a -> SParser a
inSamePE (SParser () -> SParser () -> SParser XmlTrees -> SParser XmlTrees
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between SParser ()
lpar SParser ()
rpar (SParser XmlTree -> SParser () -> SParser XmlTrees
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepBy1 SParser XmlTree
nmtoken SParser ()
bar))
      (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ([([Char]
a_type, [Char]
k_enumeration)], XmlTrees
nl)

notationType    :: SParser (Attributes, XmlTrees)
notationType :: SParser (Attributes, XmlTrees)
notationType
    = do
      [Char]
_ <- [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. [Char] -> XParser s [Char]
XT.keyword [Char]
k_notation
      SParser ()
skipS
      XmlTrees
nl <- SParser XmlTrees -> SParser XmlTrees
forall a. SParser a -> SParser a
inSamePE (SParser () -> SParser () -> SParser XmlTrees -> SParser XmlTrees
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between SParser ()
lpar SParser ()
rpar ( SParser XmlTree -> SParser () -> SParser XmlTrees
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepBy1 SParser XmlTree
name SParser ()
bar ))
      (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ([([Char]
a_type, [Char]
k_notation)], XmlTrees
nl)

defaultDecl     :: SParser Attributes
defaultDecl :: SParser Attributes
defaultDecl
    = ( do
        [Char]
str <- ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT [Char] (XPState LocalState) Identity [Char]
 -> ParsecT [Char] (XPState LocalState) Identity [Char])
-> ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
k_required
        Attributes -> SParser Attributes
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [([Char]
a_kind, [Char]
str)]
      )
      SParser Attributes -> SParser Attributes -> SParser Attributes
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
      ( do
        [Char]
str <- ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT [Char] (XPState LocalState) Identity [Char]
 -> ParsecT [Char] (XPState LocalState) Identity [Char])
-> ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
k_implied
        Attributes -> SParser Attributes
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [([Char]
a_kind, [Char]
str)]
      )
      SParser Attributes -> SParser Attributes -> SParser Attributes
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
      ( do
        Attributes
l <- SParser Attributes
fixed
        XmlTrees
v <- SParser XmlTrees
forall s. XParser s XmlTrees
XT.attrValueT
        Attributes -> SParser Attributes
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (([Char]
a_default, XmlTrees -> [Char]
xshow XmlTrees
v) ([Char], [Char]) -> Attributes -> Attributes
forall a. a -> [a] -> [a]
: Attributes
l)
      )
      SParser Attributes -> [Char] -> SParser Attributes
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"default declaration"
    where
    fixed :: SParser Attributes
fixed = Attributes -> SParser Attributes -> SParser Attributes
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [([Char]
a_kind, [Char]
k_default)]
            ( do
              [Char]
_ <- ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT [Char] (XPState LocalState) Identity [Char]
 -> ParsecT [Char] (XPState LocalState) Identity [Char])
-> ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
k_fixed
              SParser ()
skipS
              Attributes -> SParser Attributes
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [([Char]
a_kind, [Char]
k_fixed)]
            )

-- ------------------------------------------------------------
--
-- Entity Declarations (4.2)

entityDecl              :: SParser XmlTrees
entityDecl :: SParser XmlTrees
entityDecl
    = ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity Char
-> SParser XmlTrees
-> SParser XmlTrees
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between ( ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT [Char] (XPState LocalState) Identity [Char]
 -> ParsecT [Char] (XPState LocalState) Identity [Char])
-> ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"<!ENTITY" ) (Char -> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>') SParser XmlTrees
entityDeclBody

entityDeclBody          :: SParser XmlTrees
entityDeclBody :: SParser XmlTrees
entityDeclBody
    = do
      SParser ()
skipS
      ( SParser XmlTrees
peDecl
        SParser XmlTrees -> SParser XmlTrees -> SParser XmlTrees
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
        SParser XmlTrees
geDecl
        SParser XmlTrees -> [Char] -> SParser XmlTrees
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"entity declaration" )      -- don't move the ) to the next line

geDecl                  :: SParser XmlTrees
geDecl :: SParser XmlTrees
geDecl
    = do
      [Char]
n <- ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.name
      SParser ()
skipS
      (Attributes
al, XmlTrees
cl) <- SParser (Attributes, XmlTrees)
entityDef
      SParser ()
skipS0
      XmlTrees -> SParser XmlTrees
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [DTDElem -> Attributes -> XmlTrees -> XmlTree
mkDTDElem' DTDElem
ENTITY (([Char]
a_name, [Char]
n) ([Char], [Char]) -> Attributes -> Attributes
forall a. a -> [a] -> [a]
: Attributes
al) XmlTrees
cl]

entityDef               :: SParser (Attributes, XmlTrees)
entityDef :: SParser (Attributes, XmlTrees)
entityDef
    = SParser (Attributes, XmlTrees)
forall s. XParser s (Attributes, XmlTrees)
entityValue
      SParser (Attributes, XmlTrees)
-> SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
      SParser (Attributes, XmlTrees)
externalEntitySpec

externalEntitySpec      :: SParser (Attributes, XmlTrees)
externalEntitySpec :: SParser (Attributes, XmlTrees)
externalEntitySpec
    = do
      Attributes
al <- SParser Attributes
externalID
      Attributes
nd <- Attributes -> SParser Attributes -> SParser Attributes
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] SParser Attributes
nDataDecl
      (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Attributes
al Attributes -> Attributes -> Attributes
forall a. [a] -> [a] -> [a]
++ Attributes
nd), [])

peDecl                  :: SParser XmlTrees
peDecl :: SParser XmlTrees
peDecl
    = do
      Char
_ <- Char -> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'%'
      SParser ()
skipS
      [Char]
n <- ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.name
      SParser ()
skipS
      (Attributes
al, XmlTrees
cs) <- SParser (Attributes, XmlTrees)
peDef
      SParser ()
skipS0
      XmlTrees -> SParser XmlTrees
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [DTDElem -> Attributes -> XmlTrees -> XmlTree
mkDTDElem' DTDElem
PENTITY (([Char]
a_name, [Char]
n) ([Char], [Char]) -> Attributes -> Attributes
forall a. a -> [a] -> [a]
: Attributes
al) XmlTrees
cs]

peDef                   :: SParser (Attributes, XmlTrees)
peDef :: SParser (Attributes, XmlTrees)
peDef
    = SParser (Attributes, XmlTrees)
forall s. XParser s (Attributes, XmlTrees)
entityValue
      SParser (Attributes, XmlTrees)
-> SParser (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
      do
      Attributes
al <- SParser Attributes
externalID
      (Attributes, XmlTrees) -> SParser (Attributes, XmlTrees)
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Attributes
al, [])

entityValue     :: XParser s (Attributes, XmlTrees)
entityValue :: forall s. XParser s (Attributes, XmlTrees)
entityValue
    = do
      XmlTrees
v <- XParser s XmlTrees
forall s. XParser s XmlTrees
XT.entityValueT
      (Attributes, XmlTrees) -> XParser s (Attributes, XmlTrees)
forall a. a -> ParsecT [Char] (XPState s) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ([], XmlTrees
v)

-- ------------------------------------------------------------
--
-- External Entities (4.2.2)

externalID      :: SParser Attributes
externalID :: SParser Attributes
externalID
    = ( do
        [Char]
_ <- [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. [Char] -> XParser s [Char]
XT.keyword [Char]
k_system
        SParser ()
skipS
        [Char]
lit <- ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.systemLiteral
        Attributes -> SParser Attributes
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [([Char]
k_system, [Char]
lit)]
      )
      SParser Attributes -> SParser Attributes -> SParser Attributes
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
      ( do
        [Char]
_ <- [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. [Char] -> XParser s [Char]
XT.keyword [Char]
k_public
        SParser ()
skipS
        [Char]
pl <- ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.pubidLiteral
        SParser ()
skipS
        [Char]
sl <- ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.systemLiteral
        Attributes -> SParser Attributes
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [ ([Char]
k_system, [Char]
sl)
               , ([Char]
k_public, [Char]
pl) ]
      )
      SParser Attributes -> [Char] -> SParser Attributes
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"SYSTEM or PUBLIC declaration"

nDataDecl       :: SParser Attributes
nDataDecl :: SParser Attributes
nDataDecl
    = do
      [Char]
_ <- ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall tok st a. GenParser tok st a -> GenParser tok st a
try ( do
                 SParser ()
skipS
                 [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. [Char] -> XParser s [Char]
XT.keyword [Char]
k_ndata
               )
      SParser ()
skipS
      [Char]
n <- ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.name
      Attributes -> SParser Attributes
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [([Char]
k_ndata, [Char]
n)]

-- ------------------------------------------------------------
--
-- Notation Declarations (4.7)

notationDecl            :: SParser XmlTrees
notationDecl :: SParser XmlTrees
notationDecl
    = ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity Char
-> SParser XmlTrees
-> SParser XmlTrees
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT [Char] (XPState LocalState) Identity [Char]
 -> ParsecT [Char] (XPState LocalState) Identity [Char])
-> ParsecT [Char] (XPState LocalState) Identity [Char]
-> ParsecT [Char] (XPState LocalState) Identity [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"<!NOTATION") (Char -> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>' ParsecT [Char] (XPState LocalState) Identity Char
-> [Char] -> ParsecT [Char] (XPState LocalState) Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"notation declaration") SParser XmlTrees
notationDeclBody

notationDeclBody        :: SParser XmlTrees
notationDeclBody :: SParser XmlTrees
notationDeclBody
    = do
      SParser ()
skipS
      [Char]
n <- ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.name
      SParser ()
skipS
      Attributes
eid <- ( SParser Attributes -> SParser Attributes
forall tok st a. GenParser tok st a -> GenParser tok st a
try SParser Attributes
externalID
               SParser Attributes -> SParser Attributes -> SParser Attributes
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
               SParser Attributes
publicID
             )
      SParser ()
skipS0
      XmlTrees -> SParser XmlTrees
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [DTDElem -> Attributes -> XmlTrees -> XmlTree
mkDTDElem' DTDElem
NOTATION (([Char]
a_name, [Char]
n) ([Char], [Char]) -> Attributes -> Attributes
forall a. a -> [a] -> [a]
: Attributes
eid) []]

publicID                :: SParser Attributes
publicID :: SParser Attributes
publicID
    = do
      [Char]
_ <- [Char] -> ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. [Char] -> XParser s [Char]
XT.keyword [Char]
k_public
      SParser ()
skipS
      [Char]
l <- ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.pubidLiteral
      Attributes -> SParser Attributes
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [([Char]
k_public, [Char]
l)]

-- ------------------------------------------------------------

condSectCondBody        :: SParser XmlTrees
condSectCondBody :: SParser XmlTrees
condSectCondBody
    = do
      SParser ()
skipS0
      [Char]
n <- ParsecT [Char] (XPState LocalState) Identity [Char]
forall s. XParser s [Char]
XT.name
      SParser ()
skipS0
      let n' :: [Char]
n' = [Char] -> [Char]
stringToUpper [Char]
n
      if [Char]
n' [Char] -> [[Char]] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [[Char]
k_include, [Char]
k_ignore]
         then XmlTrees -> SParser XmlTrees
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [[Char] -> XmlTree
mkText'  [Char]
n']
         else [Char] -> SParser XmlTrees
forall a. [Char] -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char] -> SParser XmlTrees) -> [Char] -> SParser XmlTrees
forall a b. (a -> b) -> a -> b
$ [Char]
"INCLUDE or IGNORE expected in conditional section"

-- ------------------------------------------------------------

separator       :: Char -> SParser ()
separator :: Char -> SParser ()
separator Char
c
    = do
      Char
_ <- ParsecT [Char] (XPState LocalState) Identity Char
-> ParsecT [Char] (XPState LocalState) Identity Char
forall tok st a. GenParser tok st a -> GenParser tok st a
try ( do
                 SParser ()
skipS0
                 Char -> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c
               )
      SParser ()
skipS0
      SParser () -> [Char] -> SParser ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char
c]


bar, comma, lpar, rpar  :: SParser ()

bar :: SParser ()
bar     = Char -> SParser ()
separator Char
'|'
comma :: SParser ()
comma   = Char -> SParser ()
separator Char
','

lpar :: SParser ()
lpar
    = do
      Char
_ <- Char -> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'('
      SParser ()
skipS0

rpar :: SParser ()
rpar
    = do
      SParser ()
skipS0
      Char
_ <- Char -> ParsecT [Char] (XPState LocalState) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
')'
      () -> SParser ()
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- ------------------------------------------------------------

parseXmlDTDEntityValue  :: XmlTree -> XmlTrees
parseXmlDTDEntityValue :: XmlTree -> XmlTrees
parseXmlDTDEntityValue XmlTree
t        -- (NTree (XDTD PEREF al) cl)
    | XmlTree -> Bool
isDTDPEref XmlTree
t
        = ( (ParseError -> XmlTrees)
-> (XmlTrees -> XmlTrees) -> Either ParseError XmlTrees -> XmlTrees
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
            ( (XmlTree -> XmlTrees -> XmlTrees
forall a. a -> [a] -> [a]
:[]) (XmlTree -> XmlTrees)
-> (ParseError -> XmlTree) -> ParseError -> XmlTrees
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Char] -> XmlTree
mkError' Int
c_err ([Char] -> XmlTree)
-> (ParseError -> [Char]) -> ParseError -> XmlTree
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"\n") ([Char] -> [Char])
-> (ParseError -> [Char]) -> ParseError -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError -> [Char]
forall a. Show a => a -> [Char]
show )
            ( \XmlTrees
cl' -> if XmlTrees -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null XmlTrees
cl'
                         then [[Char] -> XmlTree
mkText' [Char]
""]
                         else XmlTrees
cl'
            )
            (Either ParseError XmlTrees -> XmlTrees)
-> ([Char] -> Either ParseError XmlTrees) -> [Char] -> XmlTrees
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            GenParser Char (XPState ()) XmlTrees
-> XPState () -> [Char] -> [Char] -> Either ParseError XmlTrees
forall tok st a.
GenParser tok st a -> st -> [Char] -> [tok] -> Either ParseError a
runParser GenParser Char (XPState ()) XmlTrees
forall s. XParser s XmlTrees
parser (() -> XPState ()
forall a. a -> XPState a
withoutNormNewline ()) [Char]
source
          ) [Char]
input
    | Bool
otherwise
        = []
    where
    al :: Attributes
al     = Attributes -> Maybe Attributes -> Attributes
forall a. a -> Maybe a -> a
fromMaybe [] (Maybe Attributes -> Attributes)
-> (XmlTree -> Maybe Attributes) -> XmlTree -> Attributes
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XmlTree -> Maybe Attributes
forall a. XmlNode a => a -> Maybe Attributes
getDTDAttrl (XmlTree -> Attributes) -> XmlTree -> Attributes
forall a b. (a -> b) -> a -> b
$ XmlTree
t
    cl :: XmlTrees
cl     = XmlTree -> XmlTrees
forall a. NTree a -> [NTree a]
forall (t :: * -> *) a. Tree t => t a -> [t a]
getChildren XmlTree
t
    parser :: XParser s XmlTrees
parser = [Char] -> XParser s XmlTrees
forall s. [Char] -> XParser s XmlTrees
XT.entityTokensT [Char]
"%&"
    source :: [Char]
source = [Char]
"value of parameter entity " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char] -> [Char] -> Attributes -> [Char]
forall k v. Eq k => v -> k -> AssocList k v -> v
lookupDef [Char]
"" [Char]
a_peref Attributes
al
    input :: [Char]
input  = XmlTrees -> [Char]
xshow XmlTrees
cl

{-
parseXmlDTDEntityValue n
    = error ("parseXmlDTDEntityValue: illegal argument: " ++ show n)
-}
-- ------------------------------------------------------------

parseXmlDTDdeclPart     :: XmlTree -> XmlTrees
parseXmlDTDdeclPart :: XmlTree -> XmlTrees
parseXmlDTDdeclPart XmlTree
t           -- @(NTree (XDTD PEREF al) cl)
    | XmlTree -> Bool
isDTDPEref XmlTree
t
        = ( (XmlTree -> XmlTrees -> XmlTrees
forall a. a -> [a] -> [a]
:[])
            (XmlTree -> XmlTrees) -> ([Char] -> XmlTree) -> [Char] -> XmlTrees
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            (ParseError -> XmlTree)
-> (XmlTrees -> XmlTree) -> Either ParseError XmlTrees -> XmlTree
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
               ( Int -> [Char] -> XmlTree
mkError' Int
c_err ([Char] -> XmlTree)
-> (ParseError -> [Char]) -> ParseError -> XmlTree
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"\n") ([Char] -> [Char])
-> (ParseError -> [Char]) -> ParseError -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError -> [Char]
forall a. Show a => a -> [Char]
show )
               ( (XmlTrees -> XmlTree -> XmlTree) -> XmlTree -> XmlTrees -> XmlTree
forall a b c. (a -> b -> c) -> b -> a -> c
flip XmlTrees -> XmlTree -> XmlTree
forall a. [NTree a] -> NTree a -> NTree a
forall (t :: * -> *) a. Tree t => [t a] -> t a -> t a
setChildren (XmlTree -> XmlTrees -> XmlTree) -> XmlTree -> XmlTrees -> XmlTree
forall a b. (a -> b) -> a -> b
$ XmlTree
t ) -- \ cl' -> setChildren cl' t)
            (Either ParseError XmlTrees -> XmlTree)
-> ([Char] -> Either ParseError XmlTrees) -> [Char] -> XmlTree
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            GenParser Char (XPState ()) XmlTrees
-> XPState () -> [Char] -> [Char] -> Either ParseError XmlTrees
forall tok st a.
GenParser tok st a -> st -> [Char] -> [tok] -> Either ParseError a
runParser GenParser Char (XPState ()) XmlTrees
forall s. XParser s XmlTrees
parser (() -> XPState ()
forall a. a -> XPState a
withoutNormNewline ()) [Char]
source
          ) [Char]
input
    | Bool
otherwise
        = []
    where
    al :: Attributes
al     = Attributes -> Maybe Attributes -> Attributes
forall a. a -> Maybe a -> a
fromMaybe [] (Maybe Attributes -> Attributes)
-> (XmlTree -> Maybe Attributes) -> XmlTree -> Attributes
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XmlTree -> Maybe Attributes
forall a. XmlNode a => a -> Maybe Attributes
getDTDAttrl (XmlTree -> Attributes) -> XmlTree -> Attributes
forall a b. (a -> b) -> a -> b
$ XmlTree
t
    cl :: XmlTrees
cl     = XmlTree -> XmlTrees
forall a. NTree a -> [NTree a]
forall (t :: * -> *) a. Tree t => t a -> [t a]
getChildren XmlTree
t
    parser :: ParsecT [Char] (XPState s) Identity XmlTrees
parser = ParsecT [Char] (XPState s) Identity XmlTree
-> ParsecT [Char] (XPState s) Identity XmlTrees
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT [Char] (XPState s) Identity XmlTree
forall s. XParser s XmlTree
XD.dtdToken
    source :: [Char]
source = [Char]
"value of parameter entity " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char] -> [Char] -> Attributes -> [Char]
forall k v. Eq k => v -> k -> AssocList k v -> v
lookupDef [Char]
"" [Char]
a_peref Attributes
al
    input :: [Char]
input  = XmlTrees -> [Char]
xshow XmlTrees
cl

{-
parseXmlDTDdeclPart n
    = error ("parseXmlDTDdeclPart: illegal argument: " ++ show n)
-}
-- ------------------------------------------------------------
--
-- the main entry point

-- | parse a tokenized DTD declaration represented by a DTD tree.
-- The content is represented by the children containing text and parameter entity reference nodes.
-- The parameter entity reference nodes contain their value in the children list, consisting of text
-- and possibly again parameter entity reference nodes. This structure is build by the parameter entity
-- substitution.
-- Output is again a DTD declaration node, but this time completely parsed and ready for further DTD processing

parseXmlDTDdecl :: XmlTree -> XmlTrees
parseXmlDTDdecl :: XmlTree -> XmlTrees
parseXmlDTDdecl XmlTree
t       -- (NTree (XDTD dtdElem al) cl)
    | XmlTree -> Bool
forall a. XmlNode a => a -> Bool
isDTD XmlTree
t
        = ( (ParseError -> XmlTrees)
-> (XmlTrees -> XmlTrees) -> Either ParseError XmlTrees -> XmlTrees
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ((XmlTree -> XmlTrees -> XmlTrees
forall a. a -> [a] -> [a]
:[]) (XmlTree -> XmlTrees)
-> (ParseError -> XmlTree) -> ParseError -> XmlTrees
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Char] -> XmlTree
mkError' Int
c_err ([Char] -> XmlTree)
-> (ParseError -> [Char]) -> ParseError -> XmlTree
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"\n") ([Char] -> [Char])
-> (ParseError -> [Char]) -> ParseError -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError -> [Char]
forall a. Show a => a -> [Char]
show) XmlTrees -> XmlTrees
forall a. a -> a
id
            (Either ParseError XmlTrees -> XmlTrees)
-> ([Char] -> Either ParseError XmlTrees) -> [Char] -> XmlTrees
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            SParser XmlTrees
-> XPState LocalState
-> [Char]
-> [Char]
-> Either ParseError XmlTrees
forall tok st a.
GenParser tok st a -> st -> [Char] -> [tok] -> Either ParseError a
runParser SParser XmlTrees
parser (SourcePos -> XPState LocalState
initialState SourcePos
pos) [Char]
source
          ) [Char]
input
    | Bool
otherwise
        = []
    where
    dtdElem :: DTDElem
dtdElem = Maybe DTDElem -> DTDElem
forall a. HasCallStack => Maybe a -> a
fromJust     (Maybe DTDElem -> DTDElem)
-> (XmlTree -> Maybe DTDElem) -> XmlTree -> DTDElem
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XmlTree -> Maybe DTDElem
forall a. XmlNode a => a -> Maybe DTDElem
getDTDPart  (XmlTree -> DTDElem) -> XmlTree -> DTDElem
forall a b. (a -> b) -> a -> b
$ XmlTree
t
    al :: Attributes
al      = Attributes -> Maybe Attributes -> Attributes
forall a. a -> Maybe a -> a
fromMaybe [] (Maybe Attributes -> Attributes)
-> (XmlTree -> Maybe Attributes) -> XmlTree -> Attributes
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XmlTree -> Maybe Attributes
forall a. XmlNode a => a -> Maybe Attributes
getDTDAttrl (XmlTree -> Attributes) -> XmlTree -> Attributes
forall a b. (a -> b) -> a -> b
$ XmlTree
t
    cl :: XmlTrees
cl      = XmlTree -> XmlTrees
forall a. NTree a -> [NTree a]
forall (t :: * -> *) a. Tree t => t a -> [t a]
getChildren XmlTree
t
    dtdParsers :: [(DTDElem, SParser XmlTrees)]
dtdParsers
        = [ (DTDElem
ELEMENT,  SParser XmlTrees
elementDeclBody)
          , (DTDElem
ATTLIST,  SParser XmlTrees
attlistDeclBody)
          , (DTDElem
ENTITY,   SParser XmlTrees
entityDeclBody)
          , (DTDElem
NOTATION, SParser XmlTrees
notationDeclBody)
          , (DTDElem
CONDSECT, SParser XmlTrees
condSectCondBody)
          ]
    source :: [Char]
source = [Char] -> [Char] -> Attributes -> [Char]
forall k v. Eq k => v -> k -> AssocList k v -> v
lookupDef [Char]
"DTD declaration" [Char]
a_source Attributes
al
    line :: [Char]
line   = [Char] -> [Char] -> Attributes -> [Char]
forall k v. Eq k => v -> k -> AssocList k v -> v
lookupDef [Char]
"1" [Char]
a_line Attributes
al
    column :: [Char]
column = [Char] -> [Char] -> Attributes -> [Char]
forall k v. Eq k => v -> k -> AssocList k v -> v
lookupDef [Char]
"1" [Char]
a_column Attributes
al
    pos :: SourcePos
pos    = [Char] -> Int -> Int -> SourcePos
newPos [Char]
source ([Char] -> Int
forall a. Read a => [Char] -> a
read [Char]
line) ([Char] -> Int
forall a. Read a => [Char] -> a
read [Char]
column)
    parser :: SParser XmlTrees
parser = do
             SourcePos -> SParser ()
forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
setPosition SourcePos
pos
             XmlTrees
res <- Maybe (SParser XmlTrees) -> SParser XmlTrees
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe (SParser XmlTrees) -> SParser XmlTrees)
-> ([(DTDElem, SParser XmlTrees)] -> Maybe (SParser XmlTrees))
-> [(DTDElem, SParser XmlTrees)]
-> SParser XmlTrees
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DTDElem
-> [(DTDElem, SParser XmlTrees)] -> Maybe (SParser XmlTrees)
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup DTDElem
dtdElem ([(DTDElem, SParser XmlTrees)] -> SParser XmlTrees)
-> [(DTDElem, SParser XmlTrees)] -> SParser XmlTrees
forall a b. (a -> b) -> a -> b
$ [(DTDElem, SParser XmlTrees)]
dtdParsers
             SParser ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
             XmlTrees -> SParser XmlTrees
forall a. a -> ParsecT [Char] (XPState LocalState) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return XmlTrees
res
    input :: [Char]
input  = (XmlTree -> [Char]) -> XmlTrees -> [Char]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap XmlTree -> [Char]
collectText XmlTrees
cl
{-
parseXmlDTDdecl _
    = []
-}

-- | collect the tokens of a DTD declaration body and build
-- a string ready for parsing. The structure of the parameter entity values
-- is stll stored in this string for checking the scope of the parameter values

collectText     :: XmlTree -> String

collectText :: XmlTree -> [Char]
collectText XmlTree
t
    | XmlTree -> Bool
forall a. XmlNode a => a -> Bool
isText XmlTree
t
        = [Char] -> Maybe [Char] -> [Char]
forall a. a -> Maybe a -> a
fromMaybe [Char]
"" (Maybe [Char] -> [Char])
-> (XmlTree -> Maybe [Char]) -> XmlTree -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XmlTree -> Maybe [Char]
forall a. XmlNode a => a -> Maybe [Char]
getText (XmlTree -> [Char]) -> XmlTree -> [Char]
forall a b. (a -> b) -> a -> b
$ XmlTree
t
    | XmlTree -> Bool
isDTDPEref XmlTree
t
        = [Char]
prefixPe [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ (XmlTree -> [Char]) -> XmlTrees -> [Char]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap XmlTree -> [Char]
collectText (XmlTree -> XmlTrees
forall a. NTree a -> [NTree a]
forall (t :: * -> *) a. Tree t => t a -> [t a]
getChildren XmlTree
t) [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
suffixPe
    | Bool
otherwise
        = [Char]
""
    where
    al :: Attributes
al       = Attributes -> Maybe Attributes -> Attributes
forall a. a -> Maybe a -> a
fromMaybe [] (Maybe Attributes -> Attributes)
-> (XmlTree -> Maybe Attributes) -> XmlTree -> Attributes
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XmlTree -> Maybe Attributes
forall a. XmlNode a => a -> Maybe Attributes
getDTDAttrl (XmlTree -> Attributes) -> XmlTree -> Attributes
forall a b. (a -> b) -> a -> b
$ XmlTree
t
    delPe :: [Char]
delPe    = [Char]
"\0"
    prefixPe :: [Char]
prefixPe = [Char]
delPe [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char] -> [Char] -> Attributes -> [Char]
forall k v. Eq k => v -> k -> AssocList k v -> v
lookupDef [Char]
"???" [Char]
a_peref Attributes
al [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
delPe
    suffixPe :: [Char]
suffixPe = [Char]
delPe [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
delPe

{-

collectText (NTree n _)
    | isXTextNode n
        = textOfXNode n

collectText (NTree (XDTD PEREF al) cl)
    = prefixPe ++ concatMap collectText cl ++ suffixPe
      where
      delPe    = "\0"
      prefixPe = delPe ++ lookupDef "???" a_peref al ++ delPe
      suffixPe = delPe ++ delPe

collectText _
    = ""
-}

isDTDPEref      :: XmlTree -> Bool
isDTDPEref :: XmlTree -> Bool
isDTDPEref
    = Bool -> (DTDElem -> Bool) -> Maybe DTDElem -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (DTDElem -> DTDElem -> Bool
forall a. Eq a => a -> a -> Bool
== DTDElem
PEREF) (Maybe DTDElem -> Bool)
-> (XmlTree -> Maybe DTDElem) -> XmlTree -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XmlTree -> Maybe DTDElem
forall a. XmlNode a => a -> Maybe DTDElem
getDTDPart

-- ------------------------------------------------------------