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) + : 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) : 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;