changeset 676:c4e3a34e40f1

Added new module dil.doc.Doc. Moved some doc related methods in dil.ast.Node to dil.doc.Doc.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 18 Jan 2008 19:28:37 +0100
parents e7811328e6c7
children 118971211c4c
files trunk/src/dil/ast/Node.d trunk/src/dil/doc/Doc.d trunk/src/main.d
diffstat 3 files changed, 72 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/ast/Node.d	Fri Jan 18 18:18:14 2008 +0100
+++ b/trunk/src/dil/ast/Node.d	Fri Jan 18 19:28:37 2008 +0100
@@ -76,67 +76,4 @@
   {
     return cast(Class)cast(void*)this;
   }
-
-  static bool isDoxygenComment(Token* token)
-  { // Doxygen: '/+!' '/*!' '//!'
-    return token.type == TOK.Comment && token.start[2] == '!';
-  }
-
-  static bool isDDocComment(Token* token)
-  { // DDOC: '/++' '/**' '///'
-    return token.type == TOK.Comment && token.start[1] == token.start[2];
-  }
-
-  /++
-    Returns the surrounding documentation comment tokens.
-    Note: this function works correctly only if
-          the source text is syntactically correct.
-  +/
-  Token*[] getDocComments(bool function(Token*) isDocComment = &isDDocComment)
-  {
-    Token*[] comments;
-    // Get preceding comments.
-    auto token = begin;
-    // Scan backwards until we hit another declaration.
-    while (1)
-    {
-      token = token.prev;
-      if (token.type == TOK.LBrace ||
-          token.type == TOK.RBrace ||
-          token.type == TOK.Semicolon ||
-          token.type == TOK.HEAD ||
-          (kind == NodeKind.EnumMember && token.type == TOK.Comma))
-        break;
-
-      if (token.type == TOK.Comment)
-      {
-        // Check that this comment doesn't belong to the previous declaration.
-        if (kind == NodeKind.EnumMember && token.type == TOK.Comma)
-          break;
-        switch (token.prev.type)
-        {
-        case TOK.Semicolon, TOK.RBrace:
-          break;
-        default:
-          if (isDocComment(token))
-            comments ~= token;
-        }
-      }
-    }
-    // Get single comment to the right.
-    token = end.next;
-    if (token.type == TOK.Comment && isDocComment(token))
-      comments ~= token;
-    else if (kind == NodeKind.EnumMember)
-    {
-      token = end.nextNWS;
-      if (token.type == TOK.Comma)
-      {
-        token = token.next;
-        if (token.type == TOK.Comment && isDocComment(token))
-          comments ~= token;
-      }
-    }
-    return comments;
-  }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trunk/src/dil/doc/Doc.d	Fri Jan 18 19:28:37 2008 +0100
@@ -0,0 +1,70 @@
+/++
+  Author: Aziz Köksal
+  License: GPL3
++/
+module dil.doc.Doc;
+
+import dil.ast.Node;
+
+bool isDoxygenComment(Token* token)
+{ // Doxygen: '/+!' '/*!' '//!'
+  return token.type == TOK.Comment && token.start[2] == '!';
+}
+
+bool isDDocComment(Token* token)
+{ // DDOC: '/++' '/**' '///'
+  return token.type == TOK.Comment && token.start[1] == token.start[2];
+}
+
+/++
+  Returns the surrounding documentation comment tokens.
+  Note: this function works correctly only if
+        the source text is syntactically correct.
++/
+Token*[] getDocComments(Node node, bool function(Token*) isDocComment = &isDDocComment)
+{
+  Token*[] comments;
+  // Get preceding comments.
+  auto token = node.begin;
+  // Scan backwards until we hit another declaration.
+  while (1)
+  {
+    token = token.prev;
+    if (token.type == TOK.LBrace ||
+        token.type == TOK.RBrace ||
+        token.type == TOK.Semicolon ||
+        token.type == TOK.HEAD ||
+        (node.kind == NodeKind.EnumMember && token.type == TOK.Comma))
+      break;
+
+    if (token.type == TOK.Comment)
+    {
+      // Check that this comment doesn't belong to the previous declaration.
+      if (node.kind == NodeKind.EnumMember && token.type == TOK.Comma)
+        break;
+      switch (token.prev.type)
+      {
+      case TOK.Semicolon, TOK.RBrace:
+        break;
+      default:
+        if (isDocComment(token))
+          comments ~= token;
+      }
+    }
+  }
+  // Get single comment to the right.
+  token = node.end.next;
+  if (token.type == TOK.Comment && isDocComment(token))
+    comments ~= token;
+  else if (node.kind == NodeKind.EnumMember)
+  {
+    token = node.end.nextNWS;
+    if (token.type == TOK.Comma)
+    {
+      token = token.next;
+      if (token.type == TOK.Comment && isDocComment(token))
+        comments ~= token;
+    }
+  }
+  return comments;
+}
--- a/trunk/src/main.d	Fri Jan 18 18:18:14 2008 +0100
+++ b/trunk/src/main.d	Fri Jan 18 19:28:37 2008 +0100
@@ -16,6 +16,7 @@
 import dil.semantic.Symbols;
 import dil.semantic.Pass1;
 import dil.translator.German;
+import dil.doc.Doc;
 import dil.Messages;
 import dil.Settings;
 import dil.SettingsLoader;
@@ -65,7 +66,7 @@
       {
         foreach (member; scopeSym.members)
         {
-          auto tokens = member.node.getDocComments();
+          auto tokens = getDocComments(member.node);
           char[] docText;
           foreach (token; tokens)
             docText ~= token.srcText;