diff trunk/src/Parser.d @ 106:441962b0f526

- Added parseArrayType() method. - Added e2 member to ArrayType and two more constructors. - Corrected function header of try_().
author aziz
date Sun, 08 Jul 2007 13:33:02 +0000
parents df34ec47fb81
children 722c05bbd5eb
line wrap: on
line diff
--- a/trunk/src/Parser.d	Sun Jul 08 11:57:03 2007 +0000
+++ b/trunk/src/Parser.d	Sun Jul 08 13:33:02 2007 +0000
@@ -66,7 +66,7 @@
     nT();
   }
 
-  ReturnType try_(ReturnType)(lazy ReturnType parseMethod, out failed)
+  ReturnType try_(ReturnType)(lazy ReturnType parseMethod, out bool failed)
   {
     auto len = errors.length;
     auto lexerState = lx.getState();
@@ -881,18 +881,7 @@
         nT();
         break;
       case T.LBracket:
-        nT();
-        if (token.type == T.RBracket)
-        {
-          t = new ArrayType(t, null);
-          nT();
-        }
-        else
-        {
-          // TODO: try parsing as Type for assoc arrays and then as Expression.
-          t = new ArrayType(t, parseExpression());
-          require(T.RBracket);
-        }
+        t = parseArrayType(t);
         break;
       case T.Function, T.Delegate:
         TOK tok = token.type;
@@ -918,18 +907,7 @@
       switch (token.type)
       {
       case T.LBracket:
-        nT();
-        if (token.type == T.RBracket)
-        {
-          t = new ArrayType(t, null);
-          nT();
-        }
-        else
-        {
-          // TODO: try parsing as Type for assoc arrays and then as Expression.
-          t = new ArrayType(t, parseExpression());
-          require(T.RBracket);
-        }
+        t = parseArrayType(t);
         continue;
       case T.LParen:
         auto params = parseParameters();
@@ -944,6 +922,36 @@
     return t;
   }
 
+  Type parseArrayType(Type t)
+  {
+    assert(token.type == T.LBracket);
+    nT();
+    if (token.type == T.RBracket)
+    {
+      t = new ArrayType(t);
+      nT();
+    }
+    else
+    {
+      bool failed;
+      auto assocType = try_(parseType(), failed);
+      if (!failed)
+        t = new ArrayType(t, assocType);
+      else
+      {
+        Expression e = parseExpression(), e2;
+        if (token.type == T.Slice)
+        {
+          nT();
+          e2 = parseExpression();
+        }
+        t = new ArrayType(t, e, e2);
+      }
+      require(T.RBracket);
+    }
+    return t;
+  }
+
   Type parseDeclarator(ref string ident, bool identOptional = false)
   {
     auto t = parseType();