[svn] r7252: nemerle/trunk/tools/ndp: DataTree.n NemerleDoc.n

marcinm svnadmin at nemerle.org
Fri Jan 12 00:13:10 CET 2007


Log:
Elements are alphabetically ordered (but ctors are on the top). Preliminary version of the replacing some monster type expressions (e.g. Function[Tuple....]) by simpler ones.


Author: marcinm
Date: Fri Jan 12 00:13:10 2007
New Revision: 7252

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

Modified: nemerle/trunk/tools/ndp/DataTree.n
==============================================================================
--- nemerle/trunk/tools/ndp/DataTree.n	(original)
+++ nemerle/trunk/tools/ndp/DataTree.n	Fri Jan 12 00:13:10 2007
@@ -6,6 +6,7 @@
   using System;
   using Nemerle.Collections;
   using System.Reflection;
+  using System.Text.RegularExpressions;
 
   /// <summary>
   /// Contains common html headers and footers, generates and writes html to a file.
@@ -13,37 +14,113 @@
   internal module HtmlGenerator
   {
     
-    // how the  n-tuple looks like in true speech
-    nemerle_tuple(n : int, start_index : int = 1) : string
+    debug (str : string, params arg : array [ object ]) : void
     {
-      mutable res = "Nemerle.Builtins.Tuple`" + n.ToString() + "[";
-      mutable i = start_index;
-      while (i < n) { res += "'p" + i.ToString() + ","; ++i }
-      res += "'p" + i.ToString() + "]";
-      res
+      when (Nemerledoc.debug) Console.WriteLine(str, arg);
     }
     
-    n_tuple(n : int) : string
-    {
-      mutable res = "(";
-      mutable i = 1;
-      while (i < n) { res += "'p" + i.ToString() + ","; ++i }
-      res += "'p" + i.ToString() + ")";
-      res
-    }
+    regExFunVoidNs : Regex = Regex(
+              @"(?<pref>.*)Nemerle\.Builtins\.FunctionVoid`(?<numargs>\d*)\[(?<arg>.*)\](?<post>.*)",
+              RegexOptions.Compiled);
+    regExFunVoid : Regex = Regex(
+              @"(?<pref>.*)FunctionVoid`(?<numargs>\d*)\[(?<arg>.*)\](?<post>.*)",
+              RegexOptions.Compiled);
+              
+    regExFunNs : Regex = Regex(
+              @"(?<pref>.*)Nemerle\.Builtins\.Function`(?<numargs>\d*)\[(?<arg>.*)\](?<post>.*)",
+              RegexOptions.Compiled);
+    regExFun : Regex = Regex(
+              @"(?<pref>.*)Function`(?<numargs>\d*)\[(?<arg>.*)\](?<post>.*)",
+              RegexOptions.Compiled);
+              
+    regExTupleNs : Regex = Regex(
+              @"(?<pref>.*)Nemerle.Builtins.Tuple`(?<numargs>\d*)\[(?<arg>.*)\](?<post>.*)",
+              RegexOptions.Compiled);
+    regExTuple : Regex = Regex(
+              @"(?<pref>.*)Tuple`(?<numargs>\d*)\[(?<arg>.*)\](?<post>.*)",
+              RegexOptions.Compiled);
     
     /// <summary>
     /// Replaces some complicated functions to simpler ones.
     /// </summary>
-    replace (text : System.Text.StringBuilder) : void
+    internal replace (text : string) : string
+    {
+      mutable res = text;
+      
+      // FunctionVoid      
+      if (text.IndexOf("FunctionVoid") > -1) {
+        // FunctionVoid with namespace (e.g. as argument)
+        when (regExFunVoidNs.IsMatch(text))
+        {
+          def resMatch = regExFunVoidNs.Match(text);
+          debug("*Nem.Built.FunVoid* {0}\n**** {1}\n**** {2}\n**** {3}", text, resMatch.Result("${pref}"), resMatch.Result("${arg}"), resMatch.Result("${post}"));
+          def arg = replace(resMatch.Result("${arg}"));
+          
+          res = resMatch.Result("${pref}") + "(" + arg + ") -> void" + resMatch.Result("${post}");
+        }
+        
+        // FunctionVoid without namespace (e.g. as argument)
+        when (regExFunVoid.IsMatch(text))
+        {
+          def resMatch = regExFunVoid.Match(text);
+          debug("*FunVoid* {0}\n**** {1}\n**** {2}\n**** {3}", text, resMatch.Result("${pref}"), resMatch.Result("${arg}"), resMatch.Result("${post}"));
+          def arg = replace(resMatch.Result("${arg}"));
+          
+          res = resMatch.Result("${pref}") + "(" + arg + ") -> void" + resMatch.Result("${post}");
+        }
+      }
+      
+      // Function'...
+      else if (text.IndexOf("Function") > -1) {
+        // FunctionVoid with namespace (e.g. as argument)
+        when (regExFunNs.IsMatch(text))
+        {
+          def resMatch = regExFunNs.Match(text);
+          debug("*Nem.Built.Fun* {0}\n**** {1}\n**** {2}\n**** {3}", text, resMatch.Result("${pref}"), resMatch.Result("${arg}"), resMatch.Result("${post}"));
+          def arg = replace(resMatch.Result("${arg}"));
+          
+          res = resMatch.Result("${pref}") + "(" + arg + ") -> void" + resMatch.Result("${post}");
+        }
+        
+        // FunctionVoid without namespace (e.g. as argument)
+        when (regExFun.IsMatch(text))
     {
-      // 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);
+          def resMatch = regExFun.Match(text);
+          debug("*Fun* {0}\n**** {1}\n**** {2}\n**** {3}", text, resMatch.Result("${pref}"), resMatch.Result("${arg}"), resMatch.Result("${post}"));
+          def arg = replace(resMatch.Result("${arg}"));
+          
+          res = resMatch.Result("${pref}") + "(" + arg + ") -> void" + resMatch.Result("${post}");
+        }
       }
       
+      // Tuple
+      else when (text.IndexOf("Tuple") > -1)
+      {
+        // second deal with Nemerle.Builtins.Tuples*
+        when (regExTupleNs.IsMatch(text))
+        {
+          def resMatch = regExTupleNs.Match(text);
+          def arg = resMatch.Result("${arg}");
+          def pref = resMatch.Result("${pref}");
+          def post = resMatch.Result("${post}");
+          debug("*tuple* {0}\npref **** {1}\narg**** {2}\n**** {3}", text, pref, arg, post);
+          
+          res = pref + "(" + arg + ")" + post;
+        }
+        
+        when (regExTuple.IsMatch(text))
+        {
+          def resMatch = regExTuple.Match(text);
+          def arg = resMatch.Result("${arg}");
+          def pref = resMatch.Result("${pref}");
+          def post = resMatch.Result("${post}");
+          debug("*tuple* {0}\npref **** {1}\narg**** {2}\n**** {3}", text, pref, arg, post);
+          
+          res = pref + "(" + arg + ")" + post;
+        }
+      }
+      when (!res.Equals(text)) debug("{0} ==>\n{1}\n", text, res);
+      if (Nemerledoc.simplify) res else text
     }
     /// <summary>
     /// Writes a html file. f is a function returns a body string.
@@ -168,7 +245,7 @@
       res += "<span class=\"ns-index\" id=\"" + this.href() + "\">" + (if (ns.Length == 0) "Root namespace" else "Namespace " + ns) +"</span>\n";
       
       // do TOC in the following order: first ordered namespaces, then ordered classes
-      def sort = fun (x, y) { String.Compare(x.name, y.name) };
+      def sort = fun (x, y) { String.Compare(x.true_name, y.true_name) };
       def class_list = List.Sort(List.RevFilter(elements, fun (cl) { cl.XMLattrib.Equals(ElementType.Type() ) }), sort);
       def ns_list = List.Sort(List.RevFilter(elements, fun (cl) { cl.XMLattrib.Equals(ElementType.Unknown() ) }), sort);
       def ord_list = ns_list + class_list;
@@ -184,7 +261,7 @@
             res += "<div title=\"" + e.full_name + "\" class=\"index-element\">";
             res += match (e.XMLattrib) { | Type => "class" | Unknown => "namespace" | _ => e.XMLattrib.ToString() };
             res += " ";
-            res += "<a href=\"" + ahref + "\">" + e.name + "</a>";
+            res += "<a href=\"" + ahref + "\">" + e.Name + "</a>";
             res += if (comment.Length > 0) "<div class=\"comment\">Comment: " + comment + "</div>" else "";
             res += if (remark.Length > 0) "<div class=\"remark\">Remark: " + remark + "</div>" else "";
             res += "</div>\n";
@@ -297,8 +374,20 @@
     /// This field is set by XML analyzer</summary>
     public mutable XMLattrib : ElementType = ElementType.Unknown();
     
-    /// <summary>Name of the element</summary>
-    public mutable name : string;
+    /// prefix (i.e. namespaces.classes.etc)
+    mutable prefix : string = "";
+    /// <summary>True (e.g. monster name with Tuple20) of the element</summary>
+    mutable public true_name : string;
+    /// <summary>Full name of the element (with namespace path)</summary>
+    public full_name : string { get { (if (this.prefix.Length > 0) this.prefix + "." else "") + this.true_name }};
+    // after some face_lifting
+    mutable lifted_name : string;
+    
+    public Name : string
+    {
+      get { when (lifted_name == null) lifted_name = HtmlGenerator.replace(true_name) ; lifted_name }
+    }
+    
     
     /// <summary>An anchor ref, used in html generation</summary>
     public override href () : string 
@@ -307,8 +396,6 @@
       else "id" + this.GetHashCode().ToString()
     }
     
-    /// <summary>Full name of the element (with namespace path)</summary>
-    public mutable full_name : string = "";
   
     /// <summary>Returns the name of a file including description of the current node</summary>
     internal override html_file (): string
@@ -379,7 +466,7 @@
           // find a reference
           mutable key = null;
           foreach (kV in this.datatree.seealsoDict)
-            when (name.StartsWith(kV.Key)) key = kV.Key;
+            when (this.true_name.StartsWith(kV.Key)) key = kV.Key;
           when (key != null)
           {
            // Console.WriteLine("Dodanie do klucza" +  key);
@@ -392,8 +479,8 @@
 
     public this(name : string, prefiks : string, parent : TopNode)
     {
-      this.name = name;
-      this.full_name = prefiks;
+      this.true_name = name;
+      this.prefix = prefiks;
       this.parent = parent;
       this.datatree = parent.datatree;
       // Console.WriteLine("Nowy element Name " + prefiks);
@@ -406,8 +493,8 @@
       def sort = fun (a : Node, b : Node) {
       
         // ctor(System.String) are compared incorrectly, so use the prefix
-        def comp_a = if (a.name.StartsWith(".ctor")) ".ctor" else if (a.name.StartsWith("ctor")) "ctor" else if (a.name.StartsWith("cctor")) "cctor" else a.name;
-        def comp_b = if (b.name.StartsWith(".ctor")) ".ctor" else if (b.name.StartsWith("ctor")) "ctor" else if (b.name.StartsWith("cctor")) "cctor" else b.name;
+        def comp_a = if (a.true_name.StartsWith(".ctor")) ".ctor" else if (a.true_name.StartsWith("ctor")) "ctor" else if (a.true_name.StartsWith("cctor")) "cctor" else a.true_name;
+        def comp_b = if (b.true_name.StartsWith(".ctor")) ".ctor" else if (b.true_name.StartsWith("ctor")) "ctor" else if (b.true_name.StartsWith("cctor")) "cctor" else b.true_name;
         
         def r = match ((comp_a, comp_b)) {
           | (".ctor", "ctor") => -1
@@ -422,7 +509,7 @@
           | (_, "ctor") => 1
           | ("cctor", _) => -1
           | (_, "cctor") => 1
-          | _ => String.Compare(a.name, b.name)
+          | _ => String.Compare(a.true_name, b.true_name)
         }
         // Console.WriteLine("Porównanie '{0}' i '{1}' zwraca {2}", a.name, b.name, r);
         r;
@@ -438,6 +525,7 @@
     /// <summary>Create a full html description of the current node.</summary>
     public ToHtml () : string
     {
+      // Console.WriteLine("true_name {0}, name {1}, prefix {2}", true_name, this.Name, this.prefix );
       mutable res = "";
       mutable com = if (comment.Length > 0) "<div class=\"comment\">" + comment + "</div>\n" else "";
       com += if (remark.Length > 0) "<div class=\"remark\">Remark: " + remark + "</div>\n" else "";
@@ -487,17 +575,17 @@
         | Unknown => 
             res += "<div>Unknown element " + this.full_name + "</div>";
             
-        | Property => res += "<span title=\"" + this.full_name + "\">" + att + name + "</span>" + com;
+        | Property => res += "<span title=\"" + this.full_name + "\">" + att + this.Name + "</span>" + com;
         
-        | Method => res += "<span title=\"" + this.full_name + "\">" + att + name + "</span>" + com;
+        | Method => res += "<span title=\"" + this.full_name + "\">" + att + this.Name + "</span>" + com;
         
-        | Field => res += att + name + com;
+        | Field => res += att + this.Name + com;
         
-        | Event => res += att + name + com;
+        | Event => res += att + this.Name + com;
         
         | Type =>
             res += "<div class=\"ns-index\"" + (" id=\"" + this.href() + "\"") + ">" + att;
-            res += "<span class=\"ns-index\" title=\"" + this.full_name + "\">" + name + "</span>\n";
+            res += "<span class=\"ns-index\" title=\"" + this.full_name + "\">" + this.Name + "</span>\n";
             res += com;
           
             def mk_element = fun (e) { "<div class=\"element\" id=\"" + e.href() + "\">" + e.ToHtml() + "</div>\n"};
@@ -627,9 +715,9 @@
     {
       mutable res = null;
       foreach (e in set.elements) // when (name.Equals(e.name)) res = e;
-          when (equal_names(e.name, name)){
+          when (equal_names(e.true_name, name)){
               res = e;
-              when (name.Length > e.name.Length) e.name = name;
+              when (name.Length > e.true_name.Length) e.true_name = name;
           }
       res;
     }
@@ -653,7 +741,7 @@
         
         when (next == null)
         {
-          def pref = if (pointer is Node) ((pointer :> Node).full_name + "." + edge) else edge;
+          def pref = if (pointer is Node) ((pointer :> Node).full_name) else "";
           next = Node(edge, pref, pointer);
           pointer.elements = pointer.elements + [ next ];
         }
@@ -680,7 +768,7 @@
         next = memb(pointer, edge);
         when (next == null)
         {
-          def prefix = if (pointer is Node) ((pointer :> Node).full_name + "." + edge) else edge;
+          def prefix = if (pointer is Node) ((pointer :> Node).full_name ) else "";
           next = Node(edge, prefix, pointer);
           pointer.elements = pointer.elements + [ next ];
         }
@@ -719,7 +807,7 @@
         next = memb(pointer, edge);
         when (next == null)
         {
-          def pref = if (pointer is Node) ((pointer :> Node).full_name + "." + edge) else edge;
+          def pref = if (pointer is Node) ((pointer :> Node).full_name) else "";
           next = Node(edge, pref, pointer);
           pointer.elements = pointer.elements + [ next ];
         }

Modified: nemerle/trunk/tools/ndp/NemerleDoc.n
==============================================================================
--- nemerle/trunk/tools/ndp/NemerleDoc.n	(original)
+++ nemerle/trunk/tools/ndp/NemerleDoc.n	Fri Jan 12 00:13:10 2007
@@ -37,11 +37,21 @@
   Help () : void {
     Console.WriteLine("USAGE:");
     Console.WriteLine("  nemerledoc.exe <options> <files>");
-    Console.WriteLine("     <options>: -np show non public elements, -title:\"title\" title for index page");
+    Console.WriteLine("     <options>:");
+    Console.WriteLine("             -np show non public elements, -title:\"title\" title for index page");
+    Console.WriteLine("             -s simplifies some monster type expressions, functions, tuples etc.");
+    Console.WriteLine("             -d debug info");
     Console.WriteLine("     <files>: a list of *.dll and *.xml files");
   }
 
   /// <summary>
+  /// Whether to simplify monsters like Function'x[Tuple'20[.....]]
+  /// </summary>
+  public mutable simplify : bool = false;
+  
+  public mutable debug : bool = false;
+
+  /// <summary>
   /// Usage:
   /// <code>nemerledoc.exe &amp;lt;options&amp;gt; &amp;lt;files&amp;gt;</code>
   /// Writing <c>nemerledoc.exe</c> shows this info. 
@@ -62,6 +72,8 @@
             _ = XmlDocParser(tree, file);
       
           if (file.Equals("-np")) publicOnly = false
+          else if (file.Equals("-s")) simplify = true
+          else if (file.Equals("-d")) debug = true
           else if (file.StartsWith("-title")) title = file.Substring(7)
           else tree.AddSource(file);
         }



More information about the svn mailing list