# HG changeset patch # User aziz # Date 1184433845 0 # Node ID d4292a5a7b8bd5b5fb25bf5b312bbbf56f83bd9a # Parent 35c93b776be08934c0afca0141f67329cb4f8872 - Implemented parseStaticIfStatement() and parseStaticAssertStatement(). - Fix: was calling wrong method in LabeledStatement parser. diff -r 35c93b776be0 -r d4292a5a7b8b trunk/src/Parser.d --- a/trunk/src/Parser.d Sat Jul 14 15:06:03 2007 +0000 +++ b/trunk/src/Parser.d Sat Jul 14 17:24:05 2007 +0000 @@ -135,7 +135,7 @@ default: goto case_AttributeSpecifier; } - break; + assert(0); case T.Import: decl = parseImportDeclaration(); break; @@ -1128,8 +1128,7 @@ string ident = token.identifier; nT(); // Skip Identifier nT(); // Skip : - s = parseStatements(); - s = new LabeledStatement(ident, s); + s = new LabeledStatement(ident, parseNoScopeStatement()); break; } goto case_Declaration; @@ -1200,6 +1199,21 @@ case T.Mixin: s = new MixinStatement(parseMixinDeclaration()); break; + case T.Static: + Token next; + lx.peek(next); + switch (next.type) + { + case T.If: + s = parseStaticIfStatement(); + break; + case T.Assert: + s = parseStaticAssertStatement(); + break; + default: + goto case_Declaration; + } + assert(0); default: // TODO: issue error msg and return IllegalStatement. } @@ -1630,6 +1644,46 @@ return new PragmaStatement(ident, args, pragmaBody); } + Statement parseStaticIfStatement() + { + assert(token.type == T.Static); + nT(); + assert(token.type == T.If); + nT(); + Expression condition; + Statement ifBody, elseBody; + + require(T.LParen); + condition = parseExpression(); + require(T.RParen); + ifBody = parseNoScopeStatement(); + if (token.type == T.Else) + { + nT(); + elseBody = parseNoScopeStatement(); + } + return new StaticIfStatement(condition, ifBody, elseBody); + } + + Statement parseStaticAssertStatement() + { + assert(token.type == T.Static); + nT(); + assert(token.type == T.Assert); + nT(); + Expression condition, message; + require(T.LParen); + condition = parseAssignExpression(); + if (token.type == T.Comma) + { + nT(); + message = parseAssignExpression(); + } + require(T.RParen); + require(T.Semicolon); + return new StaticAssertStatement(condition, message); + } + /+++++++++++++++++++++++++++++ + Assembler parsing methods + +++++++++++++++++++++++++++++/ diff -r 35c93b776be0 -r d4292a5a7b8b trunk/src/Statements.d --- a/trunk/src/Statements.d Sat Jul 14 15:06:03 2007 +0000 +++ b/trunk/src/Statements.d Sat Jul 14 17:24:05 2007 +0000 @@ -308,3 +308,25 @@ this.decl = decl; } } + +class StaticIfStatement : Statement +{ + Expression condition; + Statement ifBody, elseBody; + this(Expression condition, Statement ifBody, Statement elseBody) + { + this.condition = condition; + this.ifBody = ifBody; + this.elseBody = elseBody; + } +} + +class StaticAssertStatement : Statement +{ + Expression condition, message; + this(Expression condition, Expression message) + { + this.condition = condition; + this.message = message; + } +} \ No newline at end of file