From: Wolfgang (Blub) Bumiller Date: Thu, 23 Aug 2012 09:12:32 +0000 (+0200) Subject: for the lexer 3 dots now become TOKEN_DOTS X-Git-Tag: 0.1-rc1~80 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=deb7ccb8302f4477cf085740b9dfc7e0d11da47f;p=xonotic%2Fgmqcc.git for the lexer 3 dots now become TOKEN_DOTS --- diff --git a/lexer.c b/lexer.c index 8416255..2798737 100644 --- 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 6cdb5a5..a2f06ac 100644 --- 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",