changeset 150:753bc07bf3a0

- Forgot to pass ident to constructor of TemplateArgument. - Implemented parseMixinDeclaration(). - Forgot calling nT() before creating an AttributeDeclaration. - Removed GlobalIdExpression. Creating an IdentifierExpression with "." as ident instead. - Created TemplateArguments typedef for Object[].
author aziz
date Thu, 12 Jul 2007 18:06:02 +0000
parents 37e2e0d06013
children 2e959f67000b
files trunk/src/Declarations.d trunk/src/Expressions.d trunk/src/Parser.d trunk/src/Types.d
diffstat 4 files changed, 81 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/Declarations.d	Thu Jul 12 14:55:00 2007 +0000
+++ b/trunk/src/Declarations.d	Thu Jul 12 18:06:02 2007 +0000
@@ -348,3 +348,15 @@
     this.args = args;
   }
 }
+
+class MixinDeclaration : Declaration
+{
+  Expression[] templateIdent;
+  string mixinIdent;
+  this(Expression[] templateIdent, string mixinIdent)
+  {
+    super(false);
+    this.templateIdent = templateIdent;
+    this.mixinIdent = mixinIdent;
+  }
+}
--- a/trunk/src/Expressions.d	Thu Jul 12 14:55:00 2007 +0000
+++ b/trunk/src/Expressions.d	Thu Jul 12 18:06:02 2007 +0000
@@ -399,12 +399,14 @@
   }
 }
 
-class GlobalIdExpression : Expression
+class TemplateInstanceExpression : Expression
 {
-  string identifier;
-  this(string identifier)
+  string ident;
+  TemplateArguments targs;
+  this(string ident, TemplateArguments targs)
   {
-    this.identifier = identifier;
+    this.ident = ident;
+    this.targs = targs;
   }
 }
 
--- a/trunk/src/Parser.d	Thu Jul 12 14:55:00 2007 +0000
+++ b/trunk/src/Parser.d	Thu Jul 12 18:06:02 2007 +0000
@@ -179,16 +179,17 @@
       decl = parseDeleteDeclaration();
       break;
     case T.Mixin:
-      // TODO: parse TemplateMixin
+      decl = parseMixinDeclaration();
       break;
     case T.Semicolon:
       nT();
       decl = new EmptyDeclaration();
       break;
     case T.Module:
-      // Error: module is optional and can appear only once at the top of the source file.
+      // TODO: Error: module is optional and can appear only once at the top of the source file.
       break;
     default:
+      // TODO: issue error msg.
     }
     return decl;
   }
@@ -307,6 +308,7 @@
     case T.Const:
     case T.Auto:
     case T.Scope:
+      nT();
       decl = new AttributeDeclaration(token.type, parseDeclarationsBlock());
       break;
     default:
@@ -910,6 +912,55 @@
     return new DeleteDeclaration(parameters, decls);
   }
 
+  /*
+    TemplateMixin:
+            mixin TemplateIdentifier ;
+            mixin TemplateIdentifier MixinIdentifier ;
+            mixin TemplateIdentifier !( TemplateArgumentList ) ;
+            mixin TemplateIdentifier !( TemplateArgumentList ) MixinIdentifier ;
+  */
+  Declaration parseMixinDeclaration()
+  {
+    assert(token.type == T.Mixin);
+    nT(); // Skip mixin keyword.
+
+    Expression[] templateIdent;
+    string mixinIdent;
+
+    if (token.type == T.Dot)
+    {
+      nT();
+      templateIdent ~= new IdentifierExpression(".");
+    }
+
+    while (1)
+    {
+      string ident = requireIdentifier();
+      if (token.type == T.Not) // Identifier !( TemplateArguments )
+      {
+        // No need to peek for T.RParen. This must be a template instance.
+        nT();
+        templateIdent ~= new TemplateInstanceExpression(ident, parseTemplateArguments());
+      }
+      else // Identifier
+        templateIdent ~= new IdentifierExpression(ident);
+
+      if (token.type != T.Dot)
+        break;
+      nT();
+    }
+
+    if (token.type == T.Identifier)
+    {
+      mixinIdent = token.identifier;
+      nT();
+    }
+
+    require(T.Semicolon);
+
+    return new MixinDeclaration(templateIdent, mixinIdent);
+  }
+
   /+++++++++++++++++++++++++++++
   + Expression parsing methods +
   +++++++++++++++++++++++++++++/
@@ -1270,8 +1321,8 @@
       nT();
       break;
     case T.Dot:
-      requireNext(T.Identifier);
-      e = new GlobalIdExpression(token.identifier);
+      nT();
+      e = new IdentifierExpression(".");
       break;
     case T.This:
       nT();
@@ -1804,9 +1855,9 @@
     return params;
   }
 
-  Object[] parseTemplateArguments()
+  TemplateArguments parseTemplateArguments()
   {
-    Object[] args;
+    TemplateArguments args;
 
     require(T.LParen);
     if (token.type == T.RParen)
@@ -1939,7 +1990,7 @@
         }
       }
 
-      tparams ~= new TemplateParameter(tp, valueType, specType, defType, specValue, defValue);
+      tparams ~= new TemplateParameter(tp, valueType, ident, specType, defType, specValue, defValue);
 
       if (token.type != T.Comma)
         break;
--- a/trunk/src/Types.d	Thu Jul 12 14:55:00 2007 +0000
+++ b/trunk/src/Types.d	Thu Jul 12 18:06:02 2007 +0000
@@ -83,12 +83,14 @@
 {
   TP tp;
   Type valueType;
+  string ident;
   Type specType, defType;
   Expression specValue, defValue;
-  this(TP tp, Type valueType, Type specType, Type defType, Expression specValue, Expression defValue)
+  this(TP tp, Type valueType, string ident, Type specType, Type defType, Expression specValue, Expression defValue)
   {
     this.tp = tp;
     this.valueType = valueType;
+    this.ident = ident;
     this.specType = specType;
     this.defType = defType;
     this.specValue = specValue;
@@ -96,6 +98,8 @@
   }
 }
 
+typedef Object[] TemplateArguments;
+
 enum TID
 {
   Void    = TOK.Void,