{-# LANGUAGE DeriveDataTypeable #-}

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

{- |
   Module     : Text.XML.HXT.DOM.TypeDefs
   Copyright  : Copyright (C) 2008-2010 Uwe Schmidt
   License    : MIT

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

   The core data types of the HXT DOM.

-}

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

module Text.XML.HXT.DOM.TypeDefs
    ( module Data.AssocList
    , module Text.XML.HXT.DOM.TypeDefs
    , module Text.XML.HXT.DOM.QualifiedName
    )

where

import           Control.DeepSeq
import           Control.FlatSeq

import           Data.AssocList

import           Data.Binary
import qualified Data.ByteString.Lazy            as BS
import qualified Data.ByteString.Lazy.Char8      as CS

import           Data.Tree.NTree.TypeDefs
import           Data.Tree.NTree.Zipper.TypeDefs

import           Data.Typeable

import           Text.XML.HXT.DOM.QualifiedName

-- -----------------------------------------------------------------------------
--
-- Basic types for xml tree and filters

-- | Rose tree with XML nodes (XNode)

type XmlTree    = NTree    XNode

-- | List of rose trees with XML nodes

type XmlTrees   = NTrees   XNode

-- | Navigatable rose tree with XML nodes

type XmlNavTree = NTZipper XNode

-- | List of navigatable rose trees with XML nodes

type XmlNavTrees = [NTZipper XNode]

-- -----------------------------------------------------------------------------
--
-- XNode

-- | Represents elements

data XNode      = XText           String                        -- ^ ordinary text                                       (leaf)
                | XBlob           Blob                          -- ^ text represented more space efficient as bytestring (leaf)
                | XCharRef        Int                           -- ^ character reference                                 (leaf)
                | XEntityRef      String                        -- ^ entity reference                                    (leaf)
                | XCmt            String                        -- ^ comment                                             (leaf)
                | XCdata          String                        -- ^ CDATA section                                       (leaf)
                | XPi             QName XmlTrees                -- ^ Processing Instr with qualified name                (leaf)
                                                                --   with list of attributes.
                                                                --   If tag name is xml, attributes are \"version\", \"encoding\", \"standalone\",
                                                                --   else attribute list is empty, content is a text child node
                | XTag            QName XmlTrees                -- ^ tag with qualified name and list of attributes (inner node or leaf)
                | XDTD            DTDElem  Attributes           -- ^ DTD element with assoc list for dtd element features
                | XAttr           QName                         -- ^ attribute with qualified name, the attribute value is stored in children
                | XError          Int  String                   -- ^ error message with level and text
                  deriving (XNode -> XNode -> Bool
(XNode -> XNode -> Bool) -> (XNode -> XNode -> Bool) -> Eq XNode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: XNode -> XNode -> Bool
$c/= :: XNode -> XNode -> Bool
== :: XNode -> XNode -> Bool
$c== :: XNode -> XNode -> Bool
Eq, Int -> XNode -> ShowS
[XNode] -> ShowS
XNode -> String
(Int -> XNode -> ShowS)
-> (XNode -> String) -> ([XNode] -> ShowS) -> Show XNode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [XNode] -> ShowS
$cshowList :: [XNode] -> ShowS
show :: XNode -> String
$cshow :: XNode -> String
showsPrec :: Int -> XNode -> ShowS
$cshowsPrec :: Int -> XNode -> ShowS
Show, Typeable)

instance NFData XNode where
    rnf :: XNode -> ()
rnf (XText String
s)               = String -> ()
forall a. NFData a => a -> ()
rnf String
s
    rnf (XTag QName
qn XmlTrees
cs)            = QName -> ()
forall a. NFData a => a -> ()
rnf QName
qn () -> () -> ()
`seq` XmlTrees -> ()
forall a. NFData a => a -> ()
rnf XmlTrees
cs
    rnf (XAttr QName
qn)              = QName -> ()
forall a. NFData a => a -> ()
rnf QName
qn
    rnf (XCharRef Int
i)            = Int -> ()
forall a. NFData a => a -> ()
rnf Int
i
    rnf (XEntityRef String
n)          = String -> ()
forall a. NFData a => a -> ()
rnf String
n
    rnf (XCmt String
c)                = String -> ()
forall a. NFData a => a -> ()
rnf String
c
    rnf (XCdata String
s)              = String -> ()
forall a. NFData a => a -> ()
rnf String
s
    rnf (XPi QName
qn XmlTrees
ts)             = QName -> ()
forall a. NFData a => a -> ()
rnf QName
qn () -> () -> ()
`seq` XmlTrees -> ()
forall a. NFData a => a -> ()
rnf XmlTrees
ts
    rnf (XDTD DTDElem
de Attributes
al)            = DTDElem -> ()
forall a. NFData a => a -> ()
rnf DTDElem
de () -> () -> ()
`seq` Attributes -> ()
forall a. NFData a => a -> ()
rnf Attributes
al
    rnf (XBlob Blob
b)               = Blob -> Int64
BS.length Blob
b Int64 -> () -> ()
`seq` ()
    rnf (XError Int
n String
e)            = Int -> ()
forall a. NFData a => a -> ()
rnf Int
n  () -> () -> ()
`seq` String -> ()
forall a. NFData a => a -> ()
rnf String
e

instance WNFData XNode where
    rwnf :: XNode -> ()
rwnf (XText String
s)              = String -> ()
forall a. WNFData a => a -> ()
rwnf String
s
    rwnf (XTag QName
qn XmlTrees
cs)           = QName -> ()
forall a. WNFData a => a -> ()
rwnf QName
qn () -> () -> ()
`seq` XmlTrees -> ()
forall a. WNFData a => a -> ()
rwnf XmlTrees
cs
    rwnf (XAttr QName
qn)             = QName -> ()
forall a. WNFData a => a -> ()
rwnf QName
qn
    rwnf (XCharRef Int
i)           = Int
i Int -> () -> ()
`seq` ()
    rwnf (XEntityRef String
n)         = String -> ()
forall a. WNFData a => a -> ()
rwnf String
n
    rwnf (XCmt String
c)               = String -> ()
forall a. WNFData a => a -> ()
rwnf String
c
    rwnf (XCdata String
s)             = String -> ()
forall a. WNFData a => a -> ()
rwnf String
s
    rwnf (XPi QName
qn XmlTrees
ts)            = QName -> ()
forall a. WNFData a => a -> ()
rwnf QName
qn () -> () -> ()
`seq` XmlTrees -> ()
forall a. WNFData a => a -> ()
rwnf XmlTrees
ts
    rwnf (XDTD DTDElem
de Attributes
al)           = DTDElem -> ()
forall a. WNFData a => a -> ()
rwnf DTDElem
de () -> () -> ()
`seq` Attributes -> ()
rwnfAttributes Attributes
al
    rwnf (XBlob Blob
_b)             = () -- BS.length b `seq` () -- lazy bytestrings are not evaluated
    rwnf (XError Int
n String
e)           = Int
n Int -> () -> ()
`seq` String -> ()
forall a. WNFData a => a -> ()
rwnf String
e

-- | Evaluate an assoc list of strings
rwnfAttributes                  :: Attributes -> ()
rwnfAttributes :: Attributes -> ()
rwnfAttributes [] = ()
rwnfAttributes ((String
k, String
v) : Attributes
as)    = String -> ()
forall a. WNFData a => a -> ()
rwnf String
k () -> () -> ()
`seq` String -> ()
forall a. WNFData a => a -> ()
rwnf String
v () -> () -> ()
`seq` Attributes -> ()
rwnfAttributes Attributes
as


instance Binary XNode where
    put :: XNode -> Put
put (XText String
s)               = Word8 -> Put
forall t. Binary t => t -> Put
put ( Word8
0::Word8) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
s
    put (XTag QName
qn XmlTrees
cs)            = Word8 -> Put
forall t. Binary t => t -> Put
put ( Word8
6::Word8) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> QName -> Put
forall t. Binary t => t -> Put
put QName
qn Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> XmlTrees -> Put
forall t. Binary t => t -> Put
put XmlTrees
cs
    put (XAttr QName
qn)              = Word8 -> Put
forall t. Binary t => t -> Put
put ( Word8
8::Word8) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> QName -> Put
forall t. Binary t => t -> Put
put QName
qn
    put (XCharRef Int
i)            = Word8 -> Put
forall t. Binary t => t -> Put
put ( Word8
1::Word8) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
put Int
i
    put (XEntityRef String
n)          = Word8 -> Put
forall t. Binary t => t -> Put
put ( Word8
2::Word8) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
n
    put (XCmt String
c)                = Word8 -> Put
forall t. Binary t => t -> Put
put ( Word8
3::Word8) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
c
    put (XCdata String
s)              = Word8 -> Put
forall t. Binary t => t -> Put
put ( Word8
4::Word8) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
s
    put (XPi QName
qn XmlTrees
ts)             = Word8 -> Put
forall t. Binary t => t -> Put
put ( Word8
5::Word8) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> QName -> Put
forall t. Binary t => t -> Put
put QName
qn Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> XmlTrees -> Put
forall t. Binary t => t -> Put
put XmlTrees
ts
    put (XDTD DTDElem
de Attributes
al)            = Word8 -> Put
forall t. Binary t => t -> Put
put ( Word8
7::Word8) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> DTDElem -> Put
forall t. Binary t => t -> Put
put DTDElem
de Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Attributes -> Put
forall t. Binary t => t -> Put
put Attributes
al
    put (XError Int
n String
e)            = Word8 -> Put
forall t. Binary t => t -> Put
put ( Word8
9::Word8) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
put Int
n  Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
e
    put (XBlob Blob
b)               = Word8 -> Put
forall t. Binary t => t -> Put
put (Word8
10::Word8) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blob -> Put
forall t. Binary t => t -> Put
put Blob
b

    get :: Get XNode
get                         = do
                                  Word8
tag <- Get Word8
getWord8
                                  case Word8
tag of
                                    Word8
0  -> Get String
forall t. Binary t => Get t
get Get String -> (String -> Get XNode) -> Get XNode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= XNode -> Get XNode
forall (m :: * -> *) a. Monad m => a -> m a
return (XNode -> Get XNode) -> (String -> XNode) -> String -> Get XNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> XNode
XText
                                    Word8
1  -> Get Int
forall t. Binary t => Get t
get Get Int -> (Int -> Get XNode) -> Get XNode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= XNode -> Get XNode
forall (m :: * -> *) a. Monad m => a -> m a
return (XNode -> Get XNode) -> (Int -> XNode) -> Int -> Get XNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> XNode
XCharRef
                                    Word8
2  -> Get String
forall t. Binary t => Get t
get Get String -> (String -> Get XNode) -> Get XNode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= XNode -> Get XNode
forall (m :: * -> *) a. Monad m => a -> m a
return (XNode -> Get XNode) -> (String -> XNode) -> String -> Get XNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> XNode
XEntityRef
                                    Word8
3  -> Get String
forall t. Binary t => Get t
get Get String -> (String -> Get XNode) -> Get XNode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= XNode -> Get XNode
forall (m :: * -> *) a. Monad m => a -> m a
return (XNode -> Get XNode) -> (String -> XNode) -> String -> Get XNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> XNode
XCmt
                                    Word8
4  -> Get String
forall t. Binary t => Get t
get Get String -> (String -> Get XNode) -> Get XNode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= XNode -> Get XNode
forall (m :: * -> *) a. Monad m => a -> m a
return (XNode -> Get XNode) -> (String -> XNode) -> String -> Get XNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> XNode
XCdata
                                    Word8
5  -> do
                                          QName
qn <- Get QName
forall t. Binary t => Get t
get
                                          Get XmlTrees
forall t. Binary t => Get t
get Get XmlTrees -> (XmlTrees -> Get XNode) -> Get XNode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= XNode -> Get XNode
forall (m :: * -> *) a. Monad m => a -> m a
return (XNode -> Get XNode)
-> (XmlTrees -> XNode) -> XmlTrees -> Get XNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QName -> XmlTrees -> XNode
XPi QName
qn
                                    Word8
6  -> do
                                          QName
qn <- Get QName
forall t. Binary t => Get t
get
                                          Get XmlTrees
forall t. Binary t => Get t
get Get XmlTrees -> (XmlTrees -> Get XNode) -> Get XNode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= XNode -> Get XNode
forall (m :: * -> *) a. Monad m => a -> m a
return (XNode -> Get XNode)
-> (XmlTrees -> XNode) -> XmlTrees -> Get XNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QName -> XmlTrees -> XNode
XTag QName
qn
                                    Word8
7  -> do
                                          DTDElem
de <- Get DTDElem
forall t. Binary t => Get t
get
                                          Get Attributes
forall t. Binary t => Get t
get Get Attributes -> (Attributes -> Get XNode) -> Get XNode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= XNode -> Get XNode
forall (m :: * -> *) a. Monad m => a -> m a
return (XNode -> Get XNode)
-> (Attributes -> XNode) -> Attributes -> Get XNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DTDElem -> Attributes -> XNode
XDTD DTDElem
de
                                    Word8
8  -> Get QName
forall t. Binary t => Get t
get Get QName -> (QName -> Get XNode) -> Get XNode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= XNode -> Get XNode
forall (m :: * -> *) a. Monad m => a -> m a
return (XNode -> Get XNode) -> (QName -> XNode) -> QName -> Get XNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QName -> XNode
XAttr
                                    Word8
9  -> do
                                          Int
n <- Get Int
forall t. Binary t => Get t
get
                                          Get String
forall t. Binary t => Get t
get Get String -> (String -> Get XNode) -> Get XNode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= XNode -> Get XNode
forall (m :: * -> *) a. Monad m => a -> m a
return (XNode -> Get XNode) -> (String -> XNode) -> String -> Get XNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> XNode
XError Int
n
                                    Word8
10 -> Get Blob
forall t. Binary t => Get t
get Get Blob -> (Blob -> Get XNode) -> Get XNode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= XNode -> Get XNode
forall (m :: * -> *) a. Monad m => a -> m a
return (XNode -> Get XNode) -> (Blob -> XNode) -> Blob -> Get XNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blob -> XNode
XBlob
                                    Word8
_  -> String -> Get XNode
forall a. HasCallStack => String -> a
error String
"XNode.get: error while decoding XNode"

-- -----------------------------------------------------------------------------
--
-- DTDElem

-- | Represents a DTD element

data DTDElem    = DOCTYPE       -- ^ attr: name, system, public,        XDTD elems as children
                | ELEMENT       -- ^ attr: name, kind
                                --
                                --  name: element name
                                --
                                --  kind: \"EMPTY\" | \"ANY\" | \"\#PCDATA\" | children | mixed
                | CONTENT       -- ^ element content
                                --
                                --  attr: kind, modifier
                                --
                                --  modifier: \"\" | \"?\" | \"*\" | \"+\"
                                --
                                --  kind: seq | choice
                | ATTLIST       -- ^ attributes:
                                --  name - name of element
                                --
                                --  value - name of attribute
                                --
                                --  type: \"CDATA\" | \"ID\" | \"IDREF\" | \"IDREFS\" | \"ENTITY\" | \"ENTITIES\" |
                                --
                                --        \"NMTOKEN\" | \"NMTOKENS\" |\"NOTATION\" | \"ENUMTYPE\"
                                --
                                --  kind: \"#REQUIRED\" | \"#IMPLIED\" | \"DEFAULT\"
                | ENTITY        -- ^ for entity declarations
                | PENTITY       -- ^ for parameter entity declarations
                | NOTATION      -- ^ for notations
                | CONDSECT      -- ^ for INCLUDEs, IGNOREs and peRefs: attr: type
                                --
                                --  type = INCLUDE, IGNORE or %...;
                | NAME          -- ^ attr: name
                                --
                                --  for lists of names in notation types or nmtokens in enumeration types
                | PEREF         -- ^ for Parameter Entity References in DTDs
                  deriving (DTDElem -> DTDElem -> Bool
(DTDElem -> DTDElem -> Bool)
-> (DTDElem -> DTDElem -> Bool) -> Eq DTDElem
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DTDElem -> DTDElem -> Bool
$c/= :: DTDElem -> DTDElem -> Bool
== :: DTDElem -> DTDElem -> Bool
$c== :: DTDElem -> DTDElem -> Bool
Eq, Eq DTDElem
Eq DTDElem
-> (DTDElem -> DTDElem -> Ordering)
-> (DTDElem -> DTDElem -> Bool)
-> (DTDElem -> DTDElem -> Bool)
-> (DTDElem -> DTDElem -> Bool)
-> (DTDElem -> DTDElem -> Bool)
-> (DTDElem -> DTDElem -> DTDElem)
-> (DTDElem -> DTDElem -> DTDElem)
-> Ord DTDElem
DTDElem -> DTDElem -> Bool
DTDElem -> DTDElem -> Ordering
DTDElem -> DTDElem -> DTDElem
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: DTDElem -> DTDElem -> DTDElem
$cmin :: DTDElem -> DTDElem -> DTDElem
max :: DTDElem -> DTDElem -> DTDElem
$cmax :: DTDElem -> DTDElem -> DTDElem
>= :: DTDElem -> DTDElem -> Bool
$c>= :: DTDElem -> DTDElem -> Bool
> :: DTDElem -> DTDElem -> Bool
$c> :: DTDElem -> DTDElem -> Bool
<= :: DTDElem -> DTDElem -> Bool
$c<= :: DTDElem -> DTDElem -> Bool
< :: DTDElem -> DTDElem -> Bool
$c< :: DTDElem -> DTDElem -> Bool
compare :: DTDElem -> DTDElem -> Ordering
$ccompare :: DTDElem -> DTDElem -> Ordering
$cp1Ord :: Eq DTDElem
Ord, Int -> DTDElem
DTDElem -> Int
DTDElem -> [DTDElem]
DTDElem -> DTDElem
DTDElem -> DTDElem -> [DTDElem]
DTDElem -> DTDElem -> DTDElem -> [DTDElem]
(DTDElem -> DTDElem)
-> (DTDElem -> DTDElem)
-> (Int -> DTDElem)
-> (DTDElem -> Int)
-> (DTDElem -> [DTDElem])
-> (DTDElem -> DTDElem -> [DTDElem])
-> (DTDElem -> DTDElem -> [DTDElem])
-> (DTDElem -> DTDElem -> DTDElem -> [DTDElem])
-> Enum DTDElem
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: DTDElem -> DTDElem -> DTDElem -> [DTDElem]
$cenumFromThenTo :: DTDElem -> DTDElem -> DTDElem -> [DTDElem]
enumFromTo :: DTDElem -> DTDElem -> [DTDElem]
$cenumFromTo :: DTDElem -> DTDElem -> [DTDElem]
enumFromThen :: DTDElem -> DTDElem -> [DTDElem]
$cenumFromThen :: DTDElem -> DTDElem -> [DTDElem]
enumFrom :: DTDElem -> [DTDElem]
$cenumFrom :: DTDElem -> [DTDElem]
fromEnum :: DTDElem -> Int
$cfromEnum :: DTDElem -> Int
toEnum :: Int -> DTDElem
$ctoEnum :: Int -> DTDElem
pred :: DTDElem -> DTDElem
$cpred :: DTDElem -> DTDElem
succ :: DTDElem -> DTDElem
$csucc :: DTDElem -> DTDElem
Enum, Int -> DTDElem -> ShowS
[DTDElem] -> ShowS
DTDElem -> String
(Int -> DTDElem -> ShowS)
-> (DTDElem -> String) -> ([DTDElem] -> ShowS) -> Show DTDElem
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DTDElem] -> ShowS
$cshowList :: [DTDElem] -> ShowS
show :: DTDElem -> String
$cshow :: DTDElem -> String
showsPrec :: Int -> DTDElem -> ShowS
$cshowsPrec :: Int -> DTDElem -> ShowS
Show, ReadPrec [DTDElem]
ReadPrec DTDElem
Int -> ReadS DTDElem
ReadS [DTDElem]
(Int -> ReadS DTDElem)
-> ReadS [DTDElem]
-> ReadPrec DTDElem
-> ReadPrec [DTDElem]
-> Read DTDElem
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DTDElem]
$creadListPrec :: ReadPrec [DTDElem]
readPrec :: ReadPrec DTDElem
$creadPrec :: ReadPrec DTDElem
readList :: ReadS [DTDElem]
$creadList :: ReadS [DTDElem]
readsPrec :: Int -> ReadS DTDElem
$creadsPrec :: Int -> ReadS DTDElem
Read, Typeable)

instance NFData DTDElem
    where rnf :: DTDElem -> ()
rnf DTDElem
x = DTDElem -> () -> ()
seq DTDElem
x ()

instance WNFData DTDElem

instance Binary DTDElem where
    put :: DTDElem -> Put
put DTDElem
de = Word8 -> Put
forall t. Binary t => t -> Put
put ((Int -> Word8
forall a. Enum a => Int -> a
toEnum (Int -> Word8) -> (DTDElem -> Int) -> DTDElem -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DTDElem -> Int
forall a. Enum a => a -> Int
fromEnum (DTDElem -> Word8) -> DTDElem -> Word8
forall a b. (a -> b) -> a -> b
$ DTDElem
de)::Word8)         -- DTDElem is not yet instance of Enum
    get :: Get DTDElem
get    = do Word8
tag <- Get Word8
getWord8
                DTDElem -> Get DTDElem
forall (m :: * -> *) a. Monad m => a -> m a
return (DTDElem -> Get DTDElem) -> DTDElem -> Get DTDElem
forall a b. (a -> b) -> a -> b
$! (Int -> DTDElem
forall a. Enum a => Int -> a
toEnum (Int -> DTDElem) -> (Word8 -> Int) -> Word8 -> DTDElem
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Int
forall a. Enum a => a -> Int
fromEnum (Word8 -> DTDElem) -> Word8 -> DTDElem
forall a b. (a -> b) -> a -> b
$ Word8
tag)

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

-- | Binary large object implemented as a lazy bytestring

type Blob       = BS.ByteString

blobToString    :: Blob -> String
blobToString :: Blob -> String
blobToString    = Blob -> String
CS.unpack
{-# INLINE blobToString #-}

stringToBlob    :: String -> Blob
stringToBlob :: String -> Blob
stringToBlob    = String -> Blob
CS.pack
{-# INLINE stringToBlob #-}

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

-- | Attribute list
--
-- used for storing option lists and features of DTD parts

type Attributes = AssocList String String

-- -----------------------------------------------------------------------------
--
-- Constants for error levels

-- | no error, everything is ok
c_ok    :: Int
c_ok :: Int
c_ok    = Int
0

-- | Error level for XError, type warning
c_warn  :: Int
c_warn :: Int
c_warn  = Int
c_ok Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1

-- | Error level for XError, type error
c_err   :: Int
c_err :: Int
c_err   = Int
c_warn Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1

-- | Error level for XError, type fatal error
c_fatal :: Int
c_fatal :: Int
c_fatal = Int
c_err Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1

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

-- | data type for representing a set of nodes as a tree structure
--
-- this structure is e.g. used to repesent the result of an XPath query
-- such that the selected nodes can be processed or selected later in
-- processing a document tree

data XmlNodeSet = XNS { XmlNodeSet -> Bool
thisNode   :: Bool         -- ^ is this node part of the set ?
                      , XmlNodeSet -> [QName]
attrNodes  :: [QName]      -- ^ the set of attribute nodes
                      , XmlNodeSet -> ChildNodes
childNodes :: ChildNodes   -- ^ the set of child nodes, a list of pairs of index and node set
                      }
                  deriving (XmlNodeSet -> XmlNodeSet -> Bool
(XmlNodeSet -> XmlNodeSet -> Bool)
-> (XmlNodeSet -> XmlNodeSet -> Bool) -> Eq XmlNodeSet
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: XmlNodeSet -> XmlNodeSet -> Bool
$c/= :: XmlNodeSet -> XmlNodeSet -> Bool
== :: XmlNodeSet -> XmlNodeSet -> Bool
$c== :: XmlNodeSet -> XmlNodeSet -> Bool
Eq, Int -> XmlNodeSet -> ShowS
[XmlNodeSet] -> ShowS
XmlNodeSet -> String
(Int -> XmlNodeSet -> ShowS)
-> (XmlNodeSet -> String)
-> ([XmlNodeSet] -> ShowS)
-> Show XmlNodeSet
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [XmlNodeSet] -> ShowS
$cshowList :: [XmlNodeSet] -> ShowS
show :: XmlNodeSet -> String
$cshow :: XmlNodeSet -> String
showsPrec :: Int -> XmlNodeSet -> ShowS
$cshowsPrec :: Int -> XmlNodeSet -> ShowS
Show, Typeable)

type ChildNodes = [(Int, XmlNodeSet)]

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