]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
for the lexer 3 dots now become TOKEN_DOTS
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 23 Aug 2012 09:12:32 +0000 (11:12 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 23 Aug 2012 09:12:32 +0000 (11:12 +0200)
lexer.c
lexer.h

diff --git a/lexer.c b/lexer.c
index 841625577a96169452930eb72557525f4e7db793..2798737d200a7b130401ad43ff81804701a28f46 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -774,7 +774,6 @@ int lex_do(lex_file *lex)
             case '^':
             case '~':
             case ',':
-            case '.':
             case '!':
                 if (!lex_tokench(lex, ch) ||
                     !lex_endtoken(lex))
@@ -785,6 +784,37 @@ int lex_do(lex_file *lex)
             default:
                 break;
         }
+
+        if (ch == '.')
+        {
+            if (!lex_tokench(lex, ch))
+                return (lex->tok->ttype = TOKEN_FATAL);
+            /* peak ahead once */
+            nextch = lex_getch(lex);
+            if (nextch != '.') {
+                lex_ungetch(lex, nextch);
+                if (!lex_endtoken(lex))
+                    return (lex->tok->ttype = TOKEN_FATAL);
+                return (lex->tok->ttype = ch);
+            }
+            /* peak ahead again */
+            nextch = lex_getch(lex);
+            if (nextch != '.') {
+                lex_ungetch(lex, nextch);
+                lex_ungetch(lex, nextch);
+                if (!lex_endtoken(lex))
+                    return (lex->tok->ttype = TOKEN_FATAL);
+                return (lex->tok->ttype = ch);
+            }
+            /* fill the token to be "..." */
+            if (!lex_tokench(lex, ch) ||
+                !lex_tokench(lex, ch) ||
+                !lex_endtoken(lex))
+            {
+                return (lex->tok->ttype = TOKEN_FATAL);
+            }
+            return (lex->tok->ttype = TOKEN_DOTS);
+        }
     }
 
     if (ch == ',' || ch == '.') {
diff --git a/lexer.h b/lexer.h
index 6cdb5a58ec2474a44b1dff9ee917001ae4acd76e..a2f06acf7cb189ebff47fcdbb10bea2698583d31 100644 (file)
--- a/lexer.h
+++ b/lexer.h
@@ -45,6 +45,8 @@ enum {
 
     TOKEN_KEYWORD, /* loop */
 
+    TOKEN_DOTS, /* 3 dots, ... */
+
     TOKEN_STRINGCONST, /* not the typename but an actual "string" */
     TOKEN_CHARCONST,
     TOKEN_VECTORCONST,
@@ -66,6 +68,7 @@ static const char *_tokennames[] = {
     "TOKEN_TYPENAME",
     "TOKEN_OPERATOR",
     "TOKEN_KEYWORD",
+    "TOKEN_DOTS",
     "TOKEN_STRINGCONST",
     "TOKEN_CHARCONST",
     "TOKEN_VECTORCONST",