diff trunk/src/Parser.d @ 239:7911f6a92e6e

- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK. - Tokens are stored in a doubly linked list by the Lexer now. - Added method scanNext() which can be used by peek() and nextToken(). - Saving 'token' in Parser.try_().
author aziz
date Mon, 30 Jul 2007 12:36:04 +0000
parents f3c6c15961bb
children deab661906ae
line wrap: on
line diff
--- a/trunk/src/Parser.d	Sat Jul 28 22:59:03 2007 +0000
+++ b/trunk/src/Parser.d	Mon Jul 30 12:36:04 2007 +0000
@@ -25,7 +25,6 @@
   this(char[] srcText, string fileName)
   {
     lx = new Lexer(srcText, fileName);
-    token = &lx.token;
   }
 
   char* prev;
@@ -41,6 +40,7 @@
     do
     {
       lx.nextToken();
+      token = lx.token;
 if (!trying)
 {
 writef("\33[32m%s\33[0m", token.type);
@@ -68,14 +68,17 @@
 writef("\33[31mtry_\33[0m");
     ++trying;
 //     auto len = errors.length;
+    auto oldToken = token;
     auto oldCount = errorCount;
-    auto lexerState = lx.getState();
+//     auto lexerState = lx.getState();
     auto result = parseMethod();
     // If the length of the array changed we know an error occurred.
     if (errorCount != oldCount)
     {
-      lexerState.restore(); // Restore state of the Lexer object.
+//       lexerState.restore(); // Restore state of the Lexer object.
 //       errors = errors[0..len]; // Remove errors that were added when parseMethod() was called.
+      token = oldToken;
+      lx.token = oldToken;
       errorCount = oldCount;
       success = false;
     }
@@ -88,7 +91,7 @@
 
   TOK peekNext()
   {
-    Token next;
+    Token* next = token;
     lx.peek(next);
     return next.type;
   }
@@ -1447,6 +1450,7 @@
     switch (token.type)
     {
     case T.Align:
+      // TODO: don't call parseAttributeSpecifier().
       d = parseAttributeSpecifier();
       goto case_DeclarationStatement;
 /+ Not applicable for statements.
@@ -1757,6 +1761,8 @@
         nT();
         s = new AttributeStatement(token.type, parse());
         break;
+      // TODO: allow "scope class", "abstract scope class" in function bodies?
+      //case T.Class:
       default:
         s = new DeclarationStatement(parseDeclaration(stc));
       }
@@ -3086,7 +3092,7 @@
   {
     // We count nested parentheses tokens because template types may appear inside parameter lists; e.g. (int x, Foo!(int) y).
     assert(token.type == T.LParen);
-    Token next;
+    Token* next = token;
     uint level = 1;
     while (1)
     {