]> gitweb @ CieloNegro.org - hxt-compile.git/commitdiff
dtd.xml
authorPHO <pho@cielonegro.org>
Tue, 9 Mar 2010 07:30:33 +0000 (16:30 +0900)
committerPHO <pho@cielonegro.org>
Tue, 9 Mar 2010 07:30:33 +0000 (16:30 +0900)
Main.hs
Text/XML/HXT/Compilation.hs
Text/XML/HXT/Compilation/XmlTree.hs
examples/dtd.xml [new file with mode: 0644]
hxt-compile.cabal

diff --git a/Main.hs b/Main.hs
index 296b252f881547b713b0e719c74ffa7ab5033c59..15482e2cd41ec821cc558bc7631979925a27a000 100644 (file)
--- a/Main.hs
+++ b/Main.hs
@@ -8,13 +8,14 @@ import qualified System.IO.UTF8 as Uio
 
 
 main :: IO ()
-main = do let fpath = "examples/utf8.xml"
+main = do let fpath = "examples/dtd.xml"
 
           [hsMod] <- runX ( setErrorMsgHandler False fail
                             >>>
                             constA fpath
                             >>>
                             readFromDocument [ (a_validate        , v_0)
+                                             , (a_canonicalize    , v_0)
                                              , (a_check_namespaces, v_1)
                                              ]
                             >>>
index c2428de92137d65c3e6904bf749b96ed35337224..e8865a153df725fef4ba327d037ef06508b5f9e7 100644 (file)
@@ -30,8 +30,8 @@ wrapIntoModule :: Arrow a => a (Module, ([HsImportDecl], (HsName, (HsQualType, H
 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
+                        imports  = [ HsImportDecl undefined (Module "Text.XML.HXT.DOM.Interface") False Nothing Nothing
+                                   , HsImportDecl undefined (Module "Text.XML.HXT.DOM.XmlNode"  ) False Nothing Nothing
                                    ] ++ extImports
                         decls    = [ HsTypeSig undefined [symName] symType
                                    , HsFunBind [HsMatch undefined symName [] (HsUnGuardedRhs symExp) []]
index 7f8d48bebe390c4e0ba45b214b0d1443b9144710..1538329147e6dc41dae613fd79a0e667aee25e04 100644 (file)
@@ -32,23 +32,37 @@ 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"          $: 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 (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"     $: compileDTDElem de         $: compileAttributes as
+compileXNode (XAttr     qn) = xn "mkAttrNode"    $: HsParen (compileQName qn)
 compileXNode (XError  n  s) = xn "mkError"       $: litInt n $: litStr s
 
 
 compileDTDElem :: DTDElem -> HsExp
-compileDTDElem = error "compileDTDElem: FIXME: not implemented"
+compileDTDElem DOCTYPE  = unq "DOCTYPE"
+compileDTDElem ELEMENT  = unq "ELEMENT"
+compileDTDElem CONTENT  = unq "CONTENT"
+compileDTDElem ATTLIST  = unq "ATTLIST"
+compileDTDElem ENTITY   = unq "ENTITY"
+compileDTDElem PENTITY  = unq "PENTITY"
+compileDTDElem NOTATION = unq "NOTATION"
+compileDTDElem CONDSECT = unq "CONDSECT"
+compileDTDElem NAME     = unq "NAME"
+compileDTDElem PEREF    = unq "PEREF"
 
 
 compileAttributes :: Attributes -> HsExp
-compileAttributes = error "compileAttributes: FIXME: not implemented"
+compileAttributes = HsList . map compileAttr
+    where
+      compileAttr :: (String, String) -> HsExp
+      compileAttr (k, v) = HsTuple [ litStr k, litStr v ]
+
 
 
 xn :: String -> HsExp
-xn = HsVar . Qual (Module "XN") . HsIdent
+--xn = HsVar . Qual (Module "XN") . HsIdent
+xn = unq
 
 unq :: String -> HsExp
 unq = HsVar . UnQual . HsIdent
diff --git a/examples/dtd.xml b/examples/dtd.xml
new file mode 100644 (file)
index 0000000..077f5cf
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE foo [
+    <!ELEMENT foo (baz)>
+    <!ELEMENT baz (#PCDATA)>
+]>
+<foo>
+  <bar>baz</bar>
+</foo>
\ No newline at end of file
index e93691ee4c271861b2b4ba0c7d52c29951d79281..e455302f438863e31c1b22a4d6512861fd49dd73 100644 (file)
@@ -10,6 +10,7 @@ Cabal-Version:       >= 1.2
 Build-Type:          Simple
 
 Extra-Source-Files:
+    examples/dtd.xml
     examples/tiny.xml
     examples/utf8.xml
 
@@ -18,6 +19,7 @@ Library
         base, haskell-src, hxt, utf8-string
     Exposed-Modules:
         Text.XML.HXT.Compilation
+    Other-Modules:
         Text.XML.HXT.Compilation.XmlTree
     Extensions:
         Arrows