Module: wine Branch: master Commit: d2937bfff2d59e3b5d41baa173e9c634b0a12a22 URL: https://source.winehq.org/git/wine.git/?a=commit;h=d2937bfff2d59e3b5d41baa17...
Author: Brendan McGrath brendan@redmandi.com Date: Fri Feb 15 14:06:15 2019 +0100
vbscript: Allow more keywords to be used as identifiers.
Signed-off-by: Brendan McGrath brendan@redmandi.com Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/vbscript/lex.c | 9 +++++---- dlls/vbscript/parser.y | 21 ++++++++++++--------- dlls/vbscript/tests/lang.vbs | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/dlls/vbscript/lex.c b/dlls/vbscript/lex.c index 571854d..fa467f0 100644 --- a/dlls/vbscript/lex.c +++ b/dlls/vbscript/lex.c @@ -156,7 +156,7 @@ static inline BOOL is_identifier_char(WCHAR c) return isalnumW(c) || c == '_'; }
-static int check_keyword(parser_ctx_t *ctx, const WCHAR *word) +static int check_keyword(parser_ctx_t *ctx, const WCHAR *word, const WCHAR **lval) { const WCHAR *p1 = ctx->ptr; const WCHAR *p2 = word; @@ -174,17 +174,18 @@ static int check_keyword(parser_ctx_t *ctx, const WCHAR *word) return 1;
ctx->ptr = p1; + *lval = word; return 0; }
-static int check_keywords(parser_ctx_t *ctx) +static int check_keywords(parser_ctx_t *ctx, const WCHAR **lval) { int min = 0, max = ARRAY_SIZE(keywords)-1, r, i;
while(min <= max) { i = (min+max)/2;
- r = check_keyword(ctx, keywords[i].word); + r = check_keyword(ctx, keywords[i].word, lval); if(!r) return keywords[i].token;
@@ -412,7 +413,7 @@ static int parse_next_token(void *lval, parser_ctx_t *ctx) return parse_numeric_literal(ctx, lval);
if(isalphaW(c)) { - int ret = check_keywords(ctx); + int ret = check_keywords(ctx, lval); if(!ret) return parse_identifier(ctx, lval); if(ret != tREM) diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y index 0201099..b81d791 100644 --- a/dlls/vbscript/parser.y +++ b/dlls/vbscript/parser.y @@ -71,8 +71,6 @@ static class_decl_t *add_dim_prop(parser_ctx_t*,class_decl_t*,dim_decl_t*,unsign
static statement_t *link_statements(statement_t*,statement_t*);
-static const WCHAR propertyW[] = {'p','r','o','p','e','r','t','y',0}; - #define STORAGE_IS_PRIVATE 1 #define STORAGE_IS_DEFAULT 2
@@ -108,17 +106,18 @@ static const WCHAR propertyW[] = {'p','r','o','p','e','r','t','y',0}; %token tTRUE tFALSE %token tNOT tAND tOR tXOR tEQV tIMP tNEQ %token tIS tLTEQ tGTEQ tMOD -%token tCALL tDIM tSUB tFUNCTION tPROPERTY tGET tLET tCONST +%token tCALL tDIM tSUB tFUNCTION tGET tLET tCONST %token tIF tELSE tELSEIF tEND tTHEN tEXIT -%token tWHILE tWEND tDO tLOOP tUNTIL tFOR tTO tSTEP tEACH tIN +%token tWHILE tWEND tDO tLOOP tUNTIL tFOR tTO tEACH tIN %token tSELECT tCASE %token tBYREF tBYVAL -%token tOPTION tEXPLICIT +%token tOPTION %token tSTOP %token tNOTHING tEMPTY tNULL -%token tCLASS tSET tNEW tPUBLIC tPRIVATE tDEFAULT tME -%token tERROR tNEXT tON tRESUME tGOTO +%token tCLASS tSET tNEW tPUBLIC tPRIVATE tME +%token tNEXT tON tRESUME tGOTO %token <string> tIdentifier tString +%token <string> tDEFAULT tERROR tEXPLICIT tPROPERTY tSTEP %token <lng> tLong tShort %token <dbl> tDouble
@@ -443,10 +442,14 @@ ArgumentDecl | tBYREF Identifier EmptyBrackets_opt { $$ = new_argument_decl(ctx, $2, TRUE); } | tBYVAL Identifier EmptyBrackets_opt { $$ = new_argument_decl(ctx, $2, FALSE); }
-/* 'property' may be both keyword and identifier, depending on context */ +/* these keywords may also be an identifier, depending on context */ Identifier : tIdentifier { $$ = $1; } - | tPROPERTY { $$ = propertyW; } + | tDEFAULT { $$ = $1; } + | tERROR { $$ = $1; } + | tEXPLICIT { $$ = $1; } + | tPROPERTY { $$ = $1; } + | tSTEP { $$ = $1; }
/* Most statements accept both new line and ':' as separators */ StSep diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index 2af77bd..15ad84a 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -1345,4 +1345,24 @@ end class set x = new RegExp Call ok(x.Global = false, "x.Global = " & x.Global)
+sub test_identifiers + ' test keywords that can also be a declared identifier + Dim default + default = "xx" + Call ok(default = "xx", "default = " & default & " expected ""xx""") + + Dim error + error = "xx" + Call ok(error = "xx", "error = " & error & " expected ""xx""") + + Dim explicit + explicit = "xx" + Call ok(explicit = "xx", "explicit = " & explicit & " expected ""xx""") + + Dim step + step = "xx" + Call ok(step = "xx", "step = " & step & " expected ""xx""") +end sub +call test_identifiers() + reportSuccess()