]> gitweb @ CieloNegro.org - hxt-compile.git/blobdiff - Text/XML/HXT/Compilation.hs
filterOutRootAttrs
[hxt-compile.git] / Text / XML / HXT / Compilation.hs
index 9b2f105cf207b9ebc11f6ba0d07cc2d629ce85a7..c2428de92137d65c3e6904bf749b96ed35337224 100644 (file)
@@ -1,4 +1,39 @@
 module Text.XML.HXT.Compilation
-    (
+    ( compileDocument
+    , wrapIntoModule
     )
     where
+
+import           Language.Haskell.Syntax
+import           Text.XML.HXT.Arrow
+import           Text.XML.HXT.Compilation.XmlTree
+
+
+compileDocument :: ArrowXml a => a XmlTree (HsQualType, HsExp)
+compileDocument = uniqueNamespacesFromDeclAndQNames
+                  >>>
+                  filterOutRootAttrs
+                  >>>
+                  ( constA (HsQualType [] (HsTyCon (UnQual (HsIdent "XmlTree"))))
+                    &&&
+                    arr compileXmlTree
+                  )
+
+
+filterOutRootAttrs :: ArrowXml a => a XmlTree XmlTree
+filterOutRootAttrs = processTopDownUntil (clearAttrs `when` isRoot)
+    where
+      clearAttrs = processAttrl none
+
+
+wrapIntoModule :: Arrow a => a (Module, ([HsImportDecl], (HsName, (HsQualType, HsExp)))) HsModule
+wrapIntoModule = proc (modName, (extImports, (symName, (symType, symExp)))) ->
+                 do let hsModule = HsModule undefined modName (Just exports) imports decls
+                        exports  = [HsEVar (UnQual symName)]
+                        imports  = [ HsImportDecl undefined (Module "Text.XML.HXT.Arrow") False Nothing Nothing
+                                   , HsImportDecl undefined (Module "Text.XML.HXT.DOM.XmlNode") True (Just (Module "XN")) Nothing
+                                   ] ++ extImports
+                        decls    = [ HsTypeSig undefined [symName] symType
+                                   , HsFunBind [HsMatch undefined symName [] (HsUnGuardedRhs symExp) []]
+                                   ]
+                    returnA -< hsModule