]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - lexer.c
Support text type escape sequences \b and \s.
[xonotic/gmqcc.git] / lexer.c
diff --git a/lexer.c b/lexer.c
index 068b4dc824bd5563d1c96722860c4e054b765d79..71373255e634f8357bf7a3340d05ad15c1c796b8 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012, 2013
+ * Copyright (C) 2012, 2013, 2014
  *     Wolfgang Bumiller
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -579,7 +579,7 @@ static int lex_skipwhite(lex_file *lex, bool hadwhite)
                         if (ch == '\n')
                             lex_tokench(lex, '\n');
                         else
-                            lex_tokench(lex, ' '); /* ch); */
+                            lex_tokench(lex, ' ');
                     }
                 }
                 ch = ' '; /* cause TRUE in the isspace check */
@@ -681,7 +681,7 @@ static bool lex_finish_frames(lex_file *lex)
 static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
 {
     utf8ch_t chr = 0;
-    int ch = 0;
+    int ch = 0, texttype = 0;
     int nextch;
     bool hex;
     bool oct;
@@ -716,13 +716,12 @@ static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
             case '\\': break;
             case '\'': break;
             case '"':  break;
-            case 'a':  ch = '\a'; break;
-            case 'b':  ch = '\b'; break;
-            case 'r':  ch = '\r'; break;
-            case 'n':  ch = '\n'; break;
-            case 't':  ch = '\t'; break;
-            case 'f':  ch = '\f'; break;
-            case 'v':  ch = '\v'; break;
+            case 'a': ch = '\a'; break;
+            case 'r': ch = '\r'; break;
+            case 'n': ch = '\n'; break;
+            case 't': ch = '\t'; break;
+            case 'f': ch = '\f'; break;
+            case 'v': ch = '\v'; break;
             case 'x':
             case 'X':
                 /* same procedure as in fteqcc */
@@ -825,7 +824,15 @@ static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
                 else
                     ch = chr;
                 break;
-            case '\n':  ch = '\n'; break;
+
+            /* high bit text */
+            case 'b': case 's':
+                texttype ^= 128;
+                continue;
+
+            case '\n':
+                ch = '\n';
+                break;
 
             default:
                 lexwarn(lex, WARN_UNKNOWN_CONTROL_SEQUENCE, "unrecognized control sequence: \\%c", ch);
@@ -833,7 +840,7 @@ static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
                 lex_tokench(lex, '\\');
             }
             /* add the character finally */
-            lex_tokench(lex, ch);
+            lex_tokench(lex, ch | texttype);
         }
         else
             lex_tokench(lex, ch);
@@ -1233,12 +1240,16 @@ int lex_do(lex_file *lex)
         ch == '~' || ch == '^'    /* ~=, ~, ^                        */
     )  {
         lex_tokench(lex, ch);
-
         nextch = lex_getch(lex);
-        if ((nextch == '=' && ch != '<') ||
-            (nextch == ch  && ch != '!') ||
-            (nextch == '<' && ch == '>')) {
+
+        if ((nextch == '=' && ch != '<') || (nextch == '<' && ch == '>'))
             lex_tokench(lex, nextch);
+        else if (nextch == ch && ch != '!') {
+            lex_tokench(lex, nextch);
+            if ((thirdch = lex_getch(lex)) == '=')
+                lex_tokench(lex, thirdch);
+            else
+                lex_ungetch(lex, thirdch);
         } else if (ch == '<' && nextch == '=') {
             lex_tokench(lex, nextch);
             if ((thirdch = lex_getch(lex)) == '>')
@@ -1297,6 +1308,28 @@ int lex_do(lex_file *lex)
         return (lex->tok.ttype = TOKEN_OPERATOR);
     }
 
+    /* length operator */
+    if (ch == 'l') {
+        if ((nextch = lex_getch(lex)) == 'e') {
+        if ((nextch = lex_getch(lex)) == 'n') {
+        if ((nextch = lex_getch(lex)) == 'g') {
+        if ((nextch = lex_getch(lex)) == 't') {
+        if ((nextch = lex_getch(lex)) == 'h') {
+            lex_tokench(lex, 'l');
+            lex_tokench(lex, 'e');
+            lex_tokench(lex, 'n');
+            lex_tokench(lex, 'g');
+            lex_tokench(lex, 't');
+            lex_tokench(lex, 'h');
+            lex_endtoken(lex);
+            return (lex->tok.ttype = TOKEN_OPERATOR);
+        } else lex_ungetch(lex, nextch);
+        } else lex_ungetch(lex, nextch);
+        } else lex_ungetch(lex, nextch);
+        } else lex_ungetch(lex, nextch);
+        } else lex_ungetch(lex, nextch);
+    }
+
     if (isident_start(ch))
     {
         const char *v;