From c501345218dc5fb0fae90d56a0c6fd19d38df5bb Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 19 Apr 2014 06:38:31 +0000 Subject: [PATCH] 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ parse.y | 12 +++++++++--- test/ruby/test_syntax.rb | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index aa2e76a7f4..b204dd8f8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat Apr 19 15:38:29 2014 Nobuyoshi Nakada + + * 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 * internal.h (struct RBignum): Use size_t for len. diff --git a/parse.y b/parse.y index 5b90bd2909..726f89130b 100644 --- a/parse.y +++ b/parse.y @@ -2620,12 +2620,18 @@ primary : literal $$ = dispatch1(paren, 0); %*/ } - | tLPAREN_ARG expr {lex_state = EXPR_ENDARG;} rparen + | tLPAREN_ARG { + $1 = cmdarg_stack; + cmdarg_stack = 0; + } + expr {lex_state = EXPR_ENDARG;} rparen + { + cmdarg_stack = $1; /*%%%*/ - $$ = $2; + $$ = $3; /*% - $$ = dispatch1(paren, $2); + $$ = dispatch1(paren, $3); %*/ } | tLPAREN compstmt ')' diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index bc1d80f990..0847c28bfc 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -78,6 +78,11 @@ class TestSyntax < Test::Unit::TestCase 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)