{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Language.TCT.Write.XML where
import Data.Functor (Functor(..), (<$>))
import Data.Maybe (Maybe(..), maybe)
import Data.Monoid (Monoid(..))
-import Data.Ord (Ord(..))
import Data.Semigroup (Semigroup(..))
import Data.Sequence (Seq, ViewL(..), ViewR(..), (<|), (|>))
import Data.Set (Set)
-import Data.String (IsString(..))
import Data.Text (Text)
import Data.TreeSeq.Strict (Tree(..))
import GHC.Exts (toList)
-import Prelude (error, undefined)
-import Text.Show (Show(..), showChar, showString)
+import Prelude (undefined)
import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Sequence as Seq
import qualified Language.TCT.Write.Text as Write
import qualified System.FilePath as FP
+import Text.Blaze.XML ()
import Language.TCT hiding (Parser)
+import Language.XML
import qualified Data.TreeSeq.Strict as TreeSeq
--- * Type 'XML'
-type XML = Tree (Cell XmlName) (Cell XmlLeaf)
-type XMLs = Seq XML
-
--- ** Type 'XmlName'
-data XmlName
- = XmlName
- { xmlNamePrefix :: Text
- , xmlNameSpace :: Text
- , xmlNameLocal :: Text
- }
-instance Show XmlName where
- showsPrec _p XmlName{xmlNameSpace="", ..} =
- showString (Text.unpack xmlNameLocal)
- showsPrec _p XmlName{..} =
- if Text.null xmlNameSpace
- then showString (Text.unpack xmlNameLocal)
- else
- showChar '{' .
- showString (Text.unpack xmlNameSpace) .
- showChar '}' .
- showString (Text.unpack xmlNameLocal)
-instance Eq XmlName where
- XmlName _ sx lx == XmlName _ sy ly = sx == sy && lx == ly
-instance Ord XmlName where
- XmlName _ sx lx `compare` XmlName _ sy ly = compare sx sy <> compare lx ly
-instance IsString XmlName where
- fromString "" = XmlName "" "" ""
- fromString full@('{':rest) =
- case List.break (== '}') rest of
- (_, "") -> error ("Invalid Clark notation: " <> show full)
- (ns, local) -> XmlName "" (Text.pack ns) (Text.pack $ List.drop 1 local)
- fromString local = XmlName "" "" (Text.pack local)
-
-xmlLocalName :: Text -> XmlName
-xmlLocalName = XmlName "" ""
-
--- ** Type 'XmlLeaf'
-data XmlLeaf
- = XmlAttr XmlName Text
- | XmlComment Text
- | XmlText Text
- deriving (Eq,Ord,Show)
-
-- * Type 'InhXml'
data InhXml
= InhXml
goTokens $
rs |> Cell br er (TokenPlain (Text.dropAround Char.isSpace r))
_ -> goTokens toks
- TokenPair PairHash (toList -> [unCell -> TokenPlain t]) ->
+ TokenPair PairHash to ->
Seq.singleton $
TreeN (cell "ref") $
- xmlAttrs [cell ("to",t)]
+ xmlAttrs [cell ("to",TL.toStrict $ Write.textTokens to)]
TokenPair (PairElem name attrs) ts ->
Seq.singleton $
TreeN (cell $ xmlLocalName name) $