mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Allow non-argument endless-def with a space instead of parentheses
This commit is contained in:
parent
69837229d7
commit
bdd1d17ac2
Notes:
git
2020-10-26 22:24:17 +09:00
2 changed files with 10 additions and 7 deletions
13
parse.y
13
parse.y
|
@ -1160,7 +1160,8 @@ static int looking_at_eol_p(struct parser_params *p);
|
|||
%type <node> command_rhs arg_rhs
|
||||
%type <node> command_asgn mrhs mrhs_arg superclass block_call block_command
|
||||
%type <node> f_block_optarg f_block_opt
|
||||
%type <node> f_arglist f_paren_args f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs f_rest_marg
|
||||
%type <node> f_arglist f_opt_paren_args f_paren_args f_args f_arg f_arg_item
|
||||
%type <node> f_optarg f_marg f_marg_list f_margs f_rest_marg
|
||||
%type <node> assoc_list assocs assoc undef_list backref string_dvar for_var
|
||||
%type <node> block_param opt_block_param block_param_def f_opt
|
||||
%type <node> f_kwarg f_kw f_block_kwarg f_block_kw
|
||||
|
@ -2456,7 +2457,7 @@ arg : lhs '=' arg_rhs
|
|||
/*% %*/
|
||||
/*% ripper: ifop!($1, $3, $6) %*/
|
||||
}
|
||||
| defn_head f_paren_args '=' arg
|
||||
| defn_head f_opt_paren_args '=' arg
|
||||
{
|
||||
endless_method_name(p, $<node>1, &@1);
|
||||
token_info_drop(p, "def", @1.beg_pos);
|
||||
|
@ -2467,7 +2468,7 @@ arg : lhs '=' arg_rhs
|
|||
/*% ripper: def!(get_value($1), $2, $4) %*/
|
||||
local_pop(p);
|
||||
}
|
||||
| defn_head f_paren_args '=' arg modifier_rescue arg
|
||||
| defn_head f_opt_paren_args '=' arg modifier_rescue arg
|
||||
{
|
||||
endless_method_name(p, $<node>1, &@1);
|
||||
token_info_drop(p, "def", @1.beg_pos);
|
||||
|
@ -2479,7 +2480,7 @@ arg : lhs '=' arg_rhs
|
|||
/*% ripper: def!(get_value($1), $2, rescue_mod!($4, $6)) %*/
|
||||
local_pop(p);
|
||||
}
|
||||
| defs_head f_paren_args '=' arg
|
||||
| defs_head f_opt_paren_args '=' arg
|
||||
{
|
||||
endless_method_name(p, $<node>1, &@1);
|
||||
restore_defun(p, $<node>1->nd_defn);
|
||||
|
@ -2491,7 +2492,7 @@ arg : lhs '=' arg_rhs
|
|||
/*% ripper: defs!(AREF($1, 0), AREF($1, 1), AREF($1, 2), $2, $4) %*/
|
||||
local_pop(p);
|
||||
}
|
||||
| defs_head f_paren_args '=' arg modifier_rescue arg
|
||||
| defs_head f_opt_paren_args '=' arg modifier_rescue arg
|
||||
{
|
||||
endless_method_name(p, $<node>1, &@1);
|
||||
restore_defun(p, $<node>1->nd_defn);
|
||||
|
@ -4941,6 +4942,8 @@ superclass : '<'
|
|||
}
|
||||
;
|
||||
|
||||
f_opt_paren_args: f_paren_args | none;
|
||||
|
||||
f_paren_args : '(' f_args rparen
|
||||
{
|
||||
/*%%%*/
|
||||
|
|
|
@ -1424,10 +1424,10 @@ eom
|
|||
end
|
||||
|
||||
def test_methoddef_endless
|
||||
assert_syntax_error('private def foo = 42', /unexpected '='/)
|
||||
assert_valid_syntax('private def foo = 42')
|
||||
assert_valid_syntax('private def foo() = 42')
|
||||
assert_valid_syntax('private def inc(x) = x + 1')
|
||||
assert_syntax_error('private def obj.foo = 42', /unexpected '='/)
|
||||
assert_valid_syntax('private def obj.foo = 42')
|
||||
assert_valid_syntax('private def obj.foo() = 42')
|
||||
assert_valid_syntax('private def obj.inc(x) = x + 1')
|
||||
k = Class.new do
|
||||
|
|
Loading…
Add table
Reference in a new issue