Use user defined parameterizing rules def_endless_method(bodystmt)

This commit is contained in:
ydah 2025-01-02 01:23:26 +09:00 committed by Yudai Takada
parent 4fa68953fb
commit 2efa78099c
Notes: git 2025-01-04 09:59:04 +00:00

71
parse.y
View File

@ -2936,6 +2936,31 @@ rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
}
;
%rule def_endless_method(bodystmt) <node>
: defn_head[head] f_opt_paren_args[args] '=' bodystmt
{
endless_method_name(p, $head->nd_mid, &@head);
restore_defun(p, $head);
$bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
($$ = $head->nd_def)->nd_loc = @$;
RNODE_DEFN($$)->nd_defn = $bodystmt;
/*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
/*% ripper: def!($:head, $:args, $:$) %*/
local_pop(p);
}
| defs_head[head] f_opt_paren_args[args] '=' bodystmt
{
endless_method_name(p, $head->nd_mid, &@head);
restore_defun(p, $head);
$bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
($$ = $head->nd_def)->nd_loc = @$;
RNODE_DEFS($$)->nd_defn = $bodystmt;
/*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
/*% ripper: defs!(*$:head[0..2], $:args, $:$) %*/
local_pop(p);
}
;
%rule f_opt(value) <node_opt_arg>
: f_arg_asgn f_eq value
{
@ -3313,28 +3338,7 @@ command_asgn : asgn(lhs, command_rhs)
$$ = new_attr_op_assign(p, $1, idCOLON2, $3, $4, $6, &@$, &@2, &@3, &@4);
/*% ripper: opassign!(field!($:1, $:2, $:3), $:4, $:6) %*/
}
| defn_head[head] f_opt_paren_args[args] '=' endless_command[bodystmt]
{
endless_method_name(p, $head->nd_mid, &@head);
restore_defun(p, $head);
$bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
($$ = $head->nd_def)->nd_loc = @$;
RNODE_DEFN($$)->nd_defn = $bodystmt;
/*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
/*% ripper: def!($:head, $:args, $:$) %*/
local_pop(p);
}
| defs_head[head] f_opt_paren_args[args] '=' endless_command[bodystmt]
{
endless_method_name(p, $head->nd_mid, &@head);
restore_defun(p, $head);
$bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
($$ = $head->nd_def)->nd_loc = @$;
RNODE_DEFS($$)->nd_defn = $bodystmt;
/*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
/*% ripper: defs!(*$:head[0..2], $:args, $:$) %*/
local_pop(p);
}
| def_endless_method(endless_command)
| backref_with(command_rhs)
;
@ -4058,28 +4062,7 @@ arg : asgn(lhs, arg_rhs)
fixpos($$, $1);
/*% ripper: ifop!($:1, $:3, $:6) %*/
}
| defn_head[head] f_opt_paren_args[args] '=' endless_arg[bodystmt]
{
endless_method_name(p, $head->nd_mid, &@head);
restore_defun(p, $head);
$bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
($$ = $head->nd_def)->nd_loc = @$;
RNODE_DEFN($$)->nd_defn = $bodystmt;
/*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
/*% ripper: def!($:head, $:args, $:$) %*/
local_pop(p);
}
| defs_head[head] f_opt_paren_args[args] '=' endless_arg[bodystmt]
{
endless_method_name(p, $head->nd_mid, &@head);
restore_defun(p, $head);
$bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
($$ = $head->nd_def)->nd_loc = @$;
RNODE_DEFS($$)->nd_defn = $bodystmt;
/*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
/*% ripper: defs!(*$:head[0..2], $:args, $:$) %*/
local_pop(p);
}
| def_endless_method(endless_arg)
| primary
{
$$ = $1;