diff trunk/src/Parser.d @ 179:507998c5c1ce

- Implemented parseTryStatement(). - Added classes CatchBody and FinallyBody.
author aziz
date Sat, 14 Jul 2007 13:41:01 +0000
parents 62718b29679e
children d5a67aa578a8
line wrap: on
line diff
--- a/trunk/src/Parser.d	Sat Jul 14 11:14:04 2007 +0000
+++ b/trunk/src/Parser.d	Sat Jul 14 13:41:01 2007 +0000
@@ -1175,6 +1175,9 @@
     case T.Synchronized:
       s = parseSynchronizedStatement();
       break;
+    case T.Try:
+      s = parseTryStatement();
+      break;
     default:
       // TODO: issue error msg and return IllegalStatement.
     }
@@ -1491,6 +1494,45 @@
     return new SynchronizedStatement(expr, parseScopeStatement());
   }
 
+  Statement parseTryStatement()
+  {
+    assert(token.type == T.Try);
+    nT();
+
+    auto tryBody = parseScopeStatement();
+    CatchBody[] catchBodies;
+    FinallyBody finBody;
+
+    while (token.type == T.Catch)
+    {
+      nT();
+      Parameter param;
+      if (token.type == T.LParen)
+      {
+        string ident;
+        auto type = parseDeclarator(ident);
+        param = new Parameter(StorageClass.None, type, ident, null);
+        require(T.RParen);
+      }
+      catchBodies ~= new CatchBody(param, parseNoScopeStatement());
+      if (param is null)
+        break; // This is a LastCatch
+    }
+
+    if (token.type == T.Finally)
+    {
+      nT();
+      finBody = new FinallyBody(parseNoScopeStatement());
+    }
+
+    if (catchBodies.length == 0 || finBody is null)
+    {
+      // TODO: issue error msg.
+    }
+
+    return new TryStatement(tryBody, catchBodies, finBody);
+  }
+
   /+++++++++++++++++++++++++++++
   + Expression parsing methods +
   +++++++++++++++++++++++++++++/