changeset 154:0e7cefb15e43

- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression(). - parseDotListExpression() parses NewExpression items as well. - Commented out code in parsePostExpression(). - Commented out code in parsePrimaryExpression() and replaced with a call to parseDotListExpression(). - Fix: parseArguments() was called with T.LParen instead of T.RParen. - Removed unused class DotExpression. - Added class DotListExpression.
author aziz
date Fri, 13 Jul 2007 09:43:00 +0000
parents 66790fc2c0a2
children cd4394ef4b59
files trunk/src/Expressions.d trunk/src/Parser.d trunk/src/Types.d
diffstat 3 files changed, 114 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/Expressions.d	Thu Jul 12 22:30:01 2007 +0000
+++ b/trunk/src/Expressions.d	Fri Jul 13 09:43:00 2007 +0000
@@ -290,12 +290,6 @@
   { super(e); }
 }
 
-class DotExpression : UnaryExpression
-{
-  this(Expression e)
-  { super(e); }
-}
-
 class DotIdExpression : UnaryExpression
 {
   string ident;
@@ -328,29 +322,29 @@
   }
 }
 
-class NewExpression : UnaryExpression
+class NewExpression : /*Unary*/Expression
 {
   Expression[] newArgs;
   Type type;
   Expression[] ctorArgs;
-  this(Expression e, Expression[] newArgs, Type type, Expression[] ctorArgs)
+  this(/*Expression e, */Expression[] newArgs, Type type, Expression[] ctorArgs)
   {
-    super(e);
+    /*super(e);*/
     this.newArgs = newArgs;
     this.type = type;
     this.ctorArgs = ctorArgs;
   }
 }
 
-class NewAnonClassExpression : UnaryExpression
+class NewAnonClassExpression : /*Unary*/Expression
 {
   Expression[] newArgs;
   BaseClass[] bases;
   Expression[] ctorArgs;
   Declaration[] decls;
-  this(Expression e, Expression[] newArgs, BaseClass[] bases, Expression[] ctorArgs, Declaration[] decls)
+  this(/*Expression e, */Expression[] newArgs, BaseClass[] bases, Expression[] ctorArgs, Declaration[] decls)
   {
-    super(e);
+    /*super(e);*/
     this.newArgs = newArgs;
     this.bases = bases;
     this.ctorArgs = ctorArgs;
@@ -410,7 +404,7 @@
     this.identifier = identifier;
   }
 }
-
+/*
 class IdentifierListExpression : Expression
 {
   Expression[] identList;
@@ -419,6 +413,15 @@
     this.identList = identList;
   }
 }
+*/
+class DotListExpression : Expression
+{
+  Expression[] identList;
+  this(Expression[] identList)
+  {
+    this.identList = identList;
+  }
+}
 
 class TemplateInstanceExpression : Expression
 {
--- a/trunk/src/Parser.d	Thu Jul 12 22:30:01 2007 +0000
+++ b/trunk/src/Parser.d	Fri Jul 13 09:43:00 2007 +0000
@@ -912,19 +912,23 @@
     return new DeleteDeclaration(parameters, decls);
   }
 
-  // IdentifierListExpression:
-  //         .IdentifierList
-  //         IdentifierList
-  //         Typeof
-  //         Typeof . IdentifierList
-  // IdentifierList:
-  //         Identifier
-  //         Identifier . IdentifierList
-  //         TemplateInstance
-  //         TemplateInstance . IdentifierList
-  // TemplateInstance:
-  //         Identifier !( TemplateArgumentList )
-  IdentifierListExpression parseIdentifierListExpression()
+  /+
+    DotListExpression:
+            . DotListItems
+            DotListItems
+            Typeof
+            Typeof . DotListItems
+    DotListItems:
+            DotListItem
+            DotListItem . DotListItems
+    DotListItem:
+            Identifier
+            TemplateInstance
+            NewExpression
+    TemplateInstance:
+            Identifier !( TemplateArgumentList )
+  +/
+  DotListExpression parseDotListExpression()
   {
     Expression[] identList;
     if (token.type == T.Dot)
@@ -939,7 +943,7 @@
       require(T.RParen);
       identList ~= new TypeofExpression(type);
       if (token.type != T.Dot)
-        return new IdentifierListExpression(identList);
+        goto Lreturn;
       nT();
     }
 
@@ -956,15 +960,37 @@
       else // Identifier
         identList ~= new IdentifierExpression(ident);
 
+    LnewExpressionLoop:
       if (token.type != T.Dot)
         break;
-      nT();
+      nT(); // Skip dot.
+
+      if (token.type == T.New)
+      {
+        identList ~= parseNewExpression();
+        goto LnewExpressionLoop;
+      }
     }
-
-    return new IdentifierListExpression(identList);
+  Lreturn:
+    return new DotListExpression(identList);
   }
 
-  IdentifierListType parseIdentifierListType()
+  /+
+    DotListType:
+            . TypeItems
+            TypeItems
+            Typeof
+            Typeof . TypeItems
+    TypeItems:
+            TypeItem
+            TypeItem . TypeItems
+    TypeItem:
+            Identifier
+            TemplateInstance
+    TemplateInstance:
+            Identifier !( TemplateArgumentList )
+  +/
+  DotListType parseDotListType()
   {
     Type[] identList;
     if (token.type == T.Dot)
@@ -978,16 +1004,17 @@
       identList ~= new TypeofType(parseExpression());
       require(T.RParen);
       if (token.type != T.Dot)
-        return new IdentifierListType(identList);
+        goto Lreturn;
       nT();
     }
 
     while (1)
     {
       string ident = requireIdentifier();
-      Token next;
-      lx.peek(next);
-      if (token.type == T.Not && next.type == T.LParen) // Identifier !( TemplateArguments )
+      // NB.: Currently Types can't be followed by "!=" so we don't need to peek for "(" when parsing TemplateInstances.
+      /+Token next;
+      lx.peek(next);+/
+      if (token.type == T.Not/+ && next.type == T.LParen+/) // Identifier !( TemplateArguments )
       {
         nT(); // Skip !.
         identList ~= new TemplateInstanceType(ident, parseTemplateArguments());
@@ -999,8 +1026,8 @@
         break;
       nT();
     }
-
-    return new IdentifierListType(identList);
+  Lreturn:
+    return new DotListType(identList);
   }
 
   /*
@@ -1323,7 +1350,7 @@
       nT(); e = new CompExpression(parseUnaryExpression());
       break;
     case T.New:
-      e = parseNewExpression(null);
+      e = parseNewExpression();
       break;
     case T.Delete:
       nT();
@@ -1357,6 +1384,8 @@
     {
       switch (token.type)
       {
+/*
+// Commented out because parseDotListExpression() handles this.
       case T.Dot:
         nT();
         if (token.type == T.Identifier)
@@ -1381,6 +1410,7 @@
         else
           expected(T.Identifier);
         continue;
+*/
       case T.PlusPlus:
         e = new PostIncrExpression(e);
         break;
@@ -1388,7 +1418,7 @@
         e = new PostDecrExpression(e);
         break;
       case T.LParen:
-        e = new CallExpression(e, parseArguments(T.LParen));
+        e = new CallExpression(e, parseArguments(T.RParen));
         continue;
       case T.LBracket:
         // parse Slice- and IndexExpression
@@ -1430,6 +1460,8 @@
     Expression e;
     switch (token.type)
     {
+/*
+// Commented out because parseDotListExpression() handles this.
     case T.Identifier:
       string ident = token.identifier;
       nT();
@@ -1447,6 +1479,10 @@
       nT();
       e = new IdentifierExpression(".");
       break;
+*/
+    case T.Identifier, T.Dot, T.Typeof:
+      e = parseDotListExpression();
+      break;
     case T.This:
       nT();
       e = new ThisExpression();
@@ -1605,6 +1641,8 @@
       require(T.RParen);
       e = new TypeidExpression(type);
       break;
+/*
+// Commented out because parseDotListExpression() handles this.
     case T.Typeof:
       requireNext(T.LParen);
       auto type = new TypeofType(parseExpression());
@@ -1618,6 +1656,7 @@
       else // typeof ( Expression )
         e = new TypeofExpression(type);
       break;
+*/
     case T.Is:
       requireNext(T.LParen);
 
@@ -1696,7 +1735,7 @@
     return e;
   }
 
-  Expression parseNewExpression(Expression e)
+  Expression parseNewExpression(/*Expression e*/)
   {
     assert(token.type == T.New);
     nT(); // Skip new keyword.
@@ -1720,7 +1759,7 @@
       require(T.LBrace);
       auto decls = parseDeclarationDefinitions();
       require(T.RBrace);
-      return new NewAnonClassExpression(e, newArguments, bases, ctorArguments, decls);
+      return new NewAnonClassExpression(/*e, */newArguments, bases, ctorArguments, decls);
     }
 
     // NewExpression:
@@ -1733,7 +1772,7 @@
     {
       ctorArguments = parseArguments(T.RParen);
     }
-    return new NewExpression(e, newArguments, type, ctorArguments);
+    return new NewExpression(/*e, */newArguments, type, ctorArguments);
   }
 
   Type parseType()
@@ -1782,7 +1821,7 @@
       goto Lident;
 +/
     case T.Identifier, T.Typeof, T.Dot:
-      t = parseIdentifierListType();
+      t = parseDotListType();
       break;
     default:
       // TODO: issue error msg.
--- a/trunk/src/Types.d	Thu Jul 12 22:30:01 2007 +0000
+++ b/trunk/src/Types.d	Fri Jul 13 09:43:00 2007 +0000
@@ -130,7 +130,7 @@
   Delegate,
   Pointer,
   Array,
-  IdentifierList,
+  DotList,
   Identifier,
   Typeof,
   TemplateInstance,
@@ -165,15 +165,17 @@
   }
 }
 
-class IdentifierListType : Type
+class DotListType : Type
 {
-  Type[] identList;
-  this(Type[] identList)
+  Type[] dotList;
+  this(Type[] dotList)
   {
-    super(TID.IdentifierList, null);
+    super(TID.DotList, null);
+    this.dotList = dotList;
   }
 }
 
+/+
 class IdentifierType : Type
 {
   string[] idents;
@@ -199,7 +201,18 @@
     this.idents ~= ident;
   }
 }
++/
 
+class IdentifierType : Type
+{
+  string ident;
+  this(string ident)
+  {
+    super(TID.Identifier, null);
+    this.ident = ident;
+  }
+}
+/+
 class TypeofType : IdentifierType
 {
   Expression e;
@@ -209,6 +222,17 @@
     this.e = e;
   }
 }
++/
+
+class TypeofType : Type
+{
+  Expression e;
+  this(Expression e)
+  {
+    super(TID.Typeof, null);
+    this.e = e;
+  }
+}
 
 class TemplateInstanceType : Type
 {