# HG changeset patch # User aziz # Date 1184086141 0 # Node ID 0467f01ed524c7969e81eecb6a6de494fafd54d5 # Parent a9244d40965285a0ffefd5f41630f52f2fc2a3a7 - Fix: parameters can have optional identifier. - Added code for parsing delegates of type ( ArgumentList ) FunctionBody. - Added class FunctionType. - Added class FunctionLiteralExpression. diff -r a9244d409652 -r 0467f01ed524 trunk/src/Expressions.d --- 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; + } +} diff -r a9244d409652 -r 0467f01ed524 trunk/src/Parser.d --- 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) diff -r a9244d409652 -r 0467f01ed524 trunk/src/Types.d --- 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; + } +}