Mercurial > projects > dil
changeset 193:2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
author | aziz |
---|---|
date | Sun, 15 Jul 2007 18:19:01 +0000 |
parents | 5c898f80b436 |
children | b3604b237292 |
files | trunk/src/Expressions.d trunk/src/Parser.d |
diffstat | 2 files changed, 20 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- 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; } }
--- 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 {