]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - lexer.c
Implemented length operator. This closes #130
[xonotic/gmqcc.git] / lexer.c
diff --git a/lexer.c b/lexer.c
index d153459ebc8fe87318e05dcddbf35306b84edd97..1a8c17a1f3e414928737277fb7a5a59b76e1e8da 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
@@ -1233,12 +1233,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 +1301,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;