]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
renaming the length operator to _length and fixing the lexing of that operator, gener...
authorWolfgang Bumiller <wry.git@bumiller.com>
Sat, 18 Oct 2014 11:47:23 +0000 (13:47 +0200)
committerWolfgang Bumiller <wry.git@bumiller.com>
Sat, 18 Oct 2014 11:47:23 +0000 (13:47 +0200)
lexer.c
lexer.h
tests/length.qc

diff --git a/lexer.c b/lexer.c
index 71373255e634f8357bf7a3340d05ad15c1c796b8..9ed9c39f25742afd29caff28e37578e3bfb6aebe 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -1308,28 +1308,6 @@ 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;
@@ -1361,6 +1339,8 @@ int lex_do(lex_file *lex)
         } else if (!strcmp(v, "vector")) {
             lex->tok.ttype = TOKEN_TYPENAME;
             lex->tok.constval.t = TYPE_VECTOR;
+        } else if (!strcmp(v, "_length")) {
+            lex->tok.ttype = TOKEN_OPERATOR;
         } else {
             size_t kw;
             for (kw = 0; kw < GMQCC_ARRAY_COUNT(keywords_qc); ++kw) {
diff --git a/lexer.h b/lexer.h
index c073c8e76ca9ec4629154434aa7bbc51cb80e01d..9187dee089bce496322363f13a4d395e5f00214d 100644 (file)
--- a/lexer.h
+++ b/lexer.h
@@ -176,8 +176,8 @@ typedef struct {
 #define opid3(a,b,c) (((uint8_t)a<<16)|((uint8_t)b<<8)|(uint8_t)c)
 
 static const oper_info c_operators[] = {
-    { "(",      0, opid1('('),         ASSOC_LEFT,  99, OP_PREFIX, false}, /* paren expression - non function call */
-    { "length", 1, opid3('l','e','n'), ASSOC_RIGHT, 98, OP_PREFIX, true},
+    { "(",       0, opid1('('),         ASSOC_LEFT,  99, OP_PREFIX, false}, /* paren expression - non function call */
+    { "_length", 1, opid3('l','e','n'), ASSOC_RIGHT, 98, OP_PREFIX, true},
 
     { "++",     1, opid3('S','+','+'), ASSOC_LEFT,  17, OP_SUFFIX, false},
     { "--",     1, opid3('S','-','-'), ASSOC_LEFT,  17, OP_SUFFIX, false},
index 5abe769cc5b18bedc6cf1d253a59152f75bea899..ba5f01d9bad79d51b6fc7348218ea39a4abd0190 100644 (file)
@@ -4,20 +4,20 @@ float c[5] = { 5, 4, 3, 2, 1 }; // 5
 const float d[] = { 1 };        // 1
 
 void main() {
-    print(ftos(length a), "\n"); // 11
-    print(ftos(length b), "\n"); // 3
-    print(ftos(length c), "\n"); // 5
-    print(ftos(length d), "\n"); // 1
+    print(ftos(_length a), "\n"); // 11
+    print(ftos(_length b), "\n"); // 3
+    print(ftos(_length c), "\n"); // 5
+    print(ftos(_length d), "\n"); // 1
 
-    static float al = length(a);
-    static float bl = length(b);
-    static float cl = length(c);
-    static float dl = length(d);
+    static float al = _length(a);
+    static float bl = _length(b);
+    static float cl = _length(c);
+    static float dl = _length(d);
 
     print(ftos(al), "\n"); // 11
     print(ftos(bl), "\n"); // 3
     print(ftos(cl), "\n"); // 5
     print(ftos(dl), "\n"); // 1
 
-    print(ftos(length "hello world"), "\n"); // 11
+    print(ftos(_length "hello world"), "\n"); // 11
 }