]> git.corax.cc Git - ccc/commitdiff
lex: Parse "..." as separate token
authorMatthias Kruk <m@m10k.eu>
Sun, 12 Jul 2020 08:23:31 +0000 (17:23 +0900)
committerMatthias Kruk <m@m10k.eu>
Sun, 12 Jul 2020 08:23:31 +0000 (17:23 +0900)
src/lex.c
src/token.h

index 9d4738f2292fd7ccf87737685cbb9f5f312998ed..2d3a7a79ef31b9ada6aae8f0d1514718cb1f6bf2 100644 (file)
--- a/src/lex.c
+++ b/src/lex.c
 #define STATE_SUB         20
 #define STATE_MUL         21
 #define STATE_DOT         22
-#define STATE_ZERO        23
-#define STATE_NUM         24
-#define STATE_FLT         25
+#define STATE_DOTDOT      23
+#define STATE_ZERO        24
+#define STATE_NUM         25
+#define STATE_FLT         26
 
 #define identifier_firstchr(_c) ((_c) == '_' ||                        \
                                 (_c) >= 'a' && (_c) <= 'z' ||  \
@@ -558,19 +559,31 @@ struct token *_nexttoken(void)
                        }
 
                case STATE_DOT:
-                       _putnextchar(c);
-
                        if(c >= '0' && c <= '9') {
+                               _putnextchar(c);
+
                                tok = token_new_from_str(TOKEN_FLOAT_LITERAL, _line, _col, "0.");
                                assert(tok);
 
                                state = STATE_FLT;
+                       } else if(c == '.') {
+                               state = STATE_DOTDOT;
                        } else {
+                               _putnextchar(c);
+
                                return(token_new_from_str(TOKEN_MEMBER, _line, _col, "."));
                        }
 
                        break;
 
+               case STATE_DOTDOT:
+                       if(c == '.') {
+                               return(token_new_from_str(TOKEN_DOTS, _line, _col - 2, "..."));
+                       }
+
+                       fprintf(stderr, "Unexpected character `%c' at %d:%d\n", c, _line, _col);
+                       return(NULL);
+
                case STATE_ZERO:
                        if(c == 'x' || c == 'X') {
                                token_append_char(tok, 'x');
index 3b6d02c6c7e8fee935bbd9674bc78936ea5103b0..ce6fda6f2c21e2e57661ab1981131f6e2a7150f2 100644 (file)
@@ -40,6 +40,7 @@ typedef enum {
        TOKEN_LPAREN,
        TOKEN_LT,
        TOKEN_MEMBER,
+       TOKEN_DOTS,
        TOKEN_MOD,
        TOKEN_MUL,
        TOKEN_NEQ,