changeset 803:cb8040538772

Reporting error for invalid octal escape sequences.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 07 Mar 2008 11:46:56 +0100
parents f51305056196
children 9e6c6bb73e5f
files trunk/src/dil/Messages.d trunk/src/dil/lexer/Lexer.d trunk/src/dil/parser/Parser.d
diffstat 3 files changed, 17 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/Messages.d	Wed Mar 05 15:45:54 2008 +0100
+++ b/trunk/src/dil/Messages.d	Fri Mar 07 11:46:56 2008 +0100
@@ -113,6 +113,8 @@
   // DDoc macros:
   auto UndefinedDDocMacro = "DDoc macro '{}' is undefined";
   auto UnterminatedDDocMacro = "DDoc macro '{}' has no closing ')'";
+  // Lexer messages:
+  auto InvalidOctalEscapeSequence = "value of octal escape sequence is greater than 0xFF: '{}'";
   // Parser messages:
   auto InvalidUTF8SequenceInString = "invalid UTF-8 sequence in string literal: '{0}'";
   auto ModuleDeclarationNotFirst = "a module declaration is only allowed as the first declaration in a file";
--- a/trunk/src/dil/lexer/Lexer.d	Wed Mar 05 15:45:54 2008 +0100
+++ b/trunk/src/dil/lexer/Lexer.d	Fri Mar 07 11:46:56 2008 +0100
@@ -1849,7 +1849,10 @@
         c *= 8;
         c += *p - '0';
         ++p;
-        return c & 0xFF; // Return valid escape value.
+        if (c > 0xFF)
+          error(sequenceStart, MSG.InvalidOctalEscapeSequence,
+                sequenceStart[0..p-sequenceStart]);
+        return c; // Return valid escape value.
       }
       else if(*p == '&')
       {
@@ -2475,15 +2478,21 @@
   }
 
   /// Forwards error parameters.
+  void error(char* columnPos, char[] msg, ...)
+  {
+    error_(this.lineNum, this.lineBegin, columnPos, msg, _arguments, _argptr);
+  }
+
+  /// ditto
   void error(char* columnPos, MID mid, ...)
   {
-    error_(this.lineNum, this.lineBegin, columnPos, mid, _arguments, _argptr);
+    error_(this.lineNum, this.lineBegin, columnPos, GetMsg(mid), _arguments, _argptr);
   }
 
   /// ditto
   void error(uint lineNum, char* lineBegin, char* columnPos, MID mid, ...)
   {
-    error_(lineNum, lineBegin, columnPos, mid, _arguments, _argptr);
+    error_(lineNum, lineBegin, columnPos, GetMsg(mid), _arguments, _argptr);
   }
 
   /// Creates an error report and appends it to a list.
@@ -2491,14 +2500,14 @@
   ///   lineNum = the line number.
   ///   lineBegin = points to the first character of the current line.
   ///   columnPos = points to the character where the error is located.
-  ///   mid = the message ID.
-  void error_(uint lineNum, char* lineBegin, char* columnPos, MID mid,
+  ///   msg = the message.
+  void error_(uint lineNum, char* lineBegin, char* columnPos, char[] msg,
               TypeInfo[] _arguments, Arg _argptr)
   {
     lineNum = this.errorLineNumber(lineNum);
     auto errorPath = this.filePaths.setPath;
     auto location = new Location(errorPath, lineNum, lineBegin, columnPos);
-    auto msg = Format(_arguments, _argptr, GetMsg(mid));
+    msg = Format(_arguments, _argptr, msg);
     auto error = new LexerError(location, msg);
     errors ~= error;
     if (infoMan !is null)
--- a/trunk/src/dil/parser/Parser.d	Wed Mar 05 15:45:54 2008 +0100
+++ b/trunk/src/dil/parser/Parser.d	Fri Mar 07 11:46:56 2008 +0100
@@ -3434,11 +3434,7 @@
     if (consumed(T.Dot))
       type = set(new ModuleScopeType(parseIdentifierType()), begin);
     else if (token.kind == T.Typeof)
-    {
       type = parseTypeofType();
-      if (token.kind != T.Dot)
-        return type;
-    }
     else
       type = parseIdentifierType();