logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

r9762 - branches/xml-namespaces/libraries/xml-parser: msg#00060

Subject: r9762 - branches/xml-namespaces/libraries/xml-parser
Author: tc
Date: Sat Jan 29 18:58:20 2005
New Revision: 9762

Added:
   branches/xml-namespaces/libraries/xml-parser/macros.dylan   (contents, props 
changed)
Modified:
   branches/xml-namespaces/libraries/xml-parser/interface.dylan
   branches/xml-namespaces/libraries/xml-parser/library.dylan
Log:
Bug: 7230
Added some macros to simplify creation of XML trees.
Opened the definition of xml-name and xml-name-setter.


Modified: branches/xml-namespaces/libraries/xml-parser/interface.dylan
==============================================================================
--- branches/xml-namespaces/libraries/xml-parser/interface.dylan        
(original)
+++ branches/xml-namespaces/libraries/xml-parser/interface.dylan        Sat Jan 
29 18:58:20 2005
@@ -3,6 +3,14 @@
 inspired-from-the-work-by: Andreas Bogk, Chris Double
 copyright: (c) 2001-2002, LGPL
 
+
+define open generic xml-name
+    (object) => the-name :: false-or(<xml-name>);
+
+define open generic xml-name-setter
+    (new-value :: false-or(<xml-name>), object)
+ => (the-name :: false-or(<xml-name>));
+
 define abstract class <xml> (<object>)
   virtual slot name;
   slot name-with-proper-capitalization :: <string>,

Modified: branches/xml-namespaces/libraries/xml-parser/library.dylan
==============================================================================
--- branches/xml-namespaces/libraries/xml-parser/library.dylan  (original)
+++ branches/xml-namespaces/libraries/xml-parser/library.dylan  Sat Jan 29 
18:58:20 2005
@@ -40,6 +40,9 @@
   create node-iterator, prepare-document;
   create transform, transform-document, before-transform, <xform-state>;
 
+  // Macros
+  create $default-xml-parent, make-xml-element;
+
   // Namespaces
   create <xml-namespace-error>,
     <namespace-not-found>, <namespace-has-no-short-name>;

Added: branches/xml-namespaces/libraries/xml-parser/macros.dylan
==============================================================================
--- (empty file)
+++ branches/xml-namespaces/libraries/xml-parser/macros.dylan   Sat Jan 29 
18:58:20 2005
@@ -0,0 +1,117 @@
+Module:    interface
+Synopsis:  Some macros to simplify creation of XML trees.
+Author:    Dr. Matthias H�lzl
+Copyright: (C) 2005, Dr. Matthias H�lzl.  All rights reserved.
+
+
+define constant $default-xml-parent = make(<document>, name: "default-parent");
+
+define macro make-xml-element-children
+  { make-xml-element-children (?result:expression) end }
+  => { ?result }
+  { make-xml-element-children (?accu:expression)
+      attribute ?:name = ?value:expression;
+      ?more:*
+    end }
+  => { make-xml-element-children (?accu)
+         ?more
+       end }
+  { make-xml-element-children (?accu:expression)
+      content ?value:expression;
+      ?more:*
+    end }
+  => { make-xml-element-children (pair(?value, ?accu))
+         ?more
+       end }
+  { make-xml-element-children (?accu:expression)
+      element ?:name = ?subelement:expression;
+      ?more:*
+    end }
+  => { make-xml-element-children
+           (pair(make-xml-element(?name) content ?subelement end, ?accu))
+         ?more
+       end }
+  { make-xml-element-children (?accu:expression)
+      element (?:name) { ?subelements:* }
+      ?more:*
+    end }
+  => { make-xml-element-children
+           (pair(make-xml-element(?name) ?subelements end, ?accu))
+         ?more
+       end }
+end macro make-xml-element-children;
+
+define macro make-xml-element-attributes
+  { make-xml-element-attributes (?result:expression) end }
+  => { ?result }
+  { make-xml-element-attributes (?accu:expression)
+      attribute ?:name = ?value:expression;
+      ?more:*
+    end }
+  => { make-xml-element-attributes
+           (pair(make(<attribute>, 
+                      name: ?"name", 
+                      value: if (instance?(?value, <string>))
+                               ?value
+                             else
+                               format-to-string("%=", ?value)
+                             end),
+                 ?accu))
+         ?more
+       end }
+  { make-xml-element-attributes (?accu:expression)
+      content ?:expression;
+      ?more:*
+    end }
+  => { make-xml-element-attributes (?accu)
+         ?more
+       end }
+  { make-xml-element-attributes (?accu:expression)
+      element ?:name = ?subelement:expression;
+      ?more:*
+    end }
+  => { make-xml-element-attributes (?accu)
+         ?more
+       end }
+  { make-xml-element-attributes (?accu:expression)
+      element (?:name) { ?subelements:* }
+      ?more:*
+    end }
+  => { make-xml-element-attributes (?accu)
+         ?more
+       end }
+end macro make-xml-element-attributes;
+
+define macro make-xml-element
+  { make-xml-element (?:name) ?content:* end }
+  => { make(<element>, 
+            name: ?"name",
+            parent: $default-xml-parent,
+            children: as(<stretchy-object-vector>,
+                         make-xml-element-children (#()) ?content end),
+            attributes: as(<stretchy-object-vector>,
+                           make-xml-element-attributes (#()) ?content end)) }
+end macro make-xml-element;
+/*
+define variable *elt* = 
+  make-xml-element (foo)
+    attribute a1 = 123;
+    attribute a2 = 234;
+    element (bar) {
+      attribute b1 = "x";
+      attribute b2 = 2;
+      // content #(1, 2, 3);
+      element (sub) {
+        attribute x = 7;
+        // content #"asdf";
+      }
+      attribute b3 = 7;
+    }
+    // content "x";
+    // content #"y";
+    attribute a3 = 123.3;
+  end make-xml-element;
+
+format-out("%S\n%=\n", *elt*, *elt*);
+*/
+
-- 
Gd-chatter mailing list
Gd-chatter@xxxxxxxxxxxxxxxx
https://gauss.gwydiondylan.org/mailman/listinfo/gd-chatter



<Prev in Thread] Current Thread [Next in Thread>