vbscript: Improve parsing of separators in loops and switches.
Dmitry Kislyuk
dimaki at rocketmail.com
Tue Sep 19 22:48:38 CDT 2017
Signed-off-by: Dmitry Kislyuk <dimaki at rocketmail.com>
---
dlls/vbscript/parser.y | 24 ++++++++++++++----------
dlls/vbscript/tests/lang.vbs | 42 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 54 insertions(+), 12 deletions(-)
diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y
index 6b303eea35..53b51a0ef4 100644
--- a/dlls/vbscript/parser.y
+++ b/dlls/vbscript/parser.y
@@ -164,7 +164,7 @@ StatementsNl
| StatementNl StatementsNl { $$ = link_statements($1, $2); }
StatementNl
- : Statement tNL { $$ = $1; }
+ : Statement tNL { $$ = $1; }
Statement
: ':' { $$ = NULL; }
@@ -180,15 +180,15 @@ SimpleStatement
{ $1->args = $2; $$ = new_assign_statement(ctx, $1, $4); CHECK_ERROR; }
| tDIM DimDeclList { $$ = new_dim_statement(ctx, $2); CHECK_ERROR; }
| IfStatement { $$ = $1; }
- | tWHILE Expression StSep StatementsNl_opt tWEND
+ | tWHILE Expression StSeps StatementsNl_opt tWEND
{ $$ = new_while_statement(ctx, STAT_WHILE, $2, $4); CHECK_ERROR; }
- | tDO DoType Expression StSep StatementsNl_opt tLOOP
+ | tDO DoType Expression StSeps StatementsNl_opt tLOOP
{ $$ = new_while_statement(ctx, $2 ? STAT_WHILELOOP : STAT_UNTIL, $3, $5);
CHECK_ERROR; }
- | tDO StSep StatementsNl_opt tLOOP DoType Expression
+ | tDO StSeps StatementsNl_opt tLOOP DoType Expression
{ $$ = new_while_statement(ctx, $5 ? STAT_DOWHILE : STAT_DOUNTIL, $6, $3);
CHECK_ERROR; }
- | tDO StSep StatementsNl_opt tLOOP { $$ = new_while_statement(ctx, STAT_DOWHILE, NULL, $3); CHECK_ERROR; }
+ | tDO StSeps StatementsNl_opt tLOOP { $$ = new_while_statement(ctx, STAT_DOWHILE, NULL, $3); CHECK_ERROR; }
| FunctionDecl { $$ = new_function_statement(ctx, $1); CHECK_ERROR; }
| tEXIT tDO { $$ = new_statement(ctx, STAT_EXITDO, 0); CHECK_ERROR; }
| tEXIT tFOR { $$ = new_statement(ctx, STAT_EXITFOR, 0); CHECK_ERROR; }
@@ -201,11 +201,11 @@ SimpleStatement
| tON tERROR tRESUME tNEXT { $$ = new_onerror_statement(ctx, TRUE); CHECK_ERROR; }
| tON tERROR tGOTO '0' { $$ = new_onerror_statement(ctx, FALSE); CHECK_ERROR; }
| tCONST ConstDeclList { $$ = new_const_statement(ctx, $2); CHECK_ERROR; }
- | tFOR Identifier '=' Expression tTO Expression Step_opt StSep StatementsNl_opt tNEXT
+ | tFOR Identifier '=' Expression tTO Expression Step_opt StSeps StatementsNl_opt tNEXT
{ $$ = new_forto_statement(ctx, $2, $4, $6, $7, $9); CHECK_ERROR; }
- | tFOR tEACH Identifier tIN Expression StSep StatementsNl_opt tNEXT
+ | tFOR tEACH Identifier tIN Expression StSeps StatementsNl_opt tNEXT
{ $$ = new_foreach_statement(ctx, $3, $5, $7); }
- | tSELECT tCASE Expression StSep CaseClausules tEND tSELECT
+ | tSELECT tCASE Expression StSeps CaseClausules tEND tSELECT
{ $$ = new_select_statement(ctx, $3, $5); }
MemberExpression
@@ -273,8 +273,8 @@ Else_opt
CaseClausules
: /* empty */ { $$ = NULL; }
- | tCASE tELSE StSep StatementsNl { $$ = new_case_clausule(ctx, NULL, $4, NULL); }
- | tCASE ExpressionList StSep StatementsNl_opt CaseClausules
+ | tCASE tELSE StSeps StatementsNl { $$ = new_case_clausule(ctx, NULL, $4, NULL); }
+ | tCASE ExpressionList StSeps StatementsNl_opt CaseClausules
{ $$ = new_case_clausule(ctx, $2, $4, $5); }
Arguments_opt
@@ -448,6 +448,10 @@ Identifier
: tIdentifier { $$ = $1; }
| tPROPERTY { $$ = propertyW; }
+StSeps
+ : StSep
+ | StSep StSeps
+
/* Some statements accept both new line and ':' as a separator */
StSep
: tNL
diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs
index 23402cd893..89aa52e721 100644
--- a/dlls/vbscript/tests/lang.vbs
+++ b/dlls/vbscript/tests/lang.vbs
@@ -330,6 +330,13 @@ WHILE x < 3 : x = x + 1
Wend
Call ok(x = 3, "x not equal to 3")
+z = 2
+while z > -4 :
+
+
+z = z -2
+wend
+
x = false
y = false
do while not (x and y)
@@ -349,7 +356,8 @@ do while true
loop
x = 0
-Do While x < 2 : x = x + 1
+Do While x < 2 :
+x = x + 1
Loop
Call ok(x = 2, "x not equal to 2")
@@ -376,6 +384,14 @@ Do: :: x = x + 2
Loop Until x = 4
Call ok(x = 4, "x not equal to 4")
+x = 5
+Do: :
+
+: x = x * 2
+Loop Until x = 40
+Call ok(x = 40, "x not equal to 40")
+
+
x = false
do
if x then exit do
@@ -495,6 +511,12 @@ for x = 1 to 100
Call ok(false, "exit for not escaped the loop?")
next
+for x = 1 to 5 :
+:
+: :exit for
+ Call ok(false, "exit for not escaped the loop?")
+next
+
do while true
for x = 1 to 100
exit do
@@ -511,7 +533,8 @@ Call collectionObj.reset()
y = 0
x = 10
z = 0
-for each x in collectionObj : z = z + 2
+for each x in collectionObj :
+ :z = z + 2
y = y+1
Call ok(x = y, "x <> y")
next
@@ -611,6 +634,21 @@ select case 2: case 5,6,7: Call ok(false, "unexpected case")
end select
Call ok(x, "wrong case")
+x = False
+select case 1 :
+
+ :case 3, 4 :
+
+
+ case 5
+:
+ Call ok(false, "unexpected case") :
+ Case Else:
+
+ x = True
+end select
+Call ok(x, "wrong case")
+
if false then
Sub testsub
x = true
--
2.14.1
More information about the wine-patches
mailing list