X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=hxt-compile.git;a=blobdiff_plain;f=Text%2FXML%2FHXT%2FCompilation%2FXmlTree.hs;fp=Text%2FXML%2FHXT%2FCompilation%2FXmlTree.hs;h=37bb842ad370dd1564ca232f88e43f27f49e3d94;hp=7884c771bb632bfc428b5dbee61ce5c1a625fc15;hb=5ccdec1d86b750444704312526a44eb68972027b;hpb=9326d59bc2dbf54de0bf3c6a249093704a365a14 diff --git a/Text/XML/HXT/Compilation/XmlTree.hs b/Text/XML/HXT/Compilation/XmlTree.hs index 7884c77..37bb842 100644 --- a/Text/XML/HXT/Compilation/XmlTree.hs +++ b/Text/XML/HXT/Compilation/XmlTree.hs @@ -1,5 +1,10 @@ module Text.XML.HXT.Compilation.XmlTree ( compileXmlTree + , compileXmlTrees + , compileXNode + , compileDTDElem + , compileAttributes + , compileQName ) where @@ -9,16 +14,16 @@ 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 + xn "mkTree" $: HsParen node $: children + + +compileXmlTrees :: XmlTrees -> HsExp +compileXmlTrees = HsList . map compileXmlTree compileXNode :: XNode -> HsExp @@ -27,11 +32,11 @@ 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 +compileXNode (XPi qn ts) = xn "mkPi" $: HsParen (compileQName qn) $: compileXmlTrees ts +compileXNode (XTag qn ts) = xn "mkElementNode" $: HsParen (compileQName qn) $: compileXmlTrees ts +compileXNode (XDTD de as) = xn "mkDTDNode" $: HsParen (compileDTDElem de) $: HsParen (compileAttributes as) +compileXNode (XAttr qn) = xn "mkAttrNode" $: HsParen (compileQName qn) +compileXNode (XError n s) = xn "mkError" $: litInt n $: litStr s compileDTDElem :: DTDElem -> HsExp @@ -45,6 +50,9 @@ compileAttributes = error "compileAttributes: FIXME: not implemented" xn :: String -> HsExp xn = HsVar . Qual (Module "XN") . HsIdent +unq :: String -> HsExp +unq = HsVar . UnQual . HsIdent + litStr :: String -> HsExp litStr = HsLit . HsString @@ -54,11 +62,11 @@ litInt :: Integral a => a -> HsExp litInt = HsLit . HsInt . toInteger -infixl $: +infixr 5 $: ($:) :: HsExp -> HsExp -> HsExp -($:) = HsApp +a $: b = HsApp a b compileQName :: QName -> HsExp compileQName (QN prefix local ns) - = xn "mkQName" $: litStr prefix $: litStr local $: litStr ns + = unq "mkQName" $: litStr prefix $: litStr local $: litStr ns