changeset 298:dc8bed242db5

- Fixed parsing ImportDeclaration.
author aziz
date Thu, 09 Aug 2007 19:49:03 +0000
parents b16dda92c3dd
children 559d5d62e0c1
files trunk/src/Parser.d
diffstat 1 files changed, 35 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/Parser.d	Thu Aug 09 16:41:00 2007 +0000
+++ b/trunk/src/Parser.d	Thu Aug 09 19:49:03 2007 +0000
@@ -290,7 +290,6 @@
       // TODO: Error: module is optional and can appear only once at the top of the source file.
       break;+/
     default:
-      // TODO: issue error msg.
       error(MID.ExpectedButFound, "Declaration", token.srcText);
       decl = new IllegalDeclaration(token);
       nT();
@@ -737,7 +736,6 @@
   {
     assert(token.type == T.Import || token.type == T.Static);
 
-    Declaration decl;
     bool isStatic;
 
     if (token.type == T.Static)
@@ -752,7 +750,7 @@
     Token*[] bindAliases;
 
     nT(); // Skip import keyword.
-    do
+    while (1)
     {
       ModuleName moduleName;
       Token* moduleAlias;
@@ -771,8 +769,7 @@
         moduleAlias = null;
       }
 
-
-      // parse Identifier(.Identifier)*
+      // Identifier(.Identifier)*
       while (token.type == T.Dot)
       {
         nT();
@@ -783,35 +780,44 @@
       moduleNames ~= moduleName;
       moduleAliases ~= moduleAlias;
 
-      // parse : BindAlias = BindName(, BindAlias = BindName)*;
-      //       : BindName(, BindName)*;
       if (token.type == T.Colon)
+        break;
+      if (token.type != T.Comma)
+        break;
+      nT();
+    }
+
+    if (token.type == T.Colon)
+    {
+      // BindAlias = BindName(, BindAlias = BindName)*;
+      // BindName(, BindName)*;
+      Token* bindName, bindAlias;
+      while (1)
       {
-        Token* bindName, bindAlias;
-        do
+        nT();
+        bindAlias = requireId();
+
+        if (token.type == T.Assign)
         {
           nT();
-          bindAlias = requireId();
-
-          if (token.type == T.Assign)
-          {
-            nT();
-            bindName = requireId();
-          }
-          else
-          {
-            bindName = bindAlias;
-            bindAlias = null;
-          }
-
-          // Push identifiers.
-          bindNames ~= bindName;
-          bindAliases ~= bindAlias;
-
-        } while (token.type == T.Comma)
-        break;
+          bindName = requireId();
+        }
+        else
+        {
+          bindName = bindAlias;
+          bindAlias = null;
+        }
+
+        // Push identifiers.
+        bindNames ~= bindName;
+        bindAliases ~= bindAlias;
+
+        if (token.type != T.Comma)
+          break;
+        nT();
       }
-    } while (token.type == T.Comma)
+    }
+
     require(T.Semicolon);
 
     return new ImportDeclaration(moduleNames, moduleAliases, bindNames, bindAliases);
@@ -989,8 +995,6 @@
     else
       expected(T.LBrace); // TODO: better error msg
 
-    // TODO: error if decls.length == 0
-
     return new InterfaceDeclaration(name, tparams, bases, decls, hasBody);
   }
 
@@ -1031,8 +1035,6 @@
     else
       expected(T.LBrace); // TODO: better error msg
 
-    // TODO: error if decls.length == 0
-
     if (tok == T.Struct)
       return new StructDeclaration(name, tparams, decls, hasBody);
     else