From: Francis De Brabandere <francisdb@gmail.com> Add error productions to detect wrong End keywords inside If, Select, With, Sub, Function, and Property blocks. For example, 'End With' inside an If block now returns error 1012 "Expected 'If'" instead of the generic 1002 "Syntax error". --- dlls/vbscript/parser.y | 20 ++++++++++++++++++++ dlls/vbscript/tests/run.c | 12 ++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y index f4b573e2d15..ab4f6250aa1 100644 --- a/dlls/vbscript/parser.y +++ b/dlls/vbscript/parser.y @@ -249,8 +249,12 @@ SimpleStatement { $$ = new_foreach_statement(ctx, @$, $3, $5, $7); } | tSELECT tCASE Expression StSep CaseClausules tEND tSELECT { $$ = new_select_statement(ctx, @$, $3, $5); } + | tSELECT tCASE Expression StSep CaseClausules tEND error + { ctx->hres = MAKE_VBSERROR(VBSE_EXPECTED_SELECT); YYABORT; } | tWITH Expression StSep StatementsNl_opt tEND tWITH { $$ = new_with_statement(ctx, @$, $2, $4); } + | tWITH Expression StSep StatementsNl_opt tEND error + { ctx->hres = MAKE_VBSERROR(VBSE_EXPECTED_WITH); YYABORT; } MemberExpression : Identifier { $$ = new_member_expression(ctx, NULL, $1); CHECK_ERROR; } @@ -319,6 +323,8 @@ IfStatement { $$ = new_if_statement(ctx, @$, $2, $4, NULL, $6); CHECK_ERROR; } | tIF Expression tTHEN Statement tELSE EndIf_opt { $$ = new_if_statement(ctx, @$, $2, $4, NULL, NULL); CHECK_ERROR; } + | tIF Expression tTHEN tNL StSep_opt StatementsNl_opt ElseIfs_opt Else_opt tEND error + { ctx->hres = MAKE_VBSERROR(VBSE_EXPECTED_IF); YYABORT; } EndIf_opt : /* empty */ @@ -500,16 +506,30 @@ PropertyDecl { $$ = new_function_decl(ctx, $4, FUNC_PROPLET, @2, $1, $6, $9); CHECK_ERROR; } | Storage_opt tPROPERTY tSET Identifier '(' ArgumentDeclList ')' StSep BodyStatements tEND tPROPERTY { $$ = new_function_decl(ctx, $4, FUNC_PROPSET, @2, $1, $6, $9); CHECK_ERROR; } + | Storage_opt tPROPERTY tGET Identifier ArgumentsDecl_opt StSep BodyStatements tEND error + { ctx->hres = MAKE_VBSERROR(VBSE_EXPECTED_PROPERTY); YYABORT; } + | Storage_opt tPROPERTY tLET Identifier '(' ArgumentDeclList ')' StSep BodyStatements tEND error + { ctx->hres = MAKE_VBSERROR(VBSE_EXPECTED_PROPERTY); YYABORT; } + | Storage_opt tPROPERTY tSET Identifier '(' ArgumentDeclList ')' StSep BodyStatements tEND error + { ctx->hres = MAKE_VBSERROR(VBSE_EXPECTED_PROPERTY); YYABORT; } FunctionDecl : Storage_opt tSUB Identifier StSep BodyStatements tEND tSUB { $$ = new_function_decl(ctx, $3, FUNC_SUB, @2, $1, NULL, $5); CHECK_ERROR; } | Storage_opt tSUB Identifier ArgumentsDecl Nl_opt BodyStatements tEND tSUB { $$ = new_function_decl(ctx, $3, FUNC_SUB, @2, $1, $4, $6); CHECK_ERROR; } + | Storage_opt tSUB Identifier StSep BodyStatements tEND error + { ctx->hres = MAKE_VBSERROR(VBSE_EXPECTED_SUB); YYABORT; } + | Storage_opt tSUB Identifier ArgumentsDecl Nl_opt BodyStatements tEND error + { ctx->hres = MAKE_VBSERROR(VBSE_EXPECTED_SUB); YYABORT; } | Storage_opt tFUNCTION Identifier StSep BodyStatements tEND tFUNCTION { $$ = new_function_decl(ctx, $3, FUNC_FUNCTION, @2, $1, NULL, $5); CHECK_ERROR; } | Storage_opt tFUNCTION Identifier ArgumentsDecl Nl_opt BodyStatements tEND tFUNCTION { $$ = new_function_decl(ctx, $3, FUNC_FUNCTION, @2, $1, $4, $6); CHECK_ERROR; } + | Storage_opt tFUNCTION Identifier StSep BodyStatements tEND error + { ctx->hres = MAKE_VBSERROR(VBSE_EXPECTED_FUNCTION); YYABORT; } + | Storage_opt tFUNCTION Identifier ArgumentsDecl Nl_opt BodyStatements tEND error + { ctx->hres = MAKE_VBSERROR(VBSE_EXPECTED_FUNCTION); YYABORT; } Storage_opt : /* empty*/ { $$ = 0; } diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index f6cde521242..437ecbeb715 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -3135,21 +3135,21 @@ static void test_parse_errors(void) " x = 1\n" "End With\n", 2, 4, - NULL, S_OK, -1012 + NULL, S_OK, 1012 }, { /* Expected 'Function' - End Sub inside Function - error 1015 */ L"Function F()\n" "End Sub\n", 1, 4, - NULL, S_OK, -1015 + NULL, S_OK, 1015 }, { /* Expected 'Sub' - End Function inside Sub - error 1016 */ L"Sub S()\n" "End Function\n", 1, 4, - NULL, S_OK, -1016 + NULL, S_OK, 1016 }, { /* Expected 'Select' - End If inside Select block - error 1022 */ @@ -3157,14 +3157,14 @@ static void test_parse_errors(void) " Case 1\n" "End If\n", 2, 4, - NULL, S_OK, -1022 + NULL, S_OK, 1022 }, { /* Expected 'With' - End Sub inside With block - error 1029 */ L"With CreateObject(\"Scripting.Dictionary\")\n" "End Sub\n", 1, 4, - NULL, S_OK, -1029 + NULL, S_OK, 1029 }, { /* Expected 'Property' - End Sub inside Property Get - error 1050 */ @@ -3173,7 +3173,7 @@ static void test_parse_errors(void) " End Sub\n" "End Class\n", 2, 6, - NULL, S_OK, -1050 + NULL, S_OK, 1050 }, { /* Multiple default members - error 1052 */ -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10588