]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
string-literals now do not treat digraphs as digraphs
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 1 Nov 2012 13:05:14 +0000 (14:05 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 1 Nov 2012 13:05:14 +0000 (14:05 +0100)
lexer.c
lexer.h
testsuite/ngraphs/expected
testsuite/ngraphs/main.qc

diff --git a/lexer.c b/lexer.c
index e08a5f6d93a8b60622d7543e073c7d37e2c421e8..634f90ca348da3584998bd94f3e83425820f61c9 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -259,7 +259,7 @@ static int lex_getch(lex_file *lex)
         lex->line++;
     else if (ch == '?')
         return lex_try_trigraph(lex, ch);
-    else if (ch == '<' || ch == ':' || ch == '%')
+    else if (!lex->flags.nodigraphs && (ch == '<' || ch == ':' || ch == '%'))
         return lex_try_digraph(lex, ch);
     return ch;
 }
@@ -998,6 +998,7 @@ int lex_do(lex_file *lex)
 
     if (ch == '"')
     {
+        lex->flags.nodigraphs = true;
         lex->tok.ttype = lex_finish_string(lex, '"');
         while (lex->tok.ttype == TOKEN_STRINGCONST)
         {
@@ -1010,6 +1011,7 @@ int lex_do(lex_file *lex)
 
             lex->tok.ttype = lex_finish_string(lex, '"');
         }
+        lex->flags.nodigraphs = false;
         if (!lex_endtoken(lex))
             return (lex->tok.ttype = TOKEN_FATAL);
         return lex->tok.ttype;
diff --git a/lexer.h b/lexer.h
index c2a9a4924d758691ea1fd58d80e52c10217ac9f4..8d525a5db5e54eb507ba35a6def53ff162f365ad 100644 (file)
--- a/lexer.h
+++ b/lexer.h
@@ -108,6 +108,7 @@ typedef struct {
 
        struct {
            bool noops;
+           bool nodigraphs; /* used when lexing string constants */
        } flags;
 
     int framevalue;
index 81a5e672c1df1730b4cad61dc5c12ff56e683c47..d51a1ba773c048ca90b261bc788b16ae8e8eee05 100644 (file)
@@ -1,2 +1,2 @@
-#^[]|{}~\
-#^[]|{}~\
+#^[]|{}~\%>
+#^[]|{}~\%>
index 91e4ab40928b14a9e5f8b571884bb27632eea7b8..ef2d38b36efd70358800f7aa4a074e6e1d8221b0 100644 (file)
@@ -1,6 +1,6 @@
 void(string, string) print = %:1;
 
 void() main = ??<
-       print("??=??'??(??)??!??<??>??-??/??/", "??/n");
-       print("#^[]|{}~\\", "\n");
+       print("??=??'??(??)??!??<??>??-??/??/%>", "??/n");
+       print("#^[]|{}~\\%>", "\n");
 %>;