summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-09-04 11:11:36 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-10-26 21:15:16 +0900
commitbdd1d17ac2c14ed937944860e1ec6b361a2fda6d (patch)
tree69ea74bcb10e2da27eea3b2ee60c36e26e27bdd7
parent69837229d74813c807e9d079aaee33aec2c7a4d0 (diff)
Allow non-argument endless-def with a space instead of parentheses
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3704
-rw-r--r--parse.y13
-rw-r--r--test/ruby/test_syntax.rb4
2 files changed, 10 insertions, 7 deletions
diff --git a/parse.y b/parse.y
index 85cb671d44..256e9915ad 100644
--- a/parse.y
+++ b/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
{
/*%%%*/
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index 0a370d416d..9f8c4600c6 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -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