[svn] r7122: nemerle/trunk/tools/ndp: AssemblyAnalyzer.n DataTree.n Makefile XMLMacro.n nemerle-doc.css

marcinm svnadmin at nemerle.org
Tue Dec 19 21:01:18 CET 2006


Log:
Updates and bug fixes. Completely new XML parser, it now accepts all
tags. More info from assemblies.


Author: marcinm
Date: Tue Dec 19 21:01:17 2006
New Revision: 7122

Modified:
   nemerle/trunk/tools/ndp/AssemblyAnalyzer.n
   nemerle/trunk/tools/ndp/DataTree.n
   nemerle/trunk/tools/ndp/Makefile
   nemerle/trunk/tools/ndp/XMLMacro.n
   nemerle/trunk/tools/ndp/nemerle-doc.css

Modified: nemerle/trunk/tools/ndp/AssemblyAnalyzer.n
==============================================================================
--- nemerle/trunk/tools/ndp/AssemblyAnalyzer.n	(original)
+++ nemerle/trunk/tools/ndp/AssemblyAnalyzer.n	Tue Dec 19 21:01:17 2006
@@ -6,47 +6,53 @@
 namespace NemerleDoc
 {
 
-module AssemblyAnalyzer
-{
-  mutable ass : Assembly;
-  public analyze (filename : string, tree : DataTree) : void
-  {
-    ass = Assembly.LoadFile(filename);
-    // Console.WriteLine("Codebase={0}\nFullName={1}\nLocation={2}", ass.CodeBase, ass.FullName, ass.Location);
-    foreach (t in ass.GetTypes())
+  module AssemblyAnalyzer
     {
-      // Console.WriteLine("\n\n--> NameSp: {0}, name: {1}, FullName: {2}", t.Namespace,  t.Name, t.FullName,);
-      // Console.WriteLine("--> Attrib {0}, BaseType: {1}, DeclaredType: {2}", t.Attributes, t.BaseType, t.DeclaringType);
+    mutable ass : Assembly;
       
+    type_analyzer (t : System.Type, tree : DataTree) : void
+    {
       /*
-      when (t.IsAbstract)  Console.WriteLine("--> abstract");
-      when (t.IsArray)     Console.WriteLine("--> array ");
-      when (t.IsClass)     Console.WriteLine("--> class ");
-      when (t.IsInterface) Console.WriteLine("--> interface ");
+        Console.WriteLine("\n\n--> NameSp: {0}, name: {1}, FullName: {2}", t.Namespace,  t.Name, t.FullName,);
+        Console.WriteLine("--> Attrib {0}, BaseType: {1}, DeclaredType: {2}", t.Attributes, t.BaseType, t.DeclaringType);
+        Console.WriteLine("--> Type analyzer: Name {0} Attrib {1}", t.FullName, t.Attributes);
       */
+        // analyze attributes      
+        def attr = ReflAttribs(is_abstract=t.IsAbstract,
+                               is_array=t.IsArray,
+                               is_class=t.IsClass,
+                               is_interface=t.IsInterface,
+                               attr=t.Attributes);
       
-      tree.AddItem(t.FullName, t.Attributes, ElementType.Type());
+        tree.AddItem(t.FullName, ElementType.Type(), attr);
       
       foreach (m in t.GetMembers()) {
-        // Console.WriteLine("----> DeclType {0}, MemTye {1}, Name {2}, ReflType {3}", m.DeclaringType, m.MemberType, m.Name, m.ReflectedType);
-        // Console.WriteLine("----> GetType {0} ", m.GetType());
+          // Console.WriteLine("------> DeclType {0}, MemTye {1}, Name {2}, ReflType {3}", m.DeclaringType, m.MemberType, m.Name, m.ReflectedType);
+          // Console.WriteLine("------> GetType {0} ", m.GetType());
         def ty =
           match (m.MemberType) {
-            | Method => ElementType.Method()
-            | Property => ElementType.Property()
             | Constructor => ElementType.Method()
             | Field => ElementType.Field()
-            | NestedType => ElementType.Unknown()
-            | _ => null
+              | Method => ElementType.Method()
+              | Property => ElementType.Property()
+              | _ => ElementType.Unknown()
           }
+            
+          
         if (ty != null)
           tree.AddItem(m.DeclaringType.ToString(), m.Name, ty)
         else Console.WriteLine("*** Rejected {0} ***, {1}", m.Name, m.MemberType);
-          
       }
     }
   
-  }
+    public analyze (filename : string, tree : DataTree) : void
+    {
+      ass = Assembly.LoadFile(filename);
+      // Console.WriteLine("Codebase={0}\nFullName={1}\nLocation={2}", ass.CodeBase, ass.FullName, ass.Location);
+      foreach (t in ass.GetTypes())
+        type_analyzer(t, tree)
+    } // end subroutine
+    
+  } // end module
 
-}
-}
+} // end namespace

Modified: nemerle/trunk/tools/ndp/DataTree.n
==============================================================================
--- nemerle/trunk/tools/ndp/DataTree.n	(original)
+++ nemerle/trunk/tools/ndp/DataTree.n	Tue Dec 19 21:01:17 2006
@@ -1,12 +1,25 @@
-using System;
-using Nemerle.Collections;
 
 
-namespace NemerleDoc {
-module HtmlGenerator
+namespace NemerleDoc
 {
+
+  using System;
+  using Nemerle.Collections;
+  using System.Reflection;
+
+  /// <summary>
+  /// Generates and writes to a file a html page.
+  /// </summary>  
+  internal module HtmlGenerator
+  {
+    /// <summary>
+    /// Writes a html file. f is a function returns a body string.
+    /// </summary>
   public Page (f : void -> string, fname : string) : void
   {
+    
+        def body = f();
+        
     def buf = System.Text.StringBuilder();
     _ = buf.Append("<?xml version=\"1.0\"?>\n");
     _ = buf.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n");
@@ -18,17 +31,23 @@
     _ = buf.Append("<link rel=\"stylesheet\" type=\"text/css\" href=\"nemerle-doc.css\" />\n");
     _ = buf.Append("</head>\n");
     _ = buf.Append("<body>\n");
-    _ = buf.Append(f());
+        _ = buf.Append(body);
     _ = buf.Append("<div class=\"footer\">Nemerle Documentation Project</div>");
     _ = buf.Append("</body>\n");
     _ = buf.Append("</html>\n");
 
+        // some refinements
+        _ = buf.Replace("&", "&amp;");
+
     def outf = IO.StreamWriter(fname);
     outf.Write(buf);
     outf.Close();
     // Console.WriteLine("---> zapis do {0}", fname);
   }
 
+    /// <summary>
+    /// Generates a header of a page.
+    /// </summary>
   public Title (title : string, subtitle : string) : string
   {
     mutable content = "";
@@ -40,56 +59,75 @@
     content += "</div>\n\n";
     content;  
   }
+  } // module htmlgenerator
 
-}
-
-variant ElementType
-{
+  /// <summary>
+  /// Type of the element. This attribute is set by XML parser.
+  /// </summary>
+  public variant ElementType
+  {
   | Unknown
   | Property
   | Method
   | Field
   | Type
-}
+  }
 
-/// <summary>
-/// Top node of the tree representing a 'top' namespace, even if it is
-/// empty (how's it called, by the way?)
-/// </summary>
-class TopNode
-{
+  [Record]
+  sealed class ReflAttribs
+  {
+    internal is_interface : bool;
+    internal is_abstract : bool;
+    internal is_class : bool;
+    internal is_array : bool;
+    internal attr : System.Reflection.TypeAttributes;
+    internal Private : bool
+    {
+      // get { (attr & TypeAttributes.NotPublic != 0) || (attr & TypeAttributes.NestedPrivate != 0) }
+      get { (attr & TypeAttributes.Public == 0)  }
+    }
+  }  // Atributes
   
+  /// <summary>
+  /// Top node of the tree representing a 'top' namespace, even if it is
+  /// empty (how's it called, by the way?)
+  /// </summary>
+  public class TopNode
+  {
+    // it is a list of elements
   internal mutable elements : list [ Node ] = [];
     
-  /// <summary>A reference on a html page</summary>
+    /// <summary>An anchor ref</summary>
   public href : string = this.ToString() + this.GetHashCode().ToString();
   
-  internal mutable current : Node;
+    internal mutable attribute : ReflAttribs;
+    internal mutable parent : TopNode;
   
+    // attributes dragged out from XML file  
   internal mutable comment : string = "";
   internal mutable remark : string = "";
   internal mutable return : string = "";
   internal mutable param : string = "";
-  internal mutable attr : Reflection.TypeAttributes;
-  internal mutable info : string;
-  internal parent : TopNode;
-  
+    internal mutable example : string = "";
+    internal mutable exception : string = "";
+    internal mutable permission : string = "";
   
   /// <summary>
-  /// Create html description (i.e. TOC) of the namespace
+    /// For the current node (which represent a namespace) creates a list of elements
   /// </summary>
-  internal namespace2html (elements : list [ Node ], ns : string) : string
+    internal namespace2html (elements : list [ Node ], ns : string, publicOnly : bool) : string
   {
     // def page_ref = "<a href=\"" + ns + "\">";
     mutable res = "";
     res += "<div class=\"ns-index\">\n";
-    res += "<span class=\"ns-index\" id=\"" + this.href + "\">Namespace " + (if (ns.Length == 0) "&lt;empty&gt;" else ns) +"</span>\n";
+      res += "<span class=\"ns-index\" id=\"" + this.href + "\">Namespace " + (if (ns.Length == 0) "&lt;top&gt;" else ns) +"</span>\n";
     foreach (e in elements)      
-      when (e.elemType.Equals(ElementType.Type()) || e.elemType.Equals(ElementType.Unknown()))
+        when (!publicOnly || (e.attribute == null  || !e.attribute.Private))
+          when (e.XMLattrib.Equals(ElementType.Type()) || e.XMLattrib.Equals(ElementType.Unknown()))
       {
-        def ahref = match (e.elemType) { | Unknown => "#" + e.href | _ => e.html_file + "#" + e.href };
+            def ahref = match (e.XMLattrib) { | Unknown => "#" + e.href | _ => e.html_file + "#" + e.href };
         res += "<div title=\"" + e.full_name + "\" class=\"index-element\">";
-        res += match (e.elemType) { | Type => "class" | Unknown => "namespace" | _ => e.elemType.ToString() };
+            res += match (e.XMLattrib) { | Type => "class" | Unknown => "namespace" | _ => e.XMLattrib.ToString() };
         res += " ";
         res += "<a href=\"" + ahref + "\">" + e.name + "</a>";
         res += if (comment.Length > 0) "<div class=\"komentarz\">Comment: " + comment + "</div>" else "";
@@ -104,62 +142,88 @@
   /// Creates Table of Content for the current namespace. The current node is
   /// always a namespace.
   /// </summary>
-  public virtual ToIndex (content : ref string) : void
+    public virtual ToIndex (content : ref string, publicOnly : bool) : void
   {
     // first group types in 'anonymous' namespace
     mutable is_anonymous_ns = false;
     foreach (e in elements)      
-      when (e.elemType.Equals(ElementType.Type())) is_anonymous_ns = true;
+        when (e.XMLattrib.Equals(ElementType.Type())) is_anonymous_ns = true;
     
     // add elements in anonymous
     when (is_anonymous_ns)
     {
-      content += namespace2html(this.elements, "");
+        content += namespace2html(this.elements, "", publicOnly);
       foreach (e in this.elements)
-          unless (e.elemType.Equals(ElementType.Unknown())) content += e.ToHtml()
+            unless (e.XMLattrib.Equals(ElementType.Unknown()))
+            when (!publicOnly || (e.attribute == null || !e.attribute.Private))
+              content += e.ToHtml()
     }
         
     foreach (e in elements)
-       when (e.elemType.Equals(ElementType.Unknown())) e.ToIndex(ref content)
+         when (e.XMLattrib.Equals(ElementType.Unknown()))
+             e.ToIndex(ref content, publicOnly)
   }
   
   /// <summary>
-  /// Creates description of the current node, i.e. of the current namespace
+    /// Creates description of the current node. Since it represents a namespace,
+    /// it iterates over namespace's elements.
   /// </summary>
-  public virtual infoPages () : void
+    public virtual infoPages (publicOnly : bool) : void
   {       
     foreach (e in elements)
-        when (e.elemType.Equals(ElementType.Unknown())) e.infoPages();    
+          when (e.XMLattrib.Equals(ElementType.Unknown())) e.infoPages(publicOnly);    
   }
   
   /// <summary>Add comment to the current element</summary>
   public Comment(str : string) : void { 
-    current.comment += str;
+      this.comment += str;
   }
   
   /// <summary>Add remark to the current element</summary>
   public Remark(str : string) : void { 
-    current.remark += str;
+      this.remark += str;
   }
   
   /// <summary>Add return info to the current element</summary>
   public Return(str : string) : void { 
-    current.return += str;
+      this.return += str;
   }
   
   /// <summary>Add param info to the current element</summary>
   public Param(str : string) : void { 
-    current.param += str;
+      this.param += str;
+    }   
+  
+    /// <summary>Add example to the current element</summary>
+    public Example(str : string) : void { 
+      this.example += str;
   }   
   
-}
+    /// <summary>Add exception description to the current element</summary>
+    public Exception(str : string) : void { 
+      this.exception += str;
+    }   
 
+    /// <summary>Add permission description to the current element</summary>
+    public Permission(str : string) : void { 
+      this.permission += str;
+    }   
+    
+  } // class TopNode
+
+  
+  /// <summary>
+  /// Represents a 'concrete' (i.e. classes, fields, methods etc.) elements.
+  /// </summary>
+  public class Node : TopNode
+  {
+    /// <summary>A type of of a node.
+    /// This field is set by XML analyzer</summary>
+    public mutable XMLattrib : ElementType = ElementType.Unknown();
 
-class Node : TopNode
-{
-  public mutable elemType : ElementType = ElementType.Unknown();
   /// <summary>Name of the element</summary>
   public mutable name : string;
+    
   /// <summary>Full name of the element (with namespaces path)</summary>
   public mutable full_name : string = "";
   
@@ -168,44 +232,50 @@
     get { if (parent is Node) (parent :> Node).full_name + ".html" else "index.html"}
   }
   
-  /// <summary>
-  /// If the current node is a namespace, it creates a table of content.
-  /// </summary>
-  public override ToIndex (content : ref string) : void
+    /// <summary>If the current node is a namespace, it creates a table of content.</summary>
+    public override ToIndex (content : ref string, publicOnly : bool) : void
   {
-    when (this.elemType.Equals(ElementType.Unknown()))
+      when (this.XMLattrib.Equals(ElementType.Unknown()))
     {
       // Console.WriteLine("Podstrona typu {0}, nazwa {1}", this.elemType, this.full_name);
       // self-explanation
-      content += namespace2html(this.elements, this.full_name);
+        content += namespace2html(this.elements, this.full_name, publicOnly);
     
       foreach (e in elements)
-        when (e.elemType.Equals(ElementType.Unknown())) e.ToIndex(ref content);
+          when (e.XMLattrib.Equals(ElementType.Unknown())) e.ToIndex(ref content, publicOnly : bool);
     }
   }
 
-  /// <summary>
-  /// Creates a html page for the current namespace
-  /// </summary>
-  public override infoPages () : void
+    /// <summary>Creates a html page for the current namespace</summary>
+    public override infoPages (publicOnly : bool) : void
   {    
     // Console.WriteLine("Zapis pliku {0}", this);
-    when (this.elemType.Equals(ElementType.Unknown()))
+      // crreates a html page for the current namespace
+      when (this.XMLattrib.Equals(ElementType.Unknown()))
     {
       def fname = this.full_name;
       mutable content = "";
       content += HtmlGenerator.Title("Nemerle Library", "Namespace " + fname);
-      foreach (e in elements)
+        foreach (e in elements) {
+          mutable priv = false;
+          when (e.attribute != null)
+              priv = e.attribute.Private;
+          // Console.WriteLine("--> Element={0}, publicOnly={1}, priv={2}, cond={3}", e.name, publicOnly, priv, !publicOnly || !priv);
+          when (!publicOnly || !priv)
         content += e.ToHtml();
+          }
       HtmlGenerator.Page ( fun () { content }, fname + ".html");
     }
    
+      // crreates a html page for each sub namespace
     foreach (e in elements)
-      when (e.elemType.Equals(ElementType.Unknown())) e.infoPages();    
+        when (e.XMLattrib.Equals(ElementType.Unknown()))
+          e.infoPages(publicOnly);
   }
   
 
-  public this(name : string, prefiks : string, parent : TopNode) {
+    public this(name : string, prefiks : string, parent : TopNode)
+    {
       this.name = name;
       this.full_name = prefiks;
       this.parent = parent;
@@ -221,62 +291,79 @@
     res;
   }
   
-  /// <summary>
-  /// Create html explanation for the current node.
-  /// </summary>
+    /// <summary>Create full html description of the current node.</summary>
   public ToHtml () : string
   {
     mutable res = "";
-    mutable com = if (comment.Length > 0) "<div class=\"komentarz\">" + comment + "</div>" else "";
-    com += if (remark.Length > 0) "<div class=\"uwaga\">Remark: " + remark + "</div>" else "";
-    com += if (return.Length > 0) "<div class=\"return\">Return: " + return + "</div>" else "";
-    com += if (param.Length > 0) "<div class=\"param\">Parameter: " + param + "</div>" else "";
-    
+      mutable com = if (comment.Length > 0) "<div class=\"komentarz\">" + comment + "</div>\n" else "";
+      com += if (remark.Length > 0) "<div class=\"uwaga\">Remark: " + remark + "</div>\n" else "";
+      com += if (return.Length > 0) "<div class=\"return\">Return: " + return + "</div>\n" else "";
+      com += if (param.Length > 0) "<div class=\"param\">Parameter: " + param + "</div>\n" else "";
+      com += if (example.Length > 0) "<div class=\"example\">Example:<br />" + example + "</div>\n" else "";
+      com += if (exception.Length > 0) "<div class=\"exception\">Exception:<br />" + exception + "</div>\n" else "";
+      com += if (permission.Length > 0) "<div class=\"permission\">Permission:<br />" + permission + "</div>\n" else "";
     
     mutable att = "";
-    unless (this.attr.Equals(null))
-        att += " " + this.attr.ToString() + " ";
+      when (attribute != null) {
+        when ( (attribute.attr & TypeAttributes.Public) != 0) att += " public ";
+        when ( (attribute.attr & TypeAttributes.NotPublic) != 0) att += " notpublic ";
+        when ( (attribute.attr & TypeAttributes.NestedPublic) != 0) att += " nested public class ";
+        when ( (attribute.attr & TypeAttributes.Sealed) != 0) att += " sealed ";
+        // when ( attribute.Private) att += " PRIVATE ";
+        when (attribute.is_abstract) att += " abstract ";
+        when (attribute.is_class) att += " class ";
+        when (attribute.is_array) att += " array ";
+        when (attribute.is_interface) att += " interface ";
+        // last chance
+        when (att.Length == 0) att = attribute.attr.ToString();
+      }
     
-    match (elemType) {
+      match (XMLattrib) {
       | Unknown => 
-          /**
-          res += att + "<span class=\"namespace\" title=\"" + this.full_name + "\">" + name + "</span>\n";
-          res += com;
-          res += filteredIter(elements, fun (e) { e.elemType.Equals(ElementType.Method()) }, fun (e) { e.ToHtml() });
-          res += filteredIter(elements, fun (e) { e.elemType.Equals(ElementType.Property()) }, fun (e) { e.ToHtml() });
-          res += filteredIter(elements, fun (e) { e.elemType.Equals(ElementType.Field()) }, fun (e) { e.ToHtml() });
-          res += filteredIter(elements, fun (e) { e.elemType.Equals(ElementType.Type()) }, fun (e) { e.ToHtml() });
-          // foreach (e in elements) when (!e.elemType.Equals(ElementType.Unknown())) res += e.ToHtml();
-          **/
-          res = "";
-      | Property => res += "Property: " + att + name + com;
-      | Method => res += "<span title=\"" + this.full_name + "\">Method: " + att + name + com + "</span>";
-      | Field => res += "Field: " + att + name + com;
+            res += "<div>Unknown element " + this.full_name + "</div>";
+        | Property => res += "<span title=\"" + this.full_name + "\">" + att + name + "</span>" + com;
+        | Method => res += "<span title=\"" + this.full_name + "\">" + att + name + "</span>" + com;
+        | Field => res += att + name + com;
       | Type =>
-          res += "<div class=\"ns-index\"" + ("id=\"" + this.href + "\"") + ">Class " + att;
+            res += "<div class=\"ns-index\"" + ("id=\"" + this.href + "\"") + ">" + att;
           res += "<span class=\"ns-index\" title=\"" + this.full_name + "\">" + name + "</span>\n";
           res += com;
-          mutable components = "";
-          components += filteredIter(elements, fun (e) { e.elemType.Equals(ElementType.Method()) },   fun (e) { "<li>" + e.ToHtml() + "</li>\n"});
-          components += filteredIter(elements, fun (e) { e.elemType.Equals(ElementType.Property()) }, fun (e) { "<li>" + e.ToHtml() + "</li>\n"});
-          components += filteredIter(elements, fun (e) { e.elemType.Equals(ElementType.Field()) },    fun (e) { "<li>" + e.ToHtml() + "</li>\n"});
-          components += filteredIter(elements, fun (e) { e.elemType.Equals(ElementType.Type()) },     fun (e) { "<li>" + e.ToHtml() + "</li>\n"});
-          when (components.Length > 0)
-            res += "<ul>\n" + components + "</ul>\n";
+          
+            def methods = filteredIter(elements, fun (e) { e.XMLattrib.Equals(ElementType.Method()) },   fun (e) { "<div class=\"element\">" + e.ToHtml() + "</div>\n"});
+            when (methods.Length > 0) res += "<div class=\"elements-group\"><span class=\"elements-group\">Methods:</span>" + methods + "</div>";
+          
+            def props = filteredIter(elements, fun (e) { e.XMLattrib.Equals(ElementType.Property()) }, fun (e) { "<div class=\"element\">" + e.ToHtml() + "</div>\n"});
+            when (props.Length > 0) res += "<div class=\"elements-group\"><span class=\"elements-group\">Properties:</span>" + props + "</div>";
+          
+            def fields = filteredIter(elements, fun (e) { e.XMLattrib.Equals(ElementType.Field()) },    fun (e) { "<div class=\"element\">" + e.ToHtml() + "</div>\n"});
+            when (fields.Length > 0) res += "<div class=\"elements-group\"><span class=\"elements-group\">Fields:</span>" + fields + "</div>";
+          
+            def types = filteredIter(elements, fun (e) { e.XMLattrib.Equals(ElementType.Type()) },     fun (e) { "<div class=\"element\">" + e.ToHtml() + "</div>\n"});
+            when (types.Length > 0) res += "<div class=\"elements-group\"><span class=\"elements-group\">Types:</span>" + types + "</div>";
+          
           res += "</div>\n";
     }
     res  
-  }
-}
+    } // method ToHtml
+  } // class Node
 
-// -----------------------------------------------
-class DataTree
-{
+  /// <summary>
+  /// The class DataTree is a front-end for other modules which analyse input files.
+  /// </summary>
+  class DataTree
+  {
   split (str : string) : char*string { (str[0], str.Substring(2)) }
   
+    // top node of the tree
   mutable tree : TopNode = TopNode();
+    
+    // recently added or processed node.
+    mutable currentNode : Node;
+    
+    // list of the sources
   mutable sources : list [ string ] = [];
   
+    ///<summary>Creates a string (html) representation of the sources of the program</summary>
   public sourcesToString () : string
   {
     mutable res = "";
@@ -286,12 +373,16 @@
               | 1 => "Source: "
               | _ => "Sources:<br /> "
         }
+      when (sources.Length > 0)
+      {
     res += List.Head(sources);
     def r = List.Tail(sources);
     foreach (e in r) res += ", " + e;
+      }
     res
   }
   
+    /// <summary> Adds info about a file name being the current input</summary>
   public AddSource(src : string) : void
   {
     sources += [ src ]
@@ -317,14 +408,14 @@
     
     // Console.WriteLine("{0} = ({1},{2})", path, path_name, param);
     
-    mutable token_list = Nemerle.Collections.List.FromArray(path_name.Split(array ['.']));
+      mutable token_list = Nemerle.Collections.List.FromArray(path_name.Split(array ['.', '+']));
     mutable res = [];
     // analyze name
     while (token_list.Length > 1)
     {
       mutable r = List.Hd(token_list);
       
-      /// when not .., i.e. ctor
+        // when not .., i.e. ctor
       when (r.Length != 0)
       {
         res += [ r ];
@@ -346,9 +437,9 @@
   }
   
   /// <summary>
-  /// Add a new element to the tree. Used by assembly analyzer.
+    /// Adds a new element (typically a class) to the tree. Used by assembly analyzer.
   /// </summary>
-  public AddItem(str : string, attr : System.Reflection.TypeAttributes, ty : ElementType) : void
+    public AddItem(str : string, ty : ElementType, attr : ReflAttribs) : void
   {
     def path = smart_strip2(str);
     // Console.WriteLine("Ścieżka {0}", str);
@@ -366,12 +457,12 @@
       }
       pointer = next;
     }
-    pointer.attr = attr; 
-    next.elemType = ty
-  }
+      pointer.attribute = attr;
+      next.XMLattrib = ty
+    } // AddItem
   
   /// <summary>
-  /// Add a new element to the tree. Used by XML analyzer.
+    /// Adds a new element (a member of a class) to the tree. Used by assembly analyzer.
   /// </summary>
   public AddItem(ns_path : string, typename : string, ty : ElementType) : void
   {
@@ -391,11 +482,12 @@
       }
       pointer = next;
     }
-    next.elemType = ty
+      next.XMLattrib = ty
   }
   
   /// <summary>
-  /// Add a new element to the tree. Used by assembly analyzer.
+    /// Add a new element to the tree. An argument is a string consisting of
+    /// a stringified declaration of an element. Used by the XML analyzer.
   /// </summary>
   public AddItem (str : string) : void
   {
@@ -412,6 +504,8 @@
       }
       
     def pathList = smart_strip1(path);
+      // Console.WriteLine("Path to strip: {0}", path);
+      // foreach (n in pathList) Console.WriteLine("--> {0}", n);
     mutable pointer = tree;
     mutable next;
     foreach (edge in pathList)
@@ -425,53 +519,68 @@
       }
       pointer = next;
     }
-    tree.current = next;
-    tree.current.elemType = ty;
+      currentNode = next;
+      currentNode.XMLattrib = ty;
     // Console.WriteLine("Added {0} {1}", tree.current.full_name, tree.current.elemType);
   }
     
   public AddComment (str : string) : void 
   {
-    tree.Comment(str);
+      currentNode.Comment(str);
   }
   
   public AddRemark (str : string) : void 
   {
-    tree.Remark(str);
+      currentNode.Remark(str);
   }
   
   public AddReturn (str : string) : void 
   {
-    tree.Return(str);
+      currentNode.Return(str);
   }
   
   public AddParam (str : string) : void 
   {
-    tree.Param(str);
+      currentNode.Param(str);
   }
   
   
-  index_content () : string
+    public AddExample (str : string) : void 
+    {
+      currentNode.Example(str);
+    }
+  
+    public AddException (str : string) : void 
+    {
+      currentNode.Exception(str);
+    }
+    
+    public AddPermission (str : string) : void 
+    {
+      currentNode.Permission(str);
+    }
+    
+    index_content (publicOnly : bool) : string
   {
     mutable content = "";
     content += HtmlGenerator.Title("Nemerle Library", this.sourcesToString());
     // teraz zawartość
     
-    tree.ToIndex(ref content);
+      tree.ToIndex(ref content, publicOnly);
     content;
   }
   
   
-  public indexPage() : void
+    public indexPage(publicOnly : bool) : void
   {
-    HtmlGenerator.Page(index_content, "index.html");
+      HtmlGenerator.Page(fun () { index_content(publicOnly) }, "index.html");
   }
   
-  public infoPages () : void
+    public infoPages (publicOnly : bool) : void
   {
-    tree.infoPages();
+      tree.infoPages(publicOnly);
   }
   
-}
+  } // class DataTree
 
-}
+} // namespace NemerleDoc

Modified: nemerle/trunk/tools/ndp/Makefile
==============================================================================
--- nemerle/trunk/tools/ndp/Makefile	(original)
+++ nemerle/trunk/tools/ndp/Makefile	Tue Dec 19 21:01:17 2006
@@ -8,7 +8,9 @@
 
 $(EXE): $(SOURCES) 
 	ncc -g -Ot -texe -doc:$(DOC) -out:$@ $^
-#	mono $(EXE) $(EXE) $(DOC)
+
+test:
+	mono --debug $(EXE) -np $(EXE) $(DOC)
 
 clean:
 	rm  $(CLEAN_FILES)

Modified: nemerle/trunk/tools/ndp/XMLMacro.n
==============================================================================
--- nemerle/trunk/tools/ndp/XMLMacro.n	(original)
+++ nemerle/trunk/tools/ndp/XMLMacro.n	Tue Dec 19 21:01:17 2006
@@ -1,189 +1,228 @@
-// xml
-// Top-down (LL) parser
-
-using System;
-using System.Collections;
-using System.Text;
-using System.Xml;
-// using System.Xml.XPath;
-using Nemerle.Assertions;
-
 namespace NemerleDoc
 {
 
-module XmlDocAnalyzer
-{
+    using System.Xml;
+    using System;
+    using Nemerle.Collections;
 
-  _info () : void
+    class SaxDefaultHandler
   {
-        Console.WriteLine("Typ:" + cursor.NodeType.ToString() + " nazwa: " + cursor.Name + 
-        " atrybut: " + (if (cursor.AttributeCount > 0) cursor[0] else "") +
-        " val: " + cursor.Value + " line:" + cursor.LineNumber.ToString())
-  }
+      mutable protected cursor : XmlTextReader;
 
-  /// <summary>hygienic tests</summary>
-  StartTag(name : string) : void
-  {
-    def error = String.Format("Open tag <{0}> expected, line: {1}", name, cursor.LineNumber);
-    assert(cursor.NodeType == XmlNodeType.Element && cursor.Name.Equals(name), error);  
-  }
+      /// <param name="field">Name of a field</param>
+      /// <returns>Returns the value of an attribute</returns>
+      internal attribute (field : string) : string { cursor[field] }
   
-  SkipStartTag(name : string) : void
+      private iterate () : void
   {
-    def error = String.Format("Open tag <{0}> expected, line: {1}", name, cursor.LineNumber);
-    assert(cursor.NodeType == XmlNodeType.Element && cursor.Name.Equals(name), error);  
-    _ = cursor.Read()
-  }
+          do
+          {
+              match (cursor.NodeType) {
   
-  SkipEndTag(name : string) : void
+                | Element => Element(cursor.Name)
+                | EndElement => EndElement(cursor.Name)
+                | Text => Text(cursor.Value)
+                | Document => Document()
+                | EntityReference => EntityReference(cursor.Name)
+                | XmlDeclaration => XmlDeclaration()
+                | None => ()
+                | _ => Console.WriteLine("Unsupported element {0}", cursor.NodeType)
+              
+              } // match
+          } while (cursor.Read()) // 
+      
+      } // iterate
+      
+      // -------- public interface -------------
+      
+      virtual public Element(_ : string) : void {}
+      virtual public EndElement(_ : string) : void {};
+      virtual public Text(_ : string) : void { };
+      virtual public Document () : void {}
+      virtual public EntityReference (_ : string) : void { }
+      virtual public XmlDeclaration () : void { }
+    
+      public this (filename : string)
   {
-    def error = String.Format("Closing tag </{0}> expected, line: {1}", name, cursor.LineNumber);
-    assert(cursor.NodeType == XmlNodeType.EndElement && cursor.Name.Equals(name), error);
-    _ = cursor.Read();
+          cursor = XmlTextReader(filename);
+          cursor.WhitespaceHandling = WhitespaceHandling.None;
+          iterate();
   }
   
-  readText () : string
-  {
-    mutable res = "";
-    when (cursor.NodeType == XmlNodeType.Text)
+    } // SaxDefaultHanler
+    
+    variant TagName
     {
-      res = cursor.Value;
-      _ = cursor.Read()
-    }
-    res
+      | Summary
+      | Remarks
+      | Returns
+      | Param
+      | Example
+      | Exception
+      | Permission
+      | Other
   }
   
-  isOpenTag(name : string) : bool
+    [Record]
+    sealed class Handler
   {
-    cursor.NodeType == XmlNodeType.Element && cursor.Name.Equals(name)
+      internal begin : void -> void;
+      internal end   : void -> void    
   }
   
-  isEndTag(name : string) : bool
+    /// <summary>
+    /// Processes xml file
+    /// </summary>
+    class MyXmlHandler : SaxDefaultHandler
   {
-    cursor.NodeType == XmlNodeType.EndElement && cursor.Name.Equals(name);
-  }
   
-  // ---------------------------
-  mutable cursor : XmlTextReader;
-  mutable tree : DataTree;
+      mutable buffer : string = "";
   
-  paramTag () : void
-  {
-    mutable res = "";
-    res = cursor[0];
-    SkipStartTag("param");
-    res += ": " + readText();
-    tree.AddParam(res);
-    SkipEndTag("param");  
-  }
+      tree : DataTree ;
+      mutable state : TagName = TagName.Other();
+      
+      mutable static handlers : Hashtable [ string, Handler] ;
     
   /// <summary>
-  /// Why summary is doubly quoted???? Why?
+      /// Summary <see cref="anything" />
   /// </summary>
-  summaryTag() : void
-  {
-    SkipStartTag("summary");
+      make_handler () : void {
+        handlers = Hashtable();
     
-    match ((cursor.NodeType, cursor.Name)) {
-      | (XmlNodeType.Element, "summary") =>
-          SkipStartTag("summary");
-          tree.AddComment(readText());
-          SkipEndTag("summary");
-          when (isOpenTag("param"))
-                    paramTag ();
-          when (isEndTag("summary")) SkipEndTag("summary");
-      | (XmlNodeType.Text, _ ) =>
-          tree.AddComment(readText());
-          while (!isEndTag("summary"))
-          {
-              when (isOpenTag("param"))
-                      paramTag();
-              when (isOpenTag("returns"))
-              {
-                SkipStartTag("returns");
-                tree.AddReturn(readText());
-                SkipEndTag("returns");
-              }
-          }
-          SkipEndTag("summary");
+        handlers["member"] = Handler(fun () : void {tree.AddItem(this.attribute("name"))}, fun () {} );
           
-          when (isOpenTag("remarks")) {
-            SkipStartTag("remarks");
-            tree.AddRemark(readText());
-            SkipEndTag("remarks");
-          }
-      | _ => throw Exception("Not implemented " + cursor.LineNumber.ToString());
-    }
-  }
+        handlers["summary"] = Handler( fun () { state = TagName.Summary() },
+                                       fun () {
+                                             when (buffer.Length > 0) this.tree.AddComment(buffer);
+                                             buffer = "";
+                                             state = TagName.Other()
   
+                                       });
   
+        handlers["remarks"] = Handler( fun () { state = TagName.Remarks() },
+                                        fun () {
+                                              when (buffer.Length > 0) this.tree.AddRemark(buffer);
+                                              buffer = "";
+                                              state = TagName.Other()
+                                        });
   
-  memberTag() : void
-  {
-    StartTag("member");
-    // Info();
-    tree.AddItem(cursor[0]);
-    if (cursor.IsEmptyElement)
-    {
-      _ = cursor.Read();
-    }
-    else {
-      _ = cursor.Read();
-      summaryTag();
-      SkipEndTag("member");
-    }
-  }
+        handlers["returns"] = Handler( fun () { state = TagName.Returns() },
+                                        fun () {
+                                              when (buffer.Length > 0) this.tree.AddReturn(buffer);
+                                              buffer = "";
+                                              state = TagName.Other()
+                                        });
   
-  membersTag() : void
-  {
-    SkipStartTag("members");
-    while (isOpenTag("member"))
-        memberTag();
-    SkipEndTag("members");
-  }
+        handlers["example"] = Handler( fun () { state = TagName.Example() },
+                                        fun () {
+                                              when (buffer.Length > 0) this.tree.AddExample(buffer);
+                                              buffer = "";
+                                              state = TagName.Other()
+                                        });
   
-  nameTag() : void
-  {
-    SkipStartTag("name");
-    _ = cursor.Read();
-    SkipEndTag("name")
+        handlers["param"] = Handler(fun () {state = TagName.Param(); buffer = this.attribute("name") + ": ";},
+                                fun () {
+                                      when (buffer.Length > 0) this.tree.AddParam(buffer);
+                                      buffer = "";
+                                      state = TagName.Other()
+                                });
+                                
+        handlers["exception"] = Handler(fun () { state = TagName.Exception(); buffer = this.attribute("cref") + ": ";},
+                                fun () {
+                                      when (buffer.Length > 0) this.tree.AddException(buffer);
+                                      buffer = "";
+                                      state = TagName.Other()
+                                });
+                                
+        handlers["permission"] = Handler(fun () { state = TagName.Permission(); buffer = this.attribute("cref") + ": ";},
+                                fun () {
+                                       when (buffer.Length > 0) this.tree.AddPermission(buffer);
+                                       buffer = "";
+                                       state = TagName.Other()
+                                });
+                                
+        // formatting tags                                
+        handlers["code"] = Handler(fun () { buffer += "<pre>" }, fun () { buffer += "</pre>"   });
+                                
+        handlers["c"] = Handler(fun () { buffer += "<tt>"  }, fun () { buffer += "</tt>" });
+                                 
+        handlers["para"] = Handler( fun () { buffer += "<p>" }, fun () { buffer = "</p>" } );
+        
+        handlers["paramref"] = Handler( fun () { buffer += "<span class=\"paramref\">" }, fun () { buffer = "</span>" } );
+        
+        handlers["see"] = Handler( fun () {
+                                      buffer += "<span class=\"see\">" + this.attribute("cref");
+                                      when (this.cursor.IsEmptyElement) buffer += "</span>";
+                                      }, 
+                                   fun () { buffer = "</span>" } );
+        
+        handlers["value"] = Handler( fun () { buffer += "<div class=\"value\">" }, fun () { buffer += "</div>" });
+        
+        // list and list family tags
+        handlers["list"] = Handler( fun () { buffer += "<ul>" }, fun () { buffer += "</ul" });
+        
+        handlers["listheader"] = Handler( fun () { buffer += "<div class=\"listheader\">" }, fun () { buffer += "</div>" });
+        
+        handlers["item"] = Handler( fun () { buffer += "<li>" }, fun () { buffer += "</li>" });
+        
+        handlers["term"] = Handler( fun () { buffer += "<span class=\"term\">" }, fun () { buffer += "</span>" });
+        
+        handlers["description"] = Handler( fun () { buffer += "<span class=\"description\">" }, fun () { buffer += "</span>" });
+        
+        
+        
+        // not processed tags 
+        handlers["doc"] = Handler(fun () {}, fun () { });
+        handlers["assembly"] = Handler(fun () {}, fun () { });
+        handlers["name"] = Handler(fun () {}, fun () { });
+        handlers["members"] = Handler(fun () {}, fun () { });
   }
   
-  assemblyTag() : void
+      public override Element ( tagName : string ) : void
   {
-    SkipStartTag("assembly");
-    nameTag();
-    SkipEndTag("assembly");
+          if (handlers.Contains(tagName)) handlers[tagName].begin();
+          else
+            Console.WriteLine("Tag {0} not supported", tagName);
   }
   
-  docTag() : void
+            
+      public override Text (text : string) : void
   {
-    SkipStartTag("doc");
+        match (state) {
     
-    assemblyTag();
-    // Info();
-    membersTag();
-    // Info();
+          | Summary
+          | Remarks
+          | Returns
+          | Example
+          | Exception
+          | Permission
+          | Param   => buffer += text
+          | Other => ()
+        }
+      }
     
-    SkipEndTag("doc")
+      public override EntityReference (text : string) : void
+      {
+          Console.WriteLine("Entity");
+          Console.WriteLine(text);
+          buffer += text;
   }
   
-  rootTag() : void
+      public override EndElement (tagName : string ) : void 
   {
-    assert(cursor.NodeType == XmlNodeType.XmlDeclaration, "Oczekiwano znacznik <?xml>");
-    when (cursor.Read())
-        docTag();
+          when (handlers.Contains(tagName))
+              handlers[tagName].end()
   }
 
-  public start(tr : DataTree, file : string) : void
+            
+      // public this(f : string) { base(f) }
+      public this(tree : DataTree, file : string)
   {
-    tree = tr;
-    cursor = XmlTextReader(file);
-    cursor.WhitespaceHandling = WhitespaceHandling.None;
-    _ = cursor.Read();
-    rootTag();
+        this.tree = tree;
+        make_handler();
+        base(file)
   }
 
+    } // MyHandler
 
-  } // -- NemerleDocXml
-}
+} // namespace NemerleDoc

Modified: nemerle/trunk/tools/ndp/nemerle-doc.css
==============================================================================
--- nemerle/trunk/tools/ndp/nemerle-doc.css	(original)
+++ nemerle/trunk/tools/ndp/nemerle-doc.css	Tue Dec 19 21:01:17 2006
@@ -1,6 +1,17 @@
+/* Marcin Młotkowski, November 2006
+   University of Wrocław, Institute of Computer Science
+   
+   CSS style for the Nemerle Documentation Project
+
+   This css is based on the css of the Nemerle web page (nemerle.org)
+   and slightly modified.
+
+ */
+
 html,body	{ color: darkblue; background: #E6ECFF;
 		  font-family: helvetica, arial, sans-serif }
 
+/** Format of the header of each page **/
 
 div.title       {  border-bottom: 1px solid black;
                    background: rgb(153,212,239);
@@ -12,6 +23,19 @@
                   
 span.subtitle   { font-size: small; }
 
+/** Defines a footer **/
+
+div.footer       { 
+    background: #E6ECFF;
+    border: none;
+    margin: .6em 0 0.8em 0;
+    padding: .4em 0 .4em 0;
+    text-align: center;
+    font-size: 90%;
+    font-variant: small-caps;
+}
+
+/** Elements used in TOC and main blocks **/
 
 div.ns-index    { background-color: white;
                   color: black;
@@ -25,113 +49,78 @@
                   
 div.index-element { padding-left: 20px; margin-left: 20px; }
 
-div.footer       { 
-    background: #E6ECFF;
-    border: none;
-    margin: .6em 0 0.8em 0;
-    padding: .4em 0 .4em 0;
-    text-align: center;
-    font-size: 90%;
-    font-variant: small-caps;
-}            
 
-/* ------------ OLD ------------*/
+/** links style **/
 a		{ text-decoration: underline; }
 a:link		{ color: blue; }
 a:visited	{ color: darkblue; }
 a:active	{ color: red; }
 
-
-
-div.site	{ border-bottom: 1px solid black;
-		  background: #f0f0d0; padding-bottom: 5px;
-                  font-size:large; font-weight: bold }
-
-div.salve {
-   font-size: 200%;
-   text-align: center;
-   color: rgb(204,149,97);
-   margin-top: 1ex;
-   margin-bottom: 1ex;
+/** Grouping elements of class **/
+div.elements-group {
+      border: 1px solid grey;
+      padding-left: 5px;
+      margin: 2px;
 }
 
-/** nawigacja **/
-
-// div.navigator	{ position: fixed; float: left; margin-left: 50%; margin-top: 2ex; }
-div.navigator	{  }
-
-
-div.navigator p	{ border-left:    2px solid white;
-		  border-top:     2px solid white;
-		  border-right:   2px solid #806040;
-		  border-bottom:  2px solid #806040;
-		  padding-left:   2ex;
-		  padding-right:  2ex;
-		  padding-top:    0.5em;
-		  padding-bottom: 0.5em;
-		  margin-top:     0em;
-		  margin-bottom:  1em;
-		  background: white; color: black }
-
-div.navi span	{ display: block; text-align: center; font-weight: bold; margin-bottom: 1ex }
+span.elements-group {
+      font-weight: bold
+}
 
-div.navigator a	{ text-decoration: none; display: block;
-		  text-align: left; padding: 1px; 
-		  font-size: small; 
-		  border-bottom: 1px solid #806040; }
+div.element { padding-left: 20px; margin-left: 20px; padding-top: 5px; }
 
-div.navigator a:hover { color: black; background: grey }
 
+/** Elements like comments, remarks, parameters **/
+div.komentarz {
+      font-style: italic;
+      color:      green;
+}
 
+div.uwaga {
+      font-style: italic;
+      color:      pink;
+}
 
-/*** info ***/
+div.param {
+      font-style: italic;
+      color:      orange;
+}
 
-p.namespace,div.namespace {
-                  width:      90%;
-                  border-left:    2px solid white;
-		  border-top:     2px solid white;
-		  border-right:   2px solid #806040;
-		  border-bottom:  2px solid #806040;
-                  font-size:      small;
-                  float:          right;
-		  padding-left:   2ex;
-		  padding-right:  2ex;
-		  padding-top:    0.5em;
-		  padding-bottom: 0.5em;
-		  margin-top:     0em;
-		  margin-bottom:  1em;
-		  background: white; color: black;
+div.example {
+      font-style: italic;
+      color:      blue;
 }
 
-span.namespace {
-    font-size:  130%;
-    text-align: center;
-    background: white;
+div.exception {
+      font-style: italic;
     color:      red;
 }
 
+div.permission {
+      font-style: italic;
+      color:      magenta;
+}
 
-/*** klasa ***/
-div.klasa {
-      border: 1px solid grey;
+span.paramref {
+      color: brown
 }
 
-span.klasa {
-      color: magenta;
+span.see {
+      color: coral;
 }
 
-/** komnetarz **/
-div.komentarz {
-      font-style: italic;
-      color:      green;
+div.value {
+      color: cyan;
 }
 
-div.uwaga {
-      font-style: italic;
-      color:      pink;
+div.listheader {
+      color: darkgrey;
 }
 
-div.param {
-      font-style: italic;
-      color:      orange;
+span.term {
+      color: firebrick;
+}
+
+span.description {
+      color: khaki;
 }



More information about the svn mailing list