[svn] r7195: nemerle/trunk/tools/ndp: DataTree.n XMLMacro.n

marcinm svnadmin at nemerle.org
Tue Jan 2 21:26:38 CET 2007


Log:
Fixed incorrect function comparing names like Function'1, Function'1[p1,p2] etc.
Now title given by -title option is propagated to all html files.


Author: marcinm
Date: Tue Jan  2 21:26:37 2007
New Revision: 7195

Modified:
   nemerle/trunk/tools/ndp/DataTree.n
   nemerle/trunk/tools/ndp/XMLMacro.n

Modified: nemerle/trunk/tools/ndp/DataTree.n
==============================================================================
--- nemerle/trunk/tools/ndp/DataTree.n	(original)
+++ nemerle/trunk/tools/ndp/DataTree.n	Tue Jan  2 21:26:37 2007
@@ -12,6 +12,39 @@
   /// </summary>  
   internal module HtmlGenerator
   {
+    
+    // how the  n-tuple looks like in true speech
+    nemerle_tuple(n : int, start_index : int = 1) : string
+    {
+      mutable res = "Nemerle.Builtins.Tuple`" + n.ToString() + "[";
+      mutable i = start_index;
+      while (i < n) { res += "'p" + i.ToString() + ","; ++i }
+      res += "'p" + i.ToString() + "]";
+      res
+    }
+    
+    n_tuple(n : int) : string
+    {
+      mutable res = "(";
+      mutable i = 1;
+      while (i < n) { res += "'p" + i.ToString() + ","; ++i }
+      res += "'p" + i.ToString() + ")";
+      res
+    }
+    
+    /// <summary>
+    /// Replaces some complicated functions to simpler ones.
+    /// </summary>
+    replace (text : System.Text.StringBuilder) : void
+    {
+      // first deal with Nemerle.Builtins.Tuples*
+      for (mutable i = 1, i < 21, ++i) {
+        def orig_tuple = nemerle_tuple(i);
+        def repl_tuple = "<span title=\"" + orig_tuple + "\">" + n_tuple(i) + "</span>";
+        _ = text.Replace(orig_tuple, repl_tuple);
+      }
+      
+    }
     /// <summary>
     /// Writes a html file. f is a function returns a body string.
     /// </summary>
@@ -37,6 +70,7 @@
         _ = buf.Append("</html>\n");
         
         // some refinements
+        // replace(buf);
         _ = buf.Replace("&", "&amp;");
 
         def outf = IO.StreamWriter(fname);
@@ -189,10 +223,10 @@
     /// This method is called for each 'namespace' element of the tree, what results in
     /// in a html file for each namespace.
     /// </summary>
-    public virtual createPages (publicOnly : bool) : void
+    public virtual createPages (publicOnly : bool, title : string) : void
     {       
       foreach (e in elements)
-          when (e.XMLattrib.Equals(ElementType.Unknown())) e.createPages(publicOnly);    
+          when (e.XMLattrib.Equals(ElementType.Unknown())) e.createPages(publicOnly, title);    
     }
   
     /// <summary>Add comment to the current element</summary>
@@ -298,7 +332,7 @@
     }
 
     /// <summary>Creates a html page for the current namespace</summary>
-    public override createPages (publicOnly : bool) : void
+    public override createPages (publicOnly : bool, title : string) : void
     {    
       // Console.WriteLine("Zapis pliku {0}", this);
       // crreates a html page for the current namespace
@@ -306,7 +340,7 @@
       {
         def fname = this.full_name;
         mutable content = "";
-        content += HtmlGenerator.Title("Nemerle Library", "Namespace " + fname);
+        content += HtmlGenerator.Title(title, "Namespace " + fname);
         foreach (e in elements) {
           mutable priv = false;
           when (e.attribute != null)
@@ -321,7 +355,7 @@
       // creates a html page for each sub namespace
       foreach (e in elements)
         when (e.XMLattrib.Equals(ElementType.Unknown()))
-          e.createPages(publicOnly);
+          e.createPages(publicOnly, title);
     }
   
     internal new postAnalysis () : void
@@ -352,14 +386,6 @@
            this.datatree.seealsoDict[key] = this;
           }
         }
-        /*          
-         && this.datatree.seealsoDict.Contains(this.name))
-        {
-            // Console.WriteLine("Uzupełnienie słownika dla {0}", name);
-            this.datatree.seealsoDict[name] = this;
-            // Console.WriteLine("Słownik uzupełniony dla {0}", name);
-         }
-         */
             
         foreach (elem in elements) elem.postAnalysis()
     }
@@ -584,8 +610,16 @@
     // we have to compare
     private equal_names(x : string, y : string) : bool
     {
-      def res = x.Equals(y) || x.StartsWith(y) || y.StartsWith(x);
-      // when (res) Console.WriteLine("Considered equal names: {0}={1}", x, y);
+      mutable res = x.Equals(y);
+      when (!res && x.Length != y.Length)
+      {
+        def patt = ['(', '['];
+        when (x.StartsWith(y) && patt.Contains(x[y.Length])) res = true;
+        when (y.StartsWith(x) && patt.Contains(y[x.Length])) res = true;
+        
+        // when (!res && (x.StartsWith(y) || y.StartsWith(x))) Console.WriteLine("Not equals {0}<>{1}", x, y);
+      }
+      // when (res && x.Length != y.Length) Console.WriteLine("Considered equal names: {0}={1}", x, y);
       res;
     }
     
@@ -762,7 +796,7 @@
       // foreach ((k,v) in seealsoDict.KeyValuePairs) Console.WriteLine("({0}, {1}", k, v);
       
       HtmlGenerator.Page(fun () { index_content(publicOnly, title) }, "index.html");
-      tree.createPages(publicOnly);    
+      tree.createPages(publicOnly, title);
     }
     
   

Modified: nemerle/trunk/tools/ndp/XMLMacro.n
==============================================================================
--- nemerle/trunk/tools/ndp/XMLMacro.n	(original)
+++ nemerle/trunk/tools/ndp/XMLMacro.n	Tue Jan  2 21:26:37 2007
@@ -10,7 +10,7 @@
     /// class xml.saxutils.DefaultHandler. However, handlers are not impelemnted
     /// in a subclass, but are attached to as events.
     /// </summary>    
-    class SaxReader
+    public class SaxReader
     {
       mutable internal cursor : XmlTextReader;
       
@@ -24,12 +24,12 @@
           {
               match (cursor.NodeType) {
               
-                | Element => ElementEvent(cursor.Name)
-                | EndElement => EndElementEvent(cursor.Name)
-                | Text => TextEvent(cursor.Value)
-                | Document => DocumentEvent()
-                | EntityReference => EntityReferenceEvent()
-                | XmlDeclaration => XmlDeclarationEvent()
+                | Element         => when (ElementEvent != null) ElementEvent(cursor.Name)
+                | EndElement      => when (EndElementEvent != null) EndElementEvent(cursor.Name)
+                | Text            => when (TextEvent != null) TextEvent(cursor.Value)
+                | Document        => when (DocumentEvent != null) DocumentEvent()
+                | EntityReference => when (EntityReferenceEvent != null) EntityReferenceEvent()
+                | XmlDeclaration  => when (XmlDeclarationEvent != null) XmlDeclarationEvent()
                 | None => ()
                 | _ => Console.WriteLine("Unsupported XML node type {0}", cursor.NodeType)
               
@@ -61,10 +61,6 @@
       {
           cursor = XmlTextReader(filename);
           cursor.WhitespaceHandling = WhitespaceHandling.None;
-          // avoid 'not referenced' warnings
-          XmlDeclarationEvent += fun () {};
-          DocumentEvent += fun () {};
-          EntityReferenceEvent += fun () {};
           iterate();
       }
 



More information about the svn mailing list