From deb7ccb8302f4477cf085740b9dfc7e0d11da47f Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Thu, 23 Aug 2012 11:12:32 +0200 Subject: [PATCH] for the lexer 3 dots now become TOKEN_DOTS --- lexer.c | 32 +++++++++++++++++++++++++++++++- lexer.h | 3 +++ 2 files changed, 34 insertions(+), 1 deletion(-) 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", -- 2.39.2