module Text.XML.HaXml.Types
(
SymTab
, emptyST
, addST
, lookupST
, Document(..)
, Element(..)
, ElemTag(..)
, Content(..)
, Attribute
, AttValue(..)
, info
, Prolog(..)
, XMLDecl(..)
, Misc(..)
, ProcessingInstruction
, SDDecl
, VersionInfo
, Comment
, PITarget
, DocTypeDecl(..)
, MarkupDecl(..)
, ExtSubset(..)
, ExtSubsetDecl(..)
, ElementDecl(..)
, ContentSpec(..)
, CP(..)
, Modifier(..)
, Mixed(..)
, AttListDecl(..)
, AttDef(..)
, AttType(..)
, TokenizedType(..)
, EnumeratedType(..)
, NotationType
, Enumeration
, DefaultDecl(..)
, FIXED(..)
, ConditionalSect(..)
, IncludeSect
, IgnoreSect
, Ignore(..)
, IgnoreSectContents(..)
, Reference(..)
, EntityRef
, CharRef
, PEReference
, EntityDecl(..)
, GEDecl(..)
, PEDecl(..)
, EntityDef(..)
, PEDef(..)
, ExternalID(..)
, NDataDecl(..)
, TextDecl(..)
, ExtParsedEnt(..)
, ExtPE(..)
, NotationDecl(..)
, PublicID(..)
, EncodingDecl(..)
, EntityValue(..)
, EV(..)
, PubidLiteral(..)
, SystemLiteral(..)
, QName(..)
, Namespace(..)
, Name
, Names
, NmToken
, NmTokens
, CharData
, CDSect
) where
type SymTab a = [(String,a)]
emptyST :: SymTab a
emptyST = []
addST :: String -> a -> SymTab a -> SymTab a
addST n v = ((n,v):)
lookupST :: String -> SymTab a -> Maybe a
lookupST = lookup
data Document i = Document Prolog (SymTab EntityDef) (Element i) [Misc]
deriving (Eq, Show)
data Prolog = Prolog (Maybe XMLDecl) [Misc] (Maybe DocTypeDecl) [Misc]
deriving (Eq, Show)
data XMLDecl = XMLDecl VersionInfo (Maybe EncodingDecl) (Maybe SDDecl)
deriving (Eq, Show)
data Misc = Comment Comment
| PI ProcessingInstruction
deriving (Eq, Show)
type ProcessingInstruction = (PITarget,String)
type SDDecl = Bool
type VersionInfo = String
type Comment = String
type PITarget = String
data DocTypeDecl = DTD QName (Maybe ExternalID) [MarkupDecl] deriving (Eq, Show)
data MarkupDecl = Element ElementDecl
| AttList AttListDecl
| Entity EntityDecl
| Notation NotationDecl
| MarkupMisc Misc
deriving (Eq, Show)
data ExtSubset = ExtSubset (Maybe TextDecl) [ExtSubsetDecl] deriving (Eq, Show)
data ExtSubsetDecl = ExtMarkupDecl MarkupDecl
| ExtConditionalSect ConditionalSect
deriving (Eq, Show)
data Element i = Elem QName [Attribute] [Content i] deriving (Eq, Show)
data ElemTag = ElemTag QName [Attribute]
type Attribute = (QName, AttValue)
data Content i = CElem (Element i) i
| CString Bool CharData i
| CRef Reference i
| CMisc Misc i
deriving Show
instance Eq (Content i) where
(CElem e _) == (CElem e' _) = e==e'
(CString b c _) == (CString b' c' _) = b==b' && c==c'
(CRef r _) == (CRef r' _) = r==r'
(CMisc m _) == (CMisc m' _) = m==m'
info :: Content t -> t
info (CElem _ i) = i
info (CString _ _ i) = i
info (CRef _ i) = i
info (CMisc _ i) = i
instance Functor Document where
fmap f (Document p st e ms) = Document p st (fmap f e) ms
instance Functor Element where
fmap f (Elem t as cs) = Elem t as (map (fmap f) cs)
instance Functor Content where
fmap f (CElem e i) = CElem (fmap f e) (f i)
fmap f (CString b s i) = CString b s (f i)
fmap f (CRef r i) = CRef r (f i)
fmap f (CMisc m i) = CMisc m (f i)
data ElementDecl = ElementDecl QName ContentSpec deriving (Eq, Show)
data ContentSpec = EMPTY
| ANY
| Mixed Mixed
| ContentSpec CP
deriving (Eq, Show)
data CP = TagName QName Modifier
| Choice [CP] Modifier
| Seq [CP] Modifier
deriving (Eq, Show)
data Modifier = None
| Query
| Star
| Plus
deriving (Eq, Show)
data Mixed = PCDATA
| PCDATAplus [QName]
deriving (Eq, Show)
data AttListDecl = AttListDecl QName [AttDef] deriving (Eq, Show)
data AttDef = AttDef QName AttType DefaultDecl deriving (Eq, Show)
data AttType = StringType
| TokenizedType TokenizedType
| EnumeratedType EnumeratedType
deriving (Eq, Show)
data TokenizedType = ID
| IDREF
| IDREFS
| ENTITY
| ENTITIES
| NMTOKEN
| NMTOKENS
deriving (Eq, Show)
data EnumeratedType = NotationType NotationType
| Enumeration Enumeration
deriving (Eq, Show)
type NotationType = [Name]
type Enumeration = [NmToken]
data DefaultDecl = REQUIRED
| IMPLIED
| DefaultTo AttValue (Maybe FIXED)
deriving (Eq, Show)
data FIXED = FIXED deriving (Eq, Show)
data ConditionalSect = IncludeSect IncludeSect
| IgnoreSect IgnoreSect
deriving (Eq, Show)
type IncludeSect = [ExtSubsetDecl]
type IgnoreSect = [IgnoreSectContents]
data Ignore = Ignore deriving (Eq, Show)
data IgnoreSectContents = IgnoreSectContents Ignore [(IgnoreSectContents,Ignore)] deriving (Eq, Show)
data Reference = RefEntity EntityRef
| RefChar CharRef
deriving (Eq,Show)
type EntityRef = Name
type CharRef = Int
type PEReference = Name
data EntityDecl = EntityGEDecl GEDecl
| EntityPEDecl PEDecl
deriving (Eq, Show)
data GEDecl = GEDecl Name EntityDef deriving (Eq, Show)
data PEDecl = PEDecl Name PEDef deriving (Eq, Show)
data EntityDef = DefEntityValue EntityValue
| DefExternalID ExternalID (Maybe NDataDecl)
deriving (Eq, Show)
data PEDef = PEDefEntityValue EntityValue
| PEDefExternalID ExternalID deriving (Eq,Show)
data ExternalID = SYSTEM SystemLiteral
| PUBLIC PubidLiteral SystemLiteral deriving (Eq,Show)
newtype NDataDecl = NDATA Name deriving (Eq, Show)
data TextDecl = TextDecl (Maybe VersionInfo) EncodingDecl deriving (Eq, Show)
data ExtParsedEnt i = ExtParsedEnt (Maybe TextDecl) (Content i) deriving (Eq, Show)
data ExtPE = ExtPE (Maybe TextDecl) [ExtSubsetDecl] deriving (Eq, Show)
data NotationDecl = NOTATION Name (Either ExternalID PublicID) deriving (Eq, Show)
newtype PublicID = PUBLICID PubidLiteral deriving (Eq, Show)
newtype EncodingDecl = EncodingDecl String deriving (Eq, Show)
data QName = N Name
| QN Namespace Name deriving (Eq,Show)
data Namespace = Namespace { nsPrefix :: String
, nsURI :: String
}
deriving (Show)
instance Eq Namespace where
p == q = nsURI p == nsURI q
instance Ord QName where
compare (N n) (N m) = compare n m
compare (QN p n) (N m) = LT
compare (N n) (QN q m) = GT
compare (QN p n) (QN q m) = case compare (nsPrefix p) (nsPrefix q) of
EQ -> compare n m
r -> r
type Name = String
type Names = [Name]
type NmToken = String
type NmTokens = [NmToken]
data AttValue = AttValue [Either String Reference] deriving Eq
instance Show AttValue where
show (AttValue v) = concatMap decode v
where
decode (Left w) = w
decode (Right (RefEntity ent)) = "&"++ent++";"
decode (Right (RefChar cref)) = "&"++show cref++";"
data EntityValue = EntityValue [EV] deriving (Eq,Show)
data EV = EVString String
| EVRef Reference deriving (Eq,Show)
newtype PubidLiteral = PubidLiteral String deriving (Eq,Show)
newtype SystemLiteral = SystemLiteral String deriving (Eq,Show)
type CharData = String
type CDSect = CharData
instance Eq ElemTag where
(ElemTag n _) == (ElemTag m _) = n==m