changeset 112:004d98df65af

- Implemented parseInterfaceDeclaration(). - Compiled with warnings and fixed them.
author aziz
date Sun, 08 Jul 2007 20:34:05 +0000
parents ab1135da30c3
children 20d8ae8a3fd9
files trunk/src/Declarations.d trunk/src/Lexer.d trunk/src/Parser.d trunk/src/main.d
diffstat 4 files changed, 67 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/Declarations.d	Sun Jul 08 19:37:03 2007 +0000
+++ b/trunk/src/Declarations.d	Sun Jul 08 20:34:05 2007 +0000
@@ -57,13 +57,26 @@
 
 class ClassDeclaration : Declaration
 {
-  string className;
+  string name;
   BaseClass[] bases;
   Declaration[] decls;
-  this(string className, BaseClass[] bases, Declaration[] decls)
+  this(string name, BaseClass[] bases, Declaration[] decls)
   {
-    this.className = className;
+    this.name = name;
     this.bases = bases;
     this.decls = decls;
   }
 }
+
+class InterfaceDeclaration : Declaration
+{
+  string name;
+  BaseClass[] bases;
+  Declaration[] decls;
+  this(string name, BaseClass[] bases, Declaration[] decls)
+  {
+    this.name = name;
+    this.bases = bases;
+    this.decls = decls;
+  }
+}
--- a/trunk/src/Lexer.d	Sun Jul 08 19:37:03 2007 +0000
+++ b/trunk/src/Lexer.d	Sun Jul 08 20:34:05 2007 +0000
@@ -653,6 +653,7 @@
     default:
       return 0;
     }
+    assert(0);
   }
 
   void scanRawStringLiteral(ref Token t)
@@ -756,7 +757,7 @@
             buffer ~= h;
           }
           else
-            h = c;
+            h = cast(ubyte)c;
           ++n;
           continue;
         }
--- a/trunk/src/Parser.d	Sun Jul 08 19:37:03 2007 +0000
+++ b/trunk/src/Parser.d	Sun Jul 08 20:34:05 2007 +0000
@@ -12,7 +12,6 @@
 import Expressions;
 import Types;
 
-
 class Parameter
 {
   StorageClass stc;
@@ -163,6 +162,9 @@
     case T.Class:
       decl = parseClassDeclaration();
       break;
+    case T.Interface:
+      decl = parseInterfaceDeclaration();
+      break;
     case T.Module:
       // Error: module is optional and can only appear once at the top of the source file.
       break;
@@ -324,6 +326,7 @@
       LisIdentifier:
         ident = token.identifier;
         nT();
+        // TODO: handle template instantiations: class Foo : Bar!(int)
       }
       bases ~= new BaseClass(prot, ident);
       if (token.type != T.Comma)
@@ -332,6 +335,49 @@
     return bases;
   }
 
+  Declaration parseInterfaceDeclaration()
+  {
+    assert(token.type == T.Interface);
+
+    string name;
+    BaseClass[] bases;
+    Declaration[] decls;
+
+    nT();
+    if (token.type == T.Identifier)
+    {
+      name = token.identifier;
+      nT();
+    }
+    else
+      errorIfNot(T.Identifier);
+
+    if (token.type == T.LParen)
+    {
+      // TODO: parse template parameters
+    }
+
+    if (token.type == T.Colon)
+      bases = parseBaseClasses();
+
+    if (token.type == T.Semicolon)
+    {
+      //if (bases.length != 0)
+        // error: bases classes are not allowed in forward declarations.
+      nT();
+    }
+    else if (token.type == T.LBrace)
+    {
+      nT();
+      decls = parseDeclarationDefinitions();
+      require(T.RBrace);
+    }
+    else
+      errorIfNot(T.LBrace); // TODO: better error msg
+
+    return new InterfaceDeclaration(name, bases, decls);
+  }
+
   /+++++++++++++++++++++++++++++
   + Expression parsing methods +
   +++++++++++++++++++++++++++++/
--- a/trunk/src/main.d	Sun Jul 08 19:37:03 2007 +0000
+++ b/trunk/src/main.d	Sun Jul 08 20:34:05 2007 +0000
@@ -59,6 +59,8 @@
         case '/': c = "lc"; break;
         case '*': c = "bc"; break;
         case '+': c = "nc"; break;
+        default:
+          assert(0);
         }
         writef(`<c c="%s">%s</c>`, c, srcText);
       break;