changeset 386:392a0068fc61

Refactored code related to scanning escape sequences. The backslash character is not skipped anymore before calling scanEscapeSequence(). Added an assert() to check for this. Added code that will pass the string of an undefined escape sequence to error().
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Tue, 11 Sep 2007 23:09:27 +0200
parents c45233dc63db
children ad0cbd1c8881
files trunk/src/dil/Lexer.d
diffstat 1 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/Lexer.d	Tue Sep 11 21:56:53 2007 +0200
+++ b/trunk/src/dil/Lexer.d	Tue Sep 11 23:09:27 2007 +0200
@@ -390,7 +390,6 @@
         char[] buffer;
         do
         {
-          ++p;
           c = scanEscapeSequence();
           if (c < 128)
             buffer ~= c;
@@ -673,7 +672,6 @@
         t.end = p;
         return;
       case '\\':
-        ++p;
         c = scanEscapeSequence();
         --p;
         if (c & 128)
@@ -722,8 +720,7 @@
     switch (*p)
     {
     case '\\':
-      ++p;
-      switch (*p)
+      switch (p[1])
       {
       case 'u':
         type = TOK.WCharLiteral; break;
@@ -1160,6 +1157,8 @@
 
   dchar scanEscapeSequence()
   {
+    assert(*p == '\\');
+    ++p;
     uint c = char2ev(*p);
     if (c)
     {
@@ -1234,7 +1233,7 @@
           if (*p == ';')
           {
             c = entity2Unicode(begin[0..p - begin]);
-            ++p;
+            ++p; // Skip ;
             if (c == 0xFFFF)
               error(MID.UndefinedHTMLEntity, (begin-1)[0..p-(begin-1)]);
           }
@@ -1245,7 +1244,20 @@
           error(MID.InvalidBeginHTMLEntity);
       }
       else
-        error(MID.UndefinedEscapeSequence);
+      {
+        // TODO: add parameter to localized strings
+        dchar d = *p;
+        char[] str = `\`;
+        if (d & 128)
+        {
+          d = decodeUTF8();
+          encodeUTF8(str, d);
+          ++p;
+        }
+        else
+          str ~= d;
+        error(MID.UndefinedEscapeSequence/+, str+/);
+      }
     }
 
     return c;