Bogus chars in the lexer now return a token that signifies this.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 12 Feb 2009 22:57:21 -0500
changeset 597 832dbfa63509
parent 596 8efa254e8840
child 598 decc32dc03a7
Bogus chars in the lexer now return a token that signifies this.
mojoshader_internal.h
mojoshader_lexer.re
mojoshader_preprocessor.c
--- a/mojoshader_internal.h	Thu Feb 12 22:55:05 2009 -0500
+++ b/mojoshader_internal.h	Thu Feb 12 22:57:21 2009 -0500
@@ -326,6 +326,7 @@
     TOKEN_PP_ENDIF,
     TOKEN_PP_ERROR,
     TOKEN_PP_INCOMPLETE_COMMENT,
+    TOKEN_PP_BAD_CHARS,
     TOKEN_EOI
 } Token;
 
--- a/mojoshader_lexer.re	Thu Feb 12 22:55:05 2009 -0500
+++ b/mojoshader_lexer.re	Thu Feb 12 22:57:21 2009 -0500
@@ -54,6 +54,7 @@
 
 /*!re2c
     ANY = [\000-\377];
+    ANYLEGAL = [a-zA-Z0-9_/'*=+%^&|!#<>()[{}.,~^:;? \t\v\f\r\n\-\]\\];
     O = [0-7];
     D = [0-9];
     L = [a-zA-Z_];
@@ -145,7 +146,7 @@
 
     WHITESPACE      { goto scanner_loop; }
     NEWLINE         { s->line++; RET('\n'); }
-    ANY             { printf("bad char\n"); goto scanner_loop; }
+    ANY             { goto bad_chars; }
 */
 
 multilinecomment:
@@ -177,17 +178,13 @@
     ANY             { goto singlelinecomment; }
 */
 
-// !!! FIXME
-/*
 bad_chars:
     if (YYLIMIT == YYCURSOR)
-        RET(TOKEN_BAD_TOKEN);
-*/
+        RET(TOKEN_PP_BAD_CHARS);
 
 /*!re2c
-    NEWLINE         { s->line++; goto scanner_loop; }
-    WHITESPACE      { goto scanner_loop; }
-    any             { goto singlelinecomment; }
+    ANYLEGAL        { cursor--; RET(TOKEN_PP_BAD_CHARS); }
+    ANY             { goto bad_chars; }
 */
 
     assert(0 && "Shouldn't hit this code");
--- a/mojoshader_preprocessor.c	Thu Feb 12 22:55:05 2009 -0500
+++ b/mojoshader_preprocessor.c	Thu Feb 12 22:57:21 2009 -0500
@@ -140,6 +140,7 @@
         TOKENCASE(TOKEN_PP_ENDIF);
         TOKENCASE(TOKEN_PP_ERROR);
         TOKENCASE(TOKEN_PP_INCOMPLETE_COMMENT);
+        TOKENCASE(TOKEN_PP_BAD_CHARS);
         TOKENCASE(TOKEN_EOI);
         #undef TOKENCASE