[前][次][番号順一覧][スレッド一覧]

ruby-changes:63446

From: Nobuyoshi <ko1@a...>
Date: Mon, 26 Oct 2020 22:24:14 +0900 (JST)
Subject: [ruby-changes:63446] bdd1d17ac2 (master): Allow non-argument endless-def with a space instead of parentheses

https://git.ruby-lang.org/ruby.git/commit/?id=bdd1d17ac2

From bdd1d17ac2c14ed937944860e1ec6b361a2fda6d Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 4 Sep 2020 11:11:36 +0900
Subject: Allow non-argument endless-def with a space instead of parentheses


diff --git a/parse.y b/parse.y
index 85cb671..256e991 100644
--- a/parse.y
+++ b/parse.y
@@ -1160,7 +1160,8 @@ static int looking_at_eol_p(struct parser_params *p); https://github.com/ruby/ruby/blob/trunk/parse.y#L1160
 %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 https://github.com/ruby/ruby/blob/trunk/parse.y#L2457
 		    /*% %*/
 		    /*% 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 https://github.com/ruby/ruby/blob/trunk/parse.y#L2468
 		    /*% 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 https://github.com/ruby/ruby/blob/trunk/parse.y#L2480
 		    /*% 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 https://github.com/ruby/ruby/blob/trunk/parse.y#L2492
 		    /*% 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	: '<' https://github.com/ruby/ruby/blob/trunk/parse.y#L4942
 		    }
 		;
 
+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 0a370d4..9f8c460 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -1424,10 +1424,10 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L1424
   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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]