Skip to content

Commit

Permalink
Use user defined parameterizing rules f_kwarg(kw)
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed May 1, 2024
1 parent 9f7e0d2 commit d1910a2
Showing 1 changed file with 23 additions and 36 deletions.
59 changes: 23 additions & 36 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -2869,7 +2869,7 @@ rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
%type <node> assoc_list assocs assoc undef_list backref string_dvar for_var
%type <node_args> block_param opt_block_param block_param_def
%type <node_opt_arg> f_opt
%type <node_kw_arg> f_kwarg f_kw f_block_kwarg f_block_kw
%type <node_kw_arg> f_kw f_block_kw
%type <id> bv_decls opt_bv_decl bvar
%type <node> lambda lambda_body brace_body do_body
%type <node_args> f_larglist
Expand Down Expand Up @@ -2986,12 +2986,17 @@ rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
/*
* parameterizing rules
*/
%rule words(begin, word_list): begin ' '+ word_list tSTRING_END
{
$$ = make_list($3, &@$);
/*% ripper: array!($:3) %*/
}
;
%rule f_kwarg(kw): kw
{
$$ = $1;
/*% ripper: rb_ary_new3(1, get_value($:1)) %*/
}
| f_kwarg(kw) <node_kw_arg> ',' kw
{
$$ = kwd_append($1, $3);
/*% ripper: rb_ary_push(get_value($:1), get_value($:3)) %*/
}
;

%rule opt_args_tail(tail): ',' tail
{
Expand All @@ -3005,6 +3010,13 @@ rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
}
;

%rule words(begin, word_list): begin ' '+ word_list tSTRING_END
{
$$ = make_list($3, &@$);
/*% ripper: array!($:3) %*/
}
;

%%
program : {
SET_LEX_STATE(EXPR_BEG);
Expand Down Expand Up @@ -5073,12 +5085,12 @@ f_any_kwrest : f_kwrest

f_eq : {p->ctxt.in_argdef = 0;} '=';

block_args_tail : f_block_kwarg ',' f_kwrest opt_f_block_arg
block_args_tail : f_kwarg(f_block_kw) <node_kw_arg> ',' f_kwrest opt_f_block_arg
{
$$ = new_args_tail(p, $1, $3, $4, &@3);
/*% ripper: rb_ary_new_from_args(3, get_value($:1), get_value($:3), get_value($:4)); %*/
}
| f_block_kwarg opt_f_block_arg
| f_kwarg(f_block_kw) <node_kw_arg> opt_f_block_arg
{
$$ = new_args_tail(p, $1, 0, $2, &@1);
/*% ripper: rb_ary_new_from_args(3, get_value($:1), Qnil, get_value($:2)); %*/
Expand Down Expand Up @@ -6492,12 +6504,12 @@ f_arglist : f_paren_args
}
;

args_tail : f_kwarg ',' f_kwrest opt_f_block_arg
args_tail : f_kwarg(f_kw) <node_kw_arg> ',' f_kwrest opt_f_block_arg
{
$$ = new_args_tail(p, $1, $3, $4, &@3);
/*% ripper: rb_ary_new_from_args(3, get_value($:1), get_value($:3), get_value($:4)); %*/
}
| f_kwarg opt_f_block_arg
| f_kwarg(f_kw) <node_kw_arg> opt_f_block_arg
{
$$ = new_args_tail(p, $1, 0, $2, &@1);
/*% ripper: rb_ary_new_from_args(3, get_value($:1), Qnil, get_value($:2)); %*/
Expand Down Expand Up @@ -6752,31 +6764,6 @@ f_block_kw : f_label primary_value
}
;

f_block_kwarg : f_block_kw
{
$$ = $1;
/*% ripper: rb_ary_new3(1, get_value($:1)) %*/
}
| f_block_kwarg ',' f_block_kw
{
$$ = kwd_append($1, $3);
/*% ripper: rb_ary_push(get_value($:1), get_value($:3)) %*/
}
;


f_kwarg : f_kw
{
$$ = $1;
/*% ripper: rb_ary_new3(1, get_value($:1)) %*/
}
| f_kwarg ',' f_kw
{
$$ = kwd_append($1, $3);
/*% ripper: rb_ary_push(get_value($:1), get_value($:3)) %*/
}
;

kwrest_mark : tPOW
| tDSTAR
;
Expand Down

0 comments on commit d1910a2

Please sign in to comment.