changeset 181:abfd51142477

- Implemented parseScopeGuardStatement().
author aziz
date Sat, 14 Jul 2007 14:10:01 +0000
parents d5a67aa578a8
children 673b355ba0e9
files trunk/src/Parser.d trunk/src/Statements.d
diffstat 2 files changed, 41 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/Parser.d	Sat Jul 14 13:45:00 2007 +0000
+++ b/trunk/src/Parser.d	Sat Jul 14 14:10:01 2007 +0000
@@ -1181,6 +1181,13 @@
     case T.Throw:
       s = parseThrowStatement();
       break;
+    case T.Scope:
+      Token next;
+      lx.peek(next);
+      if (next.type != T.LParen)
+        goto case_Declaration;
+      s = parseScopeGuardStatement();
+      break;
     default:
       // TODO: issue error msg and return IllegalStatement.
     }
@@ -1545,6 +1552,33 @@
     return new ThrowStatement(expr);
   }
 
+  Statement parseScopeGuardStatement()
+  {
+    assert(token.type == T.Scope);
+    nT();
+    assert(token.type == T.LParen);
+    nT();
+
+    string condition = requireIdentifier();
+    if (condition.length)
+      switch (condition)
+      {
+      case "exit":
+      case "success":
+      case "failure":
+        break;
+      default:
+        // TODO: issue error msg.
+      }
+    require(T.RParen);
+    Statement scopeBody;
+    if (token.type == T.LBrace)
+      scopeBody = parseScopeStatement();
+    else
+      scopeBody = parseNoScopeStatement();
+    return new ScopeGuardStatement(condition, scopeBody);
+  }
+
   /+++++++++++++++++++++++++++++
   + Expression parsing methods +
   +++++++++++++++++++++++++++++/
--- a/trunk/src/Statements.d	Sat Jul 14 13:45:00 2007 +0000
+++ b/trunk/src/Statements.d	Sat Jul 14 14:10:01 2007 +0000
@@ -254,7 +254,13 @@
 
 class ScopeGuardStatement : Statement
 {
-
+  string condition;
+  Statement scopeBody;
+  this(string condition, Statement scopeBody)
+  {
+    this.condition = condition;
+    this.scopeBody = scopeBody;
+  }
 }
 
 class ThrowStatement : Statement