# HG changeset patch # User aziz # Date 1184523541 0 # Node ID 2a2975b6d5396b7ffb09a172f7964d8ebd029cd2 # Parent 5c898f80b436eb8ed3129663a117fe07fb410539 - Using parseFunctionBody() when parsing FunctionLiteralExpression. diff -r 5c898f80b436 -r 2a2975b6d539 trunk/src/Expressions.d --- a/trunk/src/Expressions.d Sun Jul 15 18:04:03 2007 +0000 +++ b/trunk/src/Expressions.d Sun Jul 15 18:19:01 2007 +0000 @@ -6,6 +6,7 @@ import Token; import Types; import Declarations; +import Statements; class Expression { @@ -600,14 +601,14 @@ class FunctionLiteralExpression : Expression { - FunctionType func; - Declaration[] decls; + FunctionType funcType; + FunctionBody funcBody; TOK funcTok; - this(FunctionType func, Declaration[] decls, TOK funcTok = TOK.Invalid) + this(FunctionType funcType, FunctionBody funcBody, TOK funcTok = TOK.Invalid) { - this.func = func; - this.decls = decls; + this.funcType = funcType; + this.funcBody = funcBody; this.funcTok = funcTok; } } diff -r 5c898f80b436 -r 2a2975b6d539 trunk/src/Parser.d --- a/trunk/src/Parser.d Sun Jul 15 18:04:03 2007 +0000 +++ b/trunk/src/Parser.d Sun Jul 15 18:19:01 2007 +0000 @@ -257,8 +257,7 @@ { // It's a function declaration type = parseDeclaratorSuffix(type); - auto funcBody = new FunctionBody; - parseFunctionBody(funcBody); + auto funcBody = parseFunctionBody(new FunctionBody); return new FunctionDeclaration(ident, type, null, funcBody); } @@ -267,7 +266,7 @@ return null; } - void parseFunctionBody(FunctionBody func) + FunctionBody parseFunctionBody(FunctionBody func) { while (1) { @@ -309,6 +308,7 @@ } break; // exit while loop } + return func; } Declaration parseAttributeSpecifier() @@ -2431,15 +2431,13 @@ e = new AssocArrayLiteralExpression(keys, values); break; case T.LBrace: - // DelegateLiteral := { DeclDefs } - require(T.LBrace); - auto decls = parseDeclarationDefinitions(); - require(T.RBrace); - auto func = new FunctionType(null, Parameters.init); - e = new FunctionLiteralExpression(func, decls); + // DelegateLiteral := { Statements } + auto funcType = new FunctionType(null, Parameters.init); + auto funcBody = parseFunctionBody(new FunctionBody); + e = new FunctionLiteralExpression(funcType, funcBody); break; case T.Function, T.Delegate: - // FunctionLiteral := (function|delegate) Type? '(' ArgumentList ')' '{' DeclDefs '}' + // FunctionLiteral := (function|delegate) Type? '(' ArgumentList ')' '{' Statements '}' TOK funcTok = token.type; nT(); // Skip function|delegate token. Type returnType; @@ -2450,11 +2448,9 @@ returnType = parseType(); parameters = parseParameterList(); } - require(T.LBrace); - auto decls = parseDeclarationDefinitions(); - require(T.RBrace); - auto func = new FunctionType(returnType, parameters); - e = new FunctionLiteralExpression(func, decls, funcTok); + auto funcType = new FunctionType(returnType, parameters); + auto funcBody = parseFunctionBody(new FunctionBody); + e = new FunctionLiteralExpression(funcType, funcBody, funcTok); break; case T.Assert: Expression msg; @@ -2546,11 +2542,9 @@ if (!failed) { // ( ParameterList ) FunctionBody - require(T.LBrace); - auto decls = parseDeclarationDefinitions(); - require(T.RBrace); - auto func = new FunctionType(null, parameters); - e = new FunctionLiteralExpression(func, decls); + auto funcType = new FunctionType(null, parameters); + auto funcBody = parseFunctionBody(new FunctionBody); + e = new FunctionLiteralExpression(funcType, funcBody); } else {