diff --git a/src/parse.y b/src/parse.y index a7e93446fe..240d6017dd 100644 --- a/src/parse.y +++ b/src/parse.y @@ -5,7 +5,7 @@ // Switching parser table type fixes ambiguity problems. %define lr.type ielr -%expect 140 +%expect 196 %token TOK_ADD TOK_ADD_TO TOK_ADDR TOK_ANY %token TOK_ATENDIF TOK_ATELSE TOK_ATIF TOK_ATIFDEF TOK_ATIFNDEF @@ -58,7 +58,7 @@ %type local_id_list case_type_list %type init_class %type TOK_CONSTANT -%type expr opt_expr init opt_init anonymous_function lambda_body index_slice opt_deprecated when_condition +%type expr opt_expr rhs opt_init anonymous_function lambda_body index_slice opt_deprecated when_condition %type event %type stmt stmt_list func_body for_head %type type opt_type enum_body @@ -67,7 +67,7 @@ %type type_decl formal_args_decl %type type_decl_list formal_args_decl_list %type formal_args -%type expr_list opt_expr_list +%type expr_list opt_expr_list rhs_expr_list %type case %type case_list %type attr @@ -488,7 +488,7 @@ expr: $$ = new AddExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); } - | expr TOK_ADD_TO expr + | expr TOK_ADD_TO rhs { set_location(@1, @3); $$ = new AddToExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); @@ -500,7 +500,7 @@ expr: $$ = new SubExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); } - | expr TOK_REMOVE_FROM expr + | expr TOK_REMOVE_FROM rhs { set_location(@1, @3); $$ = new RemoveFromExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); @@ -596,7 +596,7 @@ expr: $$ = new CondExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}, {AdoptRef{}, $5}); } - | expr '=' expr + | expr '=' rhs { set_location(@1, @3); @@ -608,7 +608,7 @@ expr: $$ = get_assign_expr({AdoptRef{}, $1}, {AdoptRef{}, $3}, in_init).release(); } - | TOK_LOCAL local_id '=' expr + | TOK_LOCAL local_id '=' rhs { set_location(@2, @4); if ( ! locals_at_this_scope.empty() ) @@ -794,7 +794,6 @@ expr: | anonymous_function - | TOK_SCHEDULE expr '{' event '}' { set_location(@1, @5); @@ -906,6 +905,19 @@ expr: } ; +rhs: '{' { ++in_init; } rhs_expr_list '}' + { + --in_init; + $$ = $3; + } + | expr + ; + +rhs_expr_list: expr_list opt_comma + | + { $$ = new ListExpr(); } + ; + expr_list: expr_list ',' expr { @@ -1508,20 +1520,12 @@ init_class: ; opt_init: - { ++in_init; } init { --in_init; } + { ++in_init; } rhs { --in_init; } { $$ = $2; } | { $$ = 0; } ; -init: - '{' opt_expr_list '}' - { $$ = $2; } - | '{' expr_list ',' '}' - { $$ = $2; } - | expr - ; - index_slice: expr '[' opt_expr ':' opt_expr ']' { @@ -2064,12 +2068,14 @@ opt_no_test: { $$ = true; } | { $$ = false; } + ; opt_no_test_block: TOK_NO_TEST { $$ = true; script_coverage_mgr.IncIgnoreDepth(); } | { $$ = false; } + ; opt_deprecated: TOK_ATTR_DEPRECATED @@ -2090,6 +2096,11 @@ opt_deprecated: } | { $$ = nullptr; } + ; + +opt_comma: ',' + | + ; %%