Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use user defined parameterizing rules compstmt(stmts) #10726

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 30 additions & 36 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -2847,8 +2847,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_def_temp> defn_head defs_head k_def
%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> bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call
%type <node> top_stmts top_stmt begin_block endless_arg endless_command
%type <node> bodystmt stmts stmt_or_begin stmt expr arg primary command command_call method_call
%type <node> expr_value expr_value_do arg_value primary_value rel_expr
%type <node_fcall> fcall
%type <node> if_tail opt_else case_body case_args cases opt_rescue exc_list exc_var opt_ensure
Expand Down Expand Up @@ -2983,6 +2983,12 @@ rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
/*
* parameterizing rules
*/
%rule compstmt(stmts): stmts terms?
{
$$ = void_stmts(p, $1);
}
;

%rule f_opt(value) <node_opt_arg>: f_arg_asgn f_eq value
{
p->cur_arg = 0;
Expand Down Expand Up @@ -3042,7 +3048,7 @@ program : {
/* jumps are possible in the top-level loop. */
if (!ifndef_ripper(p->do_loop) + 0) init_block_exit(p);
}
top_compstmt
compstmt(top_stmts)
{
if ($2 && !compile_for_eval) {
NODE *node = $2;
Expand All @@ -3062,12 +3068,6 @@ program : {
}
;

top_compstmt : top_stmts terms?
{
$$ = void_stmts(p, $1);
}
;

top_stmts : none
{
$$ = NEW_BEGIN(0, &@$);
Expand Down Expand Up @@ -3099,7 +3099,7 @@ top_stmt : stmt

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);
p->eval_tree_begin = block_append(p, p->eval_tree_begin,
Expand All @@ -3109,15 +3109,15 @@ begin_block : block_open top_compstmt '}'
}
;

bodystmt : compstmt[body]
bodystmt : compstmt(stmts)[body]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lex_ctxt[ctxt]
opt_rescue
k_else
{
if (!$opt_rescue) yyerror1(&@k_else, "else without rescue is useless");
next_rescue_context(&p->ctxt, &$ctxt, after_else);
}
compstmt[elsebody]
compstmt(stmts)[elsebody]
{
next_rescue_context(&p->ctxt, &$ctxt, after_ensure);
}
Expand All @@ -3126,7 +3126,7 @@ bodystmt : compstmt[body]
$$ = new_bodystmt(p, $body, $opt_rescue, $elsebody, $opt_ensure, &@$);
/*% ripper: bodystmt!($:body, $:opt_rescue, $:elsebody, $:opt_ensure) %*/
}
| compstmt[body]
| compstmt(stmts)[body]
lex_ctxt[ctxt]
opt_rescue
{
Expand All @@ -3139,12 +3139,6 @@ bodystmt : compstmt[body]
}
;

compstmt : stmts terms?
{
$$ = void_stmts(p, $1);
}
;

stmts : none
{
$$ = NEW_BEGIN(0, &@$);
Expand Down Expand Up @@ -3260,7 +3254,7 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
$$ = NEW_RESCUE(remove_begin($1), resq, 0, &@$);
/*% ripper: rescue_mod!($:1, $:4) %*/
}
| k_END allow_exits '{' compstmt '}'
| k_END allow_exits '{' compstmt(stmts) '}'
{
if (p->ctxt.in_def) {
rb_warn0("END in method; use at_exit");
Expand Down Expand Up @@ -4514,13 +4508,13 @@ primary : literal
nd_set_line($$, @1.end_pos.lineno);
/*% 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;
$$ = $2;
/*% ripper: paren!($:2) %*/
}
| tLPAREN compstmt ')'
| tLPAREN compstmt(stmts) ')'
{
if (nd_type_p($2, NODE_SELF)) RNODE_SELF($2)->nd_state = 0;
$$ = NEW_BLOCK($2, &@$);
Expand Down Expand Up @@ -4597,7 +4591,7 @@ primary : literal
}
| lambda
| k_if expr_value then
compstmt
compstmt(stmts)
if_tail
k_end
{
Expand All @@ -4606,7 +4600,7 @@ primary : literal
/*% ripper: if!($:2, $:4, $:5) %*/
}
| k_unless expr_value then
compstmt
compstmt(stmts)
opt_else
k_end
{
Expand All @@ -4615,7 +4609,7 @@ primary : literal
/*% ripper: unless!($:2, $:4, $:5) %*/
}
| k_while expr_value_do
compstmt
compstmt(stmts)
k_end
{
restore_block_exit(p, $1);
Expand All @@ -4624,7 +4618,7 @@ primary : literal
/*% ripper: while!($:2, $:3) %*/
}
| k_until expr_value_do
compstmt
compstmt(stmts)
k_end
{
restore_block_exit(p, $1);
Expand Down Expand Up @@ -4667,7 +4661,7 @@ primary : literal
/*% ripper: case!($:2, $:4) %*/
}
| k_for for_var keyword_in expr_value_do
compstmt
compstmt(stmts)
k_end
{
restore_block_exit(p, $1);
Expand Down Expand Up @@ -5007,7 +5001,7 @@ do : term

if_tail : opt_else
| k_elsif expr_value then
compstmt
compstmt(stmts)
if_tail
{
$$ = new_if(p, $2, $4, $5, &@$);
Expand All @@ -5017,7 +5011,7 @@ if_tail : opt_else
;

opt_else : none
| k_else compstmt
| k_else compstmt(stmts)
{
$$ = $2;
/*% ripper: else!($:2) %*/
Expand Down Expand Up @@ -5339,7 +5333,7 @@ f_larglist : '(' f_args opt_bv_decl ')'
}
;

lambda_body : tLAMBEG compstmt '}'
lambda_body : tLAMBEG compstmt(stmts) '}'
{
token_info_pop(p, "}", &@3);
$$ = $2;
Expand Down Expand Up @@ -5463,7 +5457,7 @@ brace_block : '{' brace_body '}'

brace_body : {$<vars>$ = dyna_push(p);}[dyna]
max_numparam numparam it_id allow_exits
opt_block_param[args] compstmt
opt_block_param[args] compstmt(stmts)
{
int max_numparam = p->max_numparam;
ID it_id = p->it_id;
Expand Down Expand Up @@ -5524,7 +5518,7 @@ case_args : arg_value
;

case_body : k_when case_args then
compstmt
compstmt(stmts)
cases
{
$$ = NEW_WHEN($2, $4, $5, &@$);
Expand Down Expand Up @@ -5556,7 +5550,7 @@ p_case_body : keyword_in
pop_pvtbl(p, $p_pvtbl);
p->ctxt.in_kwarg = $ctxt.in_kwarg;
}
compstmt
compstmt(stmts)
p_cases[cases]
{
$$ = NEW_IN($expr, $compstmt, $cases, &@$);
Expand Down Expand Up @@ -6058,7 +6052,7 @@ p_const : tCOLON3 cname
;

opt_rescue : k_rescue exc_list exc_var then
compstmt
compstmt(stmts)
opt_rescue
{
NODE *body = $5;
Expand Down Expand Up @@ -6102,7 +6096,7 @@ exc_var : tASSOC lhs
| none
;

opt_ensure : k_ensure compstmt
opt_ensure : k_ensure compstmt(stmts)
{
p->ctxt.in_rescue = $1.in_rescue;
$$ = $2;
Expand Down Expand Up @@ -6336,7 +6330,7 @@ string_content : tSTRING_CONTENT
$<num>$ = p->heredoc_indent;
p->heredoc_indent = 0;
}[indent]
compstmt string_dend
compstmt(stmts) string_dend
{
COND_POP();
CMDARG_POP();
Expand Down