From 9326d59bc2dbf54de0bf3c6a249093704a365a14 Mon Sep 17 00:00:00 2001 From: PHO Date: Wed, 11 Feb 2009 02:05:19 +0900 Subject: [PATCH] Compilation.XmlTree --- Text/XML/HXT/Compilation/XmlTree.hs | 64 +++++++++++++++++++++++++++++ hxt-compile.cabal | 4 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Text/XML/HXT/Compilation/XmlTree.hs diff --git a/Text/XML/HXT/Compilation/XmlTree.hs b/Text/XML/HXT/Compilation/XmlTree.hs new file mode 100644 index 0000000..7884c77 --- /dev/null +++ b/Text/XML/HXT/Compilation/XmlTree.hs @@ -0,0 +1,64 @@ +module Text.XML.HXT.Compilation.XmlTree + ( compileXmlTree + ) + where + +import Language.Haskell.Syntax +import Text.XML.HXT.DOM.QualifiedName +import Text.XML.HXT.DOM.XmlNode +import Text.XML.HXT.DOM.TypeDefs + + +compileXmlTrees :: XmlTrees -> HsExp +compileXmlTrees = HsList . map compileXmlTree + + +compileXmlTree :: XmlTree -> HsExp +compileXmlTree t + = let node = compileXNode (getNode t) + children = HsList (map compileXmlTree (getChildren t)) + in + xn "mkTree" $: node $: children + + +compileXNode :: XNode -> HsExp +compileXNode (XText s) = xn "mkText" $: litStr s +compileXNode (XCharRef n) = xn "mkCharRef" $: litInt n +compileXNode (XEntityRef s) = xn "mkEntityRef" $: litStr s +compileXNode (XCmt s) = xn "mkCmt" $: litStr s +compileXNode (XCdata s) = xn "mkCdata" $: litStr s +compileXNode (XPi qn ts) = xn "mkPi" $: compileQName qn $: compileXmlTrees ts +compileXNode (XTag qn ts) = xn "mkElementNode" $: compileQName qn $: compileXmlTrees ts +compileXNode (XDTD de as) = xn "mkDTDNode" $: compileDTDElem de $: compileAttributes as +compileXNode (XAttr qn) = xn "mkAttrNode" $: compileQName qn +compileXNode (XError n s) = xn "mkError" $: litInt n $: litStr s + + +compileDTDElem :: DTDElem -> HsExp +compileDTDElem = error "compileDTDElem: FIXME: not implemented" + + +compileAttributes :: Attributes -> HsExp +compileAttributes = error "compileAttributes: FIXME: not implemented" + + +xn :: String -> HsExp +xn = HsVar . Qual (Module "XN") . HsIdent + + +litStr :: String -> HsExp +litStr = HsLit . HsString + + +litInt :: Integral a => a -> HsExp +litInt = HsLit . HsInt . toInteger + + +infixl $: +($:) :: HsExp -> HsExp -> HsExp +($:) = HsApp + + +compileQName :: QName -> HsExp +compileQName (QN prefix local ns) + = xn "mkQName" $: litStr prefix $: litStr local $: litStr ns diff --git a/hxt-compile.cabal b/hxt-compile.cabal index a9124df..e8ba617 100644 --- a/hxt-compile.cabal +++ b/hxt-compile.cabal @@ -11,9 +11,11 @@ Build-Type: Simple Library Build-Depends: - base + base, haskell-src, hxt Exposed-Modules: Text.XML.HXT.Compilation + Text.XML.HXT.Compilation.XmlTree + GHC-Options: -Wall Executable hxt-compile Main-Is: Main.hs -- 2.40.0