changeset 130:0467f01ed524

- Fix: parameters can have optional identifier. - Added code for parsing delegates of type ( ArgumentList ) FunctionBody. - Added class FunctionType. - Added class FunctionLiteralExpression.
author aziz
date Tue, 10 Jul 2007 16:49:01 +0000
parents a9244d409652
children ce636f3981cc
files trunk/src/Expressions.d trunk/src/Parser.d trunk/src/Types.d
diffstat 3 files changed, 44 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/Expressions.d	Mon Jul 09 22:08:05 2007 +0000
+++ b/trunk/src/Expressions.d	Tue Jul 10 16:49:01 2007 +0000
@@ -5,6 +5,7 @@
 module Expressions;
 import Token;
 import Types;
+import Declarations;
 
 class Expression
 {
@@ -537,3 +538,14 @@
     this.specType = specType;
   }
 }
+
+class FunctionLiteralExpression : Expression
+{
+  FunctionType func;
+  Declaration[] decls;
+  this(FunctionType func, Declaration[] decls)
+  {
+    this.func = func;
+    this.decls = decls;
+  }
+}
--- a/trunk/src/Parser.d	Mon Jul 09 22:08:05 2007 +0000
+++ b/trunk/src/Parser.d	Tue Jul 10 16:49:01 2007 +0000
@@ -167,7 +167,7 @@
       decl = new EmptyDeclaration();
       break;
     case T.Module:
-      // Error: module is optional and can only appear once at the top of the source file.
+      // Error: module is optional and can appear only once at the top of the source file.
       break;
     default:
     }
@@ -1331,10 +1331,24 @@
       e = new IsExpression(type, ident, specType);
       break;
     case T.LParen:
-      // TODO: parse ( ArgumentList ) FunctionBody type delegates
-      nT();
-      e = parseExpression();
-      require(T.RParen);
+      Token t;
+      bool failed;
+      auto parameters = try_(parseParameters(), failed);
+      if (!failed)
+      {
+        // ( ArgumentList ) FunctionBody
+        require(T.LBrace);
+        auto decls = parseDeclarationDefinitions();
+        require(T.RBrace);
+        auto func = new FunctionType(null, parameters);
+        e = new FunctionLiteralExpression(func, decls);
+      }
+      else
+      {
+        nT();
+        e = parseExpression();
+        require(T.RParen);
+      }
       break;
     // BasicType . Identifier
     case T.Void,   T.Char,    T.Wchar,  T.Dchar, T.Bool,
@@ -1567,7 +1581,7 @@
         break;
       default:
         string ident;
-        auto type = parseDeclarator(ident);
+        auto type = parseDeclarator(ident, true);
 
         Expression assignExpr;
         if (token.type == T.Assign)
--- a/trunk/src/Types.d	Mon Jul 09 22:08:05 2007 +0000
+++ b/trunk/src/Types.d	Tue Jul 10 16:49:01 2007 +0000
@@ -167,3 +167,15 @@
     this.type = type;
   }
 }
+
+class FunctionType : Type
+{
+  Type returnType;
+  Parameters parameters;
+  this(Type returnType, Parameters parameters)
+  {
+    super(TOK.Invalid, null);
+    this.returnType = returnType;
+    this.parameters = parameters;
+  }
+}