From: Brendan McGrath Subject: [PATCH v2] vbscript: Allow "Safe Keywords" to also be an id Message-Id: <20190213043400.3724-1-brendan@redmandi.com> Date: Wed, 13 Feb 2019 15:34:00 +1100 In-Reply-To: References: "Safe Keywords" include: - Default - Error - Explicit - Property - Step Signed-off-by: Brendan McGrath --- Changes since v1: - remove the test for property (as one already exists, causing failures on Windows) dlls/vbscript/lex.c | 10 ++++++---- dlls/vbscript/parser.y | 21 ++++++++++++--------- dlls/vbscript/tests/lang.vbs | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/dlls/vbscript/lex.c b/dlls/vbscript/lex.c index 571854db58..751fdb2aa5 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; @@ -173,18 +173,20 @@ static int check_keyword(parser_ctx_t *ctx, const WCHAR *word) if(*p2 || (p1 < ctx->end && is_identifier_char(*p1))) return 1; + if(lval) + *lval = word; ctx->ptr = p1; 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 +414,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 020109998e..b81d791966 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 tIdentifier tString +%token tDEFAULT tERROR tEXPLICIT tPROPERTY tSTEP %token tLong tShort %token 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 2af77bdfcc..d016e0e22c 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -1345,4 +1345,21 @@ end class set x = new RegExp Call ok(x.Global = false, "x.Global = " & x.Global) +' 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""") + reportSuccess() -- 2.17.1