changeset 403:e7228859d865

Fixed the way newlines are handled after #! and #line tokens. Newlines after these two tokens must be scanned as whitespace by scan().
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sat, 22 Sep 2007 23:49:52 +0200
parents 22d65b2bef4f
children fe46b5ea7a18
files trunk/src/dil/Lexer.d
diffstat 1 files changed, 13 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/Lexer.d	Sat Sep 22 21:01:31 2007 +0200
+++ b/trunk/src/dil/Lexer.d	Sat Sep 22 23:49:52 2007 +0200
@@ -91,17 +91,13 @@
       t.start = p;
       t.type = TOK.Shebang;
       ++p;
+      assert(*p == '!');
       while (1)
       {
-        t.end = p;
-        switch (*++p)
+        t.end = ++p;
+        switch (*p)
         {
-        case '\r':
-          if (p[1] == '\n')
-            ++p;
-        case '\n':
-          ++p;
-          ++loc;
+        case '\n', '\r':
           break;
         case 0, _Z_:
           break;
@@ -116,6 +112,8 @@
         }
         break; // Exit loop.
       }
+      // Reset p. The newline will be scanned as whitespace in scan().
+      p = t.end;
       this.head.next = t;
       t.prev = this.head;
     }
@@ -1766,18 +1764,11 @@
     {
       switch (*++p)
       {
-      case '\r':
-        if (p[1] == '\n')
-          ++p;
-      case '\n', 0, _Z_:
+      case LS[0]:
+        if (!(p[1] == LS[1] && (p[2] == LS[2] || p[2] == PS[2])))
+          goto default;
+      case '\r', '\n', 0, _Z_:
         break Loop;
-      case LS[0]:
-        if (p[1] == LS[1] && (p[2] == LS[2] || p[2] == PS[2]))
-        {
-          ++p; ++p;
-          break Loop;
-        }
-        goto default;
       default:
         if (isspace(*p))
           continue;
@@ -1840,6 +1831,9 @@
         }
       }
     }
+    assert(*p == '\r' || *p == '\n' || *p == 0 || *p == _Z_ ||
+           *p == LS[0] && (p[1] == LS[1] && (p[2] == LS[2] || p[2] == PS[2]))
+    );
 
     if (state == State.Integer)
     {