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

ruby-changes:33556

From: nobu <ko1@a...>
Date: Sat, 19 Apr 2014 15:38:36 +0900 (JST)
Subject: [ruby-changes:33556] nobu:r45637 (trunk): parse.y: allow parenthesed do-block in cmdarg

nobu	2014-04-19 15:38:31 +0900 (Sat, 19 Apr 2014)

  New Revision: 45637

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45637

  Log:
    parse.y: allow parenthesed do-block in cmdarg
    
    * parse.y (primary): flush cmdarg flags inside left-paren in a
      command argument, to allow parenthesed do-block as an argument
      without arguments parentheses.  [ruby-core:61950] [Bug #9726]

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_syntax.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45636)
+++ ChangeLog	(revision 45637)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 19 15:38:29 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (primary): flush cmdarg flags inside left-paren in a
+	  command argument, to allow parenthesed do-block as an argument
+	  without arguments parentheses.  [ruby-core:61950] [Bug #9726]
+
 Sat Apr 19 10:07:24 2014  Tanaka Akira  <akr@f...>
 
 	* internal.h (struct RBignum): Use size_t for len.
Index: parse.y
===================================================================
--- parse.y	(revision 45636)
+++ parse.y	(revision 45637)
@@ -2620,12 +2620,18 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2620
 			$$ = dispatch1(paren, 0);
 		    %*/
 		    }
-		| tLPAREN_ARG expr {lex_state = EXPR_ENDARG;} rparen
+		| tLPAREN_ARG
 		    {
+			$<val>1 = cmdarg_stack;
+			cmdarg_stack = 0;
+		    }
+		  expr {lex_state = EXPR_ENDARG;} rparen
+		    {
+			cmdarg_stack = $<val>1;
 		    /*%%%*/
-			$$ = $2;
+			$$ = $3;
 		    /*%
-			$$ = dispatch1(paren, $2);
+			$$ = dispatch1(paren, $3);
 		    %*/
 		    }
 		| tLPAREN compstmt ')'
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 45636)
+++ test/ruby/test_syntax.rb	(revision 45637)
@@ -78,6 +78,11 @@ class TestSyntax < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L78
     end
   end
 
+  def test_do_block_in_cmdarg
+    bug9726 = '[ruby-core:61950] [Bug #9726]'
+    assert_valid_syntax("tap (proc do end)", __FILE__, bug9726)
+  end
+
   def test_keyword_rest
     bug5989 = '[ruby-core:42455]'
     assert_valid_syntax("def kwrest_test(**a) a; end", __FILE__, bug5989)

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

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