allow {} expression lists for =/+=/-= RHS

This commit is contained in:
Vern Paxson 2022-03-11 14:17:39 -08:00 committed by Tim Wojtulewicz
parent e13dd30565
commit 8e745f6f48

View file

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