ruby-changes:43815
From: nobu <ko1@a...>
Date: Sat, 13 Aug 2016 11:10:16 +0900 (JST)
Subject: [ruby-changes:43815] nobu:r55888 (trunk): parse.y: chained assignments
nobu 2016-08-13 11:10:11 +0900 (Sat, 13 Aug 2016) New Revision: 55888 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55888 Log: parse.y: chained assignments * parse.y (command_asgn, arg): fix syntax errors with chained assignment with op assign. [Bug #12669] Modified files: trunk/ChangeLog trunk/parse.y trunk/test/ruby/test_assignment.rb Index: test/ruby/test_assignment.rb =================================================================== --- test/ruby/test_assignment.rb (revision 55887) +++ test/ruby/test_assignment.rb (revision 55888) @@ -771,4 +771,14 @@ class TestAssignmentGen < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/ruby/test_assignment.rb#L771 h[*k], = ["ok", "ng"] assert_equal("ok", h[:key], bug11970) end + + def test_chainged_assign_command + all_assertions do |a| + asgn = %w'= +=' + asgn.product(asgn) do |a1, a2| + stmt = "a #{a1} b #{a2} raise 'x'" + a.for(stmt) {assert_valid_syntax(stmt)} + end + end + end end Index: parse.y =================================================================== --- parse.y (revision 55887) +++ parse.y (revision 55888) @@ -1284,6 +1284,28 @@ stmt : keyword_alias fitem {SET_LEX_STA https://github.com/ruby/ruby/blob/trunk/parse.y#L1284 $$ = dispatch2(massign, $1, $3); %*/ } + | lhs '=' mrhs + { + value_expr($3); + $$ = node_assign($1, $3); + } + | mlhs '=' mrhs_arg + { + /*%%%*/ + $1->nd_value = $3; + $$ = $1; + /*% + $$ = dispatch2(massign, $1, $3); + %*/ + } + | expr + ; + +command_asgn : lhs '=' command_rhs + { + value_expr($3); + $$ = node_assign($1, $3); + } | var_lhs tOP_ASGN command_rhs { value_expr($3); @@ -1335,28 +1357,6 @@ stmt : keyword_alias fitem {SET_LEX_STA https://github.com/ruby/ruby/blob/trunk/parse.y#L1357 $1 = var_field($1); $$ = backref_assign_error($1, node_assign($1, $3)); } - | lhs '=' mrhs - { - value_expr($3); - $$ = node_assign($1, $3); - } - | mlhs '=' mrhs_arg - { - /*%%%*/ - $1->nd_value = $3; - $$ = $1; - /*% - $$ = dispatch2(massign, $1, $3); - %*/ - } - | expr - ; - -command_asgn : lhs '=' command_rhs - { - value_expr($3); - $$ = node_assign($1, $3); - } ; command_rhs : command_call %prec tOP_ASGN Index: ChangeLog =================================================================== --- ChangeLog (revision 55887) +++ ChangeLog (revision 55888) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Aug 13 11:10:08 2016 Nobuyoshi Nakada <nobu@r...> + + * parse.y (command_asgn, arg): fix syntax errors with chained + assignment with op assign. [Bug #12669] + Sat Aug 13 10:52:19 2016 Nobuyoshi Nakada <nobu@r...> * parse.y (stmt, arg): rescue modifier in command op assignment -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/