aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-13 02:10:11 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-13 02:10:11 +0000
commit2e0d97cb7a33844347de6dc494c715e585d17701 (patch)
treec7d67b9dc63c2534b4f02c5f09fef482de30733c
parenta4de31c32205e4cff9ecaa1d896a5dedfcfd5560 (diff)
downloadruby-2e0d97cb7a33844347de6dc494c715e585d17701.tar.gz
parse.y: chained assignments
* parse.y (command_asgn, arg): fix syntax errors with chained assignment with op assign. [Bug #12669] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--parse.y44
-rw-r--r--test/ruby/test_assignment.rb10
3 files changed, 37 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index 01a0bc4063..328319aadd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Aug 13 11:10:08 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* parse.y (stmt, arg): rescue modifier in command op assignment
diff --git a/parse.y b/parse.y
index 41a164c02a..17f0f9c50a 100644
--- a/parse.y
+++ b/parse.y
@@ -1284,6 +1284,28 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
$$ = 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_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
$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
diff --git a/test/ruby/test_assignment.rb b/test/ruby/test_assignment.rb
index 41c14d3a44..45c4d6e058 100644
--- a/test/ruby/test_assignment.rb
+++ b/test/ruby/test_assignment.rb
@@ -771,4 +771,14 @@ class TestAssignmentGen < Test::Unit::TestCase
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