{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Text.XML.Types where
import Common
data Content
= Elem Element
| Text CData
| CRef !ShortText
deriving (Show, Typeable, Data, Generic)
instance NFData Content
type Element = Element' Content
data Element' cnode = Element
{ elName :: !QName
, elAttribs :: [Attr]
, elContent :: [cnode]
} deriving (Show, Typeable, Data, Generic, Functor, Foldable, Traversable)
instance NFData cnode => NFData (Element' cnode)
data Attr = Attr
{ attrKey :: !QName
, attrVal :: !Text
} deriving (Eq, Ord, Show, Typeable, Data, Generic)
instance NFData Attr
data CData = CData
{ cdVerbatim :: !CDataKind
, cdData :: !Text
} deriving (Show, Typeable, Data, Generic)
instance NFData CData
data CDataKind
= CDataText
| CDataVerbatim
| CDataRaw
deriving (Eq, Show, Typeable, Data, Generic)
instance NFData CDataKind
data QName = QName
{ qLName :: !LName
, qURI :: Maybe URI
, qPrefix :: Maybe ShortText
} deriving (Show, Typeable, Data, Generic)
instance NFData QName
instance Eq QName where
q1 == q2 = compare q1 q2 == EQ
instance Ord QName where
compare q1 q2 =
case compare (qLName q1) (qLName q2) of
EQ -> case (qURI q1, qURI q2) of
(Nothing,Nothing) -> compare (qPrefix q1) (qPrefix q2)
(u1,u2) -> compare u1 u2
x -> x
newtype LName = LName { unLName :: ShortText }
deriving (Show, Ord, Eq, Typeable, Data, IsString, NFData, Generic)
newtype URI = URI { unURI :: ShortText }
deriving (Show, Ord, Eq, Typeable, Data, IsString, NFData, Generic)
type Pos = Int
blank_name :: QName
blank_name = QName
{ qLName = LName mempty
, qURI = Nothing
, qPrefix = Nothing
}
blank_cdata :: CData
blank_cdata = CData
{ cdVerbatim = CDataText
, cdData = mempty
}
blank_element :: Element
blank_element = Element
{ elName = blank_name
, elAttribs = mempty
, elContent = mempty
}