~singpolyma/xml-types-haskell

ed4e0ed06f9110a90d62bd85e7701a2b48a5e5f9 — John Millikin 12 years ago 6d9f573
Add ``Ord`` instances for ``Instruction``, ``Name``, and ``Doctype``.
1 files changed, 19 insertions(+), 12 deletions(-)

M Data/XML/Types.hs
M Data/XML/Types.hs => Data/XML/Types.hs +19 -12
@@ 62,6 62,7 @@ import Control.Monad ((>=>))
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as T
import Data.String (IsString, fromString)
import Data.Function (on)

data Document = Document
	{ documentPrologue :: Prologue


@@ 81,7 82,7 @@ data Instruction = Instruction
	{ instructionTarget :: Text
	, instructionData :: Text
	}
	deriving (Show, Eq)
	deriving (Show, Eq, Ord)

data Miscellaneous
	= MiscInstruction Instruction


@@ 113,11 114,6 @@ data Content
	| ContentEntity Text
	deriving (Show, Eq)

-- | The 'Eq' instance for 'Name' ignores prefixes.
--
-- The 'IsString' instance for 'Name' allows entry using Clark notation;
-- see <http://www.jclark.com/xml/xmlns.htm> and
-- <http://infohost.nmt.edu/tcc/help/pubs/pylxml/etree-QName.html>
data Name = Name
	{ nameLocalName :: Text
	, nameNamespace :: Maybe Text


@@ 125,13 121,20 @@ data Name = Name
	}
	deriving (Show)

-- Ignore prefixes when comparing names
-- | Ignores prefixes
instance Eq Name where
	x == y = and
		[ nameLocalName x == nameLocalName y
		, nameNamespace x == nameNamespace y
		]
	(==) = (==) `on` (\x -> (nameNamespace x, nameLocalName x))

-- | Ignores prefixes
--
-- Since 0.1.3
instance Ord Name where
	compare = compare `on` (\x -> (nameNamespace x, nameLocalName x))

-- | Supports Clark notation; see <http://www.jclark.com/xml/xmlns.htm> and
-- <http://infohost.nmt.edu/tcc/help/pubs/pylxml/etree-QName.html>
--
-- Since 0.1.2
instance IsString Name where
	fromString "" = Name T.empty Nothing Nothing
	fromString full@('{':rest) = case break (== '}') rest of


@@ 155,10 158,14 @@ data Doctype = Doctype
	}
	deriving (Show, Eq)

-- | Since 0.1.3
instance Ord Doctype where
	compare = compare `on` (\x -> (doctypeName x, doctypeExternalID x))

data ExternalID
	= SystemID Text
	| PublicID Text Text
	deriving (Show, Eq)
	deriving (Show, Eq, Ord)

data InternalSubset = InternalSubset
	-- TODO