Module: wine Branch: master Commit: b6e9a83d781e33b261fa880ef78a85025449913c URL: http://source.winehq.org/git/wine.git/?a=commit;h=b6e9a83d781e33b261fa880ef7...
Author: Jacek Caban jacek@codeweavers.com Date: Thu Sep 8 14:55:51 2011 +0200
vbscript: Added support for call keyword in lexer.
---
dlls/vbscript/lex.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++- dlls/vbscript/parser.y | 1 + 2 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/dlls/vbscript/lex.c b/dlls/vbscript/lex.c index d41c582..af01220 100644 --- a/dlls/vbscript/lex.c +++ b/dlls/vbscript/lex.c @@ -26,11 +26,61 @@
WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
+static const WCHAR callW[] = {'c','a','l','l',0}; + +static const struct { + const WCHAR *word; + int token; +} keywords[] = { + {callW, tCALL} +}; + static inline BOOL is_identifier_char(WCHAR c) { return isalnumW(c) || c == '_'; }
+static int check_keyword(parser_ctx_t *ctx, const WCHAR *word) +{ + const WCHAR *p1 = ctx->ptr; + const WCHAR *p2 = word; + WCHAR c; + + while(p1 < ctx->end && *p2) { + c = tolowerW(*p1); + if(c != *p2) + return c - *p2; + p1++; + p2++; + } + + if(*p2 || (p1 < ctx->end && is_identifier_char(*p1))) + return 1; + + ctx->ptr = p1; + return 0; +} + +static int check_keywords(parser_ctx_t *ctx) +{ + int min = 0, max = sizeof(keywords)/sizeof(keywords[0])-1, r, i; + + while(min <= max) { + i = (min+max)/2; + + r = check_keyword(ctx, keywords[i].word); + if(!r) + return keywords[i].token; + + if(r > 0) + min = i+1; + else + max = i-1; + } + + return 0; +} + static int parse_identifier(parser_ctx_t *ctx, const WCHAR **ret) { const WCHAR *ptr = ctx->ptr++; @@ -62,8 +112,12 @@ static int parse_next_token(void *lval, parser_ctx_t *ctx)
c = *ctx->ptr;
- if(isalphaW(c)) - return parse_identifier(ctx, lval); + if(isalphaW(c)) { + int ret = check_keywords(ctx); + if(!ret) + return parse_identifier(ctx, lval); + return ret; + }
switch(c) { case '\n': diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y index d5c7d40..447aa12 100644 --- a/dlls/vbscript/parser.y +++ b/dlls/vbscript/parser.y @@ -54,6 +54,7 @@ static statement_t *new_call_statement(parser_ctx_t*,member_expression_t*); }
%token tEOF tNL blah +%token tCALL %token <string> tIdentifier
%type <statement> Statement StatementNl