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 command_rhs arg_rhs %type command_asgn mrhs mrhs_arg superclass block_call block_command %type f_block_optarg f_block_opt -%type 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 f_arglist f_opt_paren_args f_paren_args f_args f_arg f_arg_item +%type f_optarg f_marg f_marg_list f_margs f_rest_marg %type assoc_list assocs assoc undef_list backref string_dvar for_var %type block_param opt_block_param block_param_def f_opt %type 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, $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, $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, $1, &@1); restore_defun(p, $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, $1, &@1); restore_defun(p, $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