diff options
| author | ydah <t.yudai92@gmail.com> | 2025-01-02 01:23:26 +0900 |
|---|---|---|
| committer | Yudai Takada <t.yudai92@gmail.com> | 2025-01-04 18:58:44 +0900 |
| commit | 2efa78099cabbf40e0c974a047605ca0bfc09fc6 (patch) | |
| tree | f7f528942d0c3f745368f4403b550b6a6e928d76 /parse.y | |
| parent | 4fa68953fbf1e2cec9b8650a5a25b4b6bfe0e331 (diff) | |
Use user defined parameterizing rules `def_endless_method(bodystmt)`
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12494
Diffstat (limited to 'parse.y')
| -rw-r--r-- | parse.y | 71 |
1 files changed, 27 insertions, 44 deletions
@@ -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; |
