summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorydah <t.yudai92@gmail.com>2025-01-02 01:23:26 +0900
committerYudai Takada <t.yudai92@gmail.com>2025-01-04 18:58:44 +0900
commit2efa78099cabbf40e0c974a047605ca0bfc09fc6 (patch)
treef7f528942d0c3f745368f4403b550b6a6e928d76
parent4fa68953fbf1e2cec9b8650a5a25b4b6bfe0e331 (diff)
Use user defined parameterizing rules `def_endless_method(bodystmt)`
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12494
-rw-r--r--parse.y71
1 files changed, 27 insertions, 44 deletions
diff --git a/parse.y b/parse.y
index ff9a1ed2d6..0fe92d3cfa 100644
--- a/parse.y
+++ b/parse.y
@@ -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;