diff trunk/src/Parser.d @ 186:d4292a5a7b8b

- Implemented parseStaticIfStatement() and parseStaticAssertStatement(). - Fix: was calling wrong method in LabeledStatement parser.
author aziz
date Sat, 14 Jul 2007 17:24:05 +0000
parents 35c93b776be0
children c977b8a78507
line wrap: on
line diff
--- 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  +
   +++++++++++++++++++++++++++++/