Use user defined parameterizing rules compstmt(stmts)
This commit is contained in:
parent
bb66b42a7f
commit
a1f010b8e4
Notes:
git
2025-01-04 09:59:48 +00:00
65
parse.y
65
parse.y
@ -2765,8 +2765,8 @@ rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
|
|||||||
%type <node> literal numeric simple_numeric ssym dsym symbol cpath
|
%type <node> literal numeric simple_numeric ssym dsym symbol cpath
|
||||||
%type <node_def_temp> defn_head defs_head k_def
|
%type <node_def_temp> defn_head defs_head k_def
|
||||||
%type <node_exits> block_open k_while k_until k_for allow_exits
|
%type <node_exits> block_open k_while k_until k_for allow_exits
|
||||||
%type <node> top_compstmt top_stmts top_stmt begin_block endless_arg endless_command
|
%type <node> top_stmts top_stmt begin_block endless_arg endless_command
|
||||||
%type <node> bodystmt compstmt stmts stmt_or_begin stmt expr arg primary
|
%type <node> bodystmt stmts stmt_or_begin stmt expr arg primary
|
||||||
%type <node> command command_call command_call_value method_call
|
%type <node> command command_call command_call_value method_call
|
||||||
%type <node> expr_value expr_value_do arg_value primary_value rel_expr
|
%type <node> expr_value expr_value_do arg_value primary_value rel_expr
|
||||||
%type <node_fcall> fcall
|
%type <node_fcall> fcall
|
||||||
@ -2952,6 +2952,13 @@ rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
%rule compstmt(stmts) <node>
|
||||||
|
: stmts terms?
|
||||||
|
{
|
||||||
|
void_stmts(p, $$ = $stmts);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
%rule f_opt(value) <node_opt_arg>
|
%rule f_opt(value) <node_opt_arg>
|
||||||
: f_arg_asgn f_eq value
|
: f_arg_asgn f_eq value
|
||||||
{
|
{
|
||||||
@ -3077,7 +3084,7 @@ program : {
|
|||||||
/* jumps are possible in the top-level loop. */
|
/* jumps are possible in the top-level loop. */
|
||||||
if (!ifndef_ripper(p->do_loop) + 0) init_block_exit(p);
|
if (!ifndef_ripper(p->do_loop) + 0) init_block_exit(p);
|
||||||
}
|
}
|
||||||
top_compstmt
|
compstmt(top_stmts)
|
||||||
{
|
{
|
||||||
if ($2 && !compile_for_eval) {
|
if ($2 && !compile_for_eval) {
|
||||||
NODE *node = $2;
|
NODE *node = $2;
|
||||||
@ -3097,12 +3104,6 @@ program : {
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
top_compstmt : top_stmts terms?
|
|
||||||
{
|
|
||||||
void_stmts(p, $$ = $1);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
top_stmts : none
|
top_stmts : none
|
||||||
{
|
{
|
||||||
$$ = NEW_BEGIN(0, &@$);
|
$$ = NEW_BEGIN(0, &@$);
|
||||||
@ -3134,7 +3135,7 @@ top_stmt : stmt
|
|||||||
|
|
||||||
block_open : '{' {$$ = init_block_exit(p);};
|
block_open : '{' {$$ = init_block_exit(p);};
|
||||||
|
|
||||||
begin_block : block_open top_compstmt '}'
|
begin_block : block_open compstmt(top_stmts) '}'
|
||||||
{
|
{
|
||||||
restore_block_exit(p, $block_open);
|
restore_block_exit(p, $block_open);
|
||||||
p->eval_tree_begin = block_append(p, p->eval_tree_begin,
|
p->eval_tree_begin = block_append(p, p->eval_tree_begin,
|
||||||
@ -3144,7 +3145,7 @@ begin_block : block_open top_compstmt '}'
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
bodystmt : compstmt[body]
|
bodystmt : compstmt(stmts)[body]
|
||||||
lex_ctxt[ctxt]
|
lex_ctxt[ctxt]
|
||||||
opt_rescue
|
opt_rescue
|
||||||
k_else
|
k_else
|
||||||
@ -3152,7 +3153,7 @@ bodystmt : compstmt[body]
|
|||||||
if (!$opt_rescue) yyerror1(&@k_else, "else without rescue is useless");
|
if (!$opt_rescue) yyerror1(&@k_else, "else without rescue is useless");
|
||||||
next_rescue_context(&p->ctxt, &$ctxt, after_else);
|
next_rescue_context(&p->ctxt, &$ctxt, after_else);
|
||||||
}
|
}
|
||||||
compstmt[elsebody]
|
compstmt(stmts)[elsebody]
|
||||||
{
|
{
|
||||||
next_rescue_context(&p->ctxt, &$ctxt, after_ensure);
|
next_rescue_context(&p->ctxt, &$ctxt, after_ensure);
|
||||||
}
|
}
|
||||||
@ -3161,7 +3162,7 @@ bodystmt : compstmt[body]
|
|||||||
$$ = new_bodystmt(p, $body, $opt_rescue, $elsebody, $opt_ensure, &@$);
|
$$ = new_bodystmt(p, $body, $opt_rescue, $elsebody, $opt_ensure, &@$);
|
||||||
/*% ripper: bodystmt!($:body, $:opt_rescue, $:elsebody, $:opt_ensure) %*/
|
/*% ripper: bodystmt!($:body, $:opt_rescue, $:elsebody, $:opt_ensure) %*/
|
||||||
}
|
}
|
||||||
| compstmt[body]
|
| compstmt(stmts)[body]
|
||||||
lex_ctxt[ctxt]
|
lex_ctxt[ctxt]
|
||||||
opt_rescue
|
opt_rescue
|
||||||
{
|
{
|
||||||
@ -3174,12 +3175,6 @@ bodystmt : compstmt[body]
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
compstmt : stmts terms?
|
|
||||||
{
|
|
||||||
void_stmts(p, $$ = $1);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
stmts : none
|
stmts : none
|
||||||
{
|
{
|
||||||
$$ = NEW_BEGIN(0, &@$);
|
$$ = NEW_BEGIN(0, &@$);
|
||||||
@ -3297,7 +3292,7 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
|
|||||||
$$ = NEW_RESCUE(remove_begin($1), resq, 0, &@$);
|
$$ = NEW_RESCUE(remove_begin($1), resq, 0, &@$);
|
||||||
/*% ripper: rescue_mod!($:1, $:4) %*/
|
/*% ripper: rescue_mod!($:1, $:4) %*/
|
||||||
}
|
}
|
||||||
| k_END allow_exits '{' compstmt '}'
|
| k_END allow_exits '{' compstmt(stmts) '}'
|
||||||
{
|
{
|
||||||
if (p->ctxt.in_def) {
|
if (p->ctxt.in_def) {
|
||||||
rb_warn0("END in method; use at_exit");
|
rb_warn0("END in method; use at_exit");
|
||||||
@ -4367,13 +4362,13 @@ primary : inline_primary
|
|||||||
nd_set_line($$, @1.end_pos.lineno);
|
nd_set_line($$, @1.end_pos.lineno);
|
||||||
/*% ripper: begin!($:3) %*/
|
/*% ripper: begin!($:3) %*/
|
||||||
}
|
}
|
||||||
| tLPAREN_ARG compstmt {SET_LEX_STATE(EXPR_ENDARG);} ')'
|
| tLPAREN_ARG compstmt(stmts) {SET_LEX_STATE(EXPR_ENDARG);} ')'
|
||||||
{
|
{
|
||||||
if (nd_type_p($2, NODE_SELF)) RNODE_SELF($2)->nd_state = 0;
|
if (nd_type_p($2, NODE_SELF)) RNODE_SELF($2)->nd_state = 0;
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
/*% ripper: paren!($:2) %*/
|
/*% ripper: paren!($:2) %*/
|
||||||
}
|
}
|
||||||
| tLPAREN compstmt ')'
|
| tLPAREN compstmt(stmts) ')'
|
||||||
{
|
{
|
||||||
if (nd_type_p($2, NODE_SELF)) RNODE_SELF($2)->nd_state = 0;
|
if (nd_type_p($2, NODE_SELF)) RNODE_SELF($2)->nd_state = 0;
|
||||||
$$ = NEW_BLOCK($2, &@$);
|
$$ = NEW_BLOCK($2, &@$);
|
||||||
@ -4450,7 +4445,7 @@ primary : inline_primary
|
|||||||
}
|
}
|
||||||
| lambda
|
| lambda
|
||||||
| k_if expr_value then
|
| k_if expr_value then
|
||||||
compstmt
|
compstmt(stmts)
|
||||||
if_tail
|
if_tail
|
||||||
k_end
|
k_end
|
||||||
{
|
{
|
||||||
@ -4462,7 +4457,7 @@ primary : inline_primary
|
|||||||
/*% ripper: if!($:2, $:4, $:5) %*/
|
/*% ripper: if!($:2, $:4, $:5) %*/
|
||||||
}
|
}
|
||||||
| k_unless expr_value then
|
| k_unless expr_value then
|
||||||
compstmt
|
compstmt(stmts)
|
||||||
opt_else
|
opt_else
|
||||||
k_end
|
k_end
|
||||||
{
|
{
|
||||||
@ -4471,7 +4466,7 @@ primary : inline_primary
|
|||||||
/*% ripper: unless!($:2, $:4, $:5) %*/
|
/*% ripper: unless!($:2, $:4, $:5) %*/
|
||||||
}
|
}
|
||||||
| k_while expr_value_do
|
| k_while expr_value_do
|
||||||
compstmt
|
compstmt(stmts)
|
||||||
k_end
|
k_end
|
||||||
{
|
{
|
||||||
restore_block_exit(p, $1);
|
restore_block_exit(p, $1);
|
||||||
@ -4480,7 +4475,7 @@ primary : inline_primary
|
|||||||
/*% ripper: while!($:2, $:3) %*/
|
/*% ripper: while!($:2, $:3) %*/
|
||||||
}
|
}
|
||||||
| k_until expr_value_do
|
| k_until expr_value_do
|
||||||
compstmt
|
compstmt(stmts)
|
||||||
k_end
|
k_end
|
||||||
{
|
{
|
||||||
restore_block_exit(p, $1);
|
restore_block_exit(p, $1);
|
||||||
@ -4523,7 +4518,7 @@ primary : inline_primary
|
|||||||
/*% ripper: case!($:2, $:4) %*/
|
/*% ripper: case!($:2, $:4) %*/
|
||||||
}
|
}
|
||||||
| k_for for_var keyword_in expr_value_do
|
| k_for for_var keyword_in expr_value_do
|
||||||
compstmt
|
compstmt(stmts)
|
||||||
k_end
|
k_end
|
||||||
{
|
{
|
||||||
restore_block_exit(p, $1);
|
restore_block_exit(p, $1);
|
||||||
@ -4862,7 +4857,7 @@ do : term
|
|||||||
|
|
||||||
if_tail : opt_else
|
if_tail : opt_else
|
||||||
| k_elsif expr_value then
|
| k_elsif expr_value then
|
||||||
compstmt
|
compstmt(stmts)
|
||||||
if_tail
|
if_tail
|
||||||
{
|
{
|
||||||
$$ = new_if(p, $2, $4, $5, &@$, &@1, &@3, &NULL_LOC);
|
$$ = new_if(p, $2, $4, $5, &@$, &@1, &@3, &NULL_LOC);
|
||||||
@ -4872,7 +4867,7 @@ if_tail : opt_else
|
|||||||
;
|
;
|
||||||
|
|
||||||
opt_else : none
|
opt_else : none
|
||||||
| k_else compstmt
|
| k_else compstmt(stmts)
|
||||||
{
|
{
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
/*% ripper: else!($:2) %*/
|
/*% ripper: else!($:2) %*/
|
||||||
@ -5184,7 +5179,7 @@ f_larglist : '(' f_args opt_bv_decl ')'
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
lambda_body : tLAMBEG compstmt '}'
|
lambda_body : tLAMBEG compstmt(stmts) '}'
|
||||||
{
|
{
|
||||||
token_info_pop(p, "}", &@3);
|
token_info_pop(p, "}", &@3);
|
||||||
$$ = new_locations_lambda_body(p, $2, &@2, &@1, &@3);
|
$$ = new_locations_lambda_body(p, $2, &@2, &@1, &@3);
|
||||||
@ -5327,7 +5322,7 @@ brace_block : '{' brace_body '}'
|
|||||||
|
|
||||||
brace_body : {$$ = dyna_push(p);}[dyna]<vars>
|
brace_body : {$$ = dyna_push(p);}[dyna]<vars>
|
||||||
max_numparam numparam it_id allow_exits
|
max_numparam numparam it_id allow_exits
|
||||||
opt_block_param[args] compstmt
|
opt_block_param[args] compstmt(stmts)
|
||||||
{
|
{
|
||||||
int max_numparam = p->max_numparam;
|
int max_numparam = p->max_numparam;
|
||||||
ID it_id = p->it_id;
|
ID it_id = p->it_id;
|
||||||
@ -5388,7 +5383,7 @@ case_args : arg_value
|
|||||||
;
|
;
|
||||||
|
|
||||||
case_body : k_when case_args then
|
case_body : k_when case_args then
|
||||||
compstmt
|
compstmt(stmts)
|
||||||
cases
|
cases
|
||||||
{
|
{
|
||||||
$$ = NEW_WHEN($2, $4, $5, &@$, &@1, &@3);
|
$$ = NEW_WHEN($2, $4, $5, &@$, &@1, &@3);
|
||||||
@ -5420,7 +5415,7 @@ p_case_body : keyword_in
|
|||||||
pop_pvtbl(p, $p_pvtbl);
|
pop_pvtbl(p, $p_pvtbl);
|
||||||
p->ctxt.in_kwarg = $ctxt.in_kwarg;
|
p->ctxt.in_kwarg = $ctxt.in_kwarg;
|
||||||
}
|
}
|
||||||
compstmt
|
compstmt(stmts)
|
||||||
p_cases[cases]
|
p_cases[cases]
|
||||||
{
|
{
|
||||||
$$ = NEW_IN($expr, $compstmt, $cases, &@$);
|
$$ = NEW_IN($expr, $compstmt, $cases, &@$);
|
||||||
@ -5888,7 +5883,7 @@ p_const : tCOLON3 cname
|
|||||||
;
|
;
|
||||||
|
|
||||||
opt_rescue : k_rescue exc_list exc_var then
|
opt_rescue : k_rescue exc_list exc_var then
|
||||||
compstmt
|
compstmt(stmts)
|
||||||
opt_rescue
|
opt_rescue
|
||||||
{
|
{
|
||||||
NODE *err = $3;
|
NODE *err = $3;
|
||||||
@ -6157,7 +6152,7 @@ string_content : tSTRING_CONTENT
|
|||||||
$$ = p->heredoc_indent;
|
$$ = p->heredoc_indent;
|
||||||
p->heredoc_indent = 0;
|
p->heredoc_indent = 0;
|
||||||
}[indent]<num>
|
}[indent]<num>
|
||||||
compstmt string_dend
|
compstmt(stmts) string_dend
|
||||||
{
|
{
|
||||||
COND_POP();
|
COND_POP();
|
||||||
CMDARG_POP();
|
CMDARG_POP();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user