]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - lexer.c
Parsing a comma as an operator now - unless noop is true
[xonotic/gmqcc.git] / lexer.c
diff --git a/lexer.c b/lexer.c
index 867fb9430fe796ed227a59a13279415cd6d3fd63..3f1aa76c0f5c312273a1d17a8c33fe06996e8627 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -464,7 +464,7 @@ int lex_do(lex_file *lex)
                case '[':
                case ']':
 
-               case ',':
+               case '#':
 
                        return (lex->tok->ttype = ch);
                default:
@@ -489,12 +489,22 @@ int lex_do(lex_file *lex)
                        case '|':
                        case '^':
                        case '~':
+                       case ',':
                                return ch;
                        default:
                                break;
                }
        }
 
+       if (ch == ',') {
+           if (!lex_tokench(lex, ch) ||
+               !lex_endtoken(lex))
+           {
+               return (lex->tok->ttype = TOKEN_FATAL);
+           }
+           return (lex->tok->ttype = TOKEN_OPERATOR);
+       }
+
        if (ch == '+' || ch == '-' || /* ++, --, +=, -=  and -> as well! */
            ch == '>' || ch == '<' || /* <<, >>, <=, >= */
            ch == '=' ||              /* == */
@@ -559,22 +569,30 @@ int lex_do(lex_file *lex)
                lex->tok->ttype = TOKEN_IDENT;
 
                v = lex->tok->value;
-               if (!strcmp(v, "void") ||
-                   !strcmp(v, "int") ||
-                   !strcmp(v, "float") ||
-                   !strcmp(v, "vector") )
-               {
+               if (!strcmp(v, "void")) {
                        lex->tok->ttype = TOKEN_TYPENAME;
-                       switch (v[1]) {
-                               case 'o': lex->tok->constval.t = TYPE_VOID;    break;
-                               case 'n': lex->tok->constval.t = TYPE_INTEGER; break;
-                               case 'l': lex->tok->constval.t = TYPE_FLOAT;   break;
-                               case 'e': lex->tok->constval.t = TYPE_VECTOR;  break;
-                       }
-               }
-               else if (!strcmp(v, "for") ||
-                        !strcmp(v, "while") ||
-                        !strcmp(v, "do"))
+                   lex->tok->constval.t = TYPE_VOID;
+               } else if (!strcmp(v, "int")) {
+                       lex->tok->ttype = TOKEN_TYPENAME;
+                   lex->tok->constval.t = TYPE_INTEGER;
+               } else if (!strcmp(v, "float")) {
+                       lex->tok->ttype = TOKEN_TYPENAME;
+                   lex->tok->constval.t = TYPE_FLOAT;
+               } else if (!strcmp(v, "string")) {
+                       lex->tok->ttype = TOKEN_TYPENAME;
+                   lex->tok->constval.t = TYPE_STRING;
+               } else if (!strcmp(v, "entity")) {
+                       lex->tok->ttype = TOKEN_TYPENAME;
+                   lex->tok->constval.t = TYPE_ENTITY;
+               } else if (!strcmp(v, "vector")) {
+                       lex->tok->ttype = TOKEN_TYPENAME;
+                   lex->tok->constval.t = TYPE_VECTOR;
+               } else if (!strcmp(v, "for")  ||
+                        !strcmp(v, "while")  ||
+                        !strcmp(v, "do")     ||
+                        !strcmp(v, "var")    ||
+                        !strcmp(v, "return") ||
+                        !strcmp(v, "const"))
                        lex->tok->ttype = TOKEN_KEYWORD;
 
                return lex->tok->ttype;