summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-24 15:59:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-24 15:59:31 +0000
commit7ea675732ac1dac72f07756498706678d8725719 (patch)
treee6a405332d045f861a5ec13e253bdcfc56ffbf5c /parse.y
parentd2fa4d7118b4b064cd84a7b1dbf37ae0ff6c1883 (diff)
scoped constant op-assignment
* node.h (NODE_OP_CDECL), compile.c (iseq_compile_each), parse.y (stmt, arg): allow scoped constant op-assignment. [ruby-core:40154] [Bug #5449] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38585 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y38
1 files changed, 29 insertions, 9 deletions
diff --git a/parse.y b/parse.y
index e42cd9e79f..2b119d465d 100644
--- a/parse.y
+++ b/parse.y
@@ -435,6 +435,8 @@ static NODE *node_assign_gen(struct parser_params*,NODE*,NODE*);
static NODE *new_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs);
static NODE *new_attr_op_assign_gen(struct parser_params *parser, NODE *lhs, ID attr, ID op, NODE *rhs);
#define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (attr), (op), (rhs))
+static NODE *new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs);
+#define new_const_op_assign(lhs, op, rhs) new_const_op_assign_gen(parser, (lhs), (op), (rhs))
static NODE *match_op_gen(struct parser_params*,NODE*,NODE*);
#define match_op(node1,node2) match_op_gen(parser, (node1), (node2))
@@ -1200,12 +1202,11 @@ stmt : keyword_alias fitem {lex_state = EXPR_FNAME;} fitem
| primary_value tCOLON2 tCONSTANT tOP_ASGN command_call
{
/*%%%*/
- yyerror("constant re-assignment");
- $$ = 0;
+ $$ = NEW_COLON2($1, $3);
+ $$ = new_const_op_assign($$, $4, $5);
/*%
$$ = dispatch2(const_path_field, $1, $3);
$$ = dispatch3(opassign, $$, $4, $5);
- $$ = dispatch1(assign_error, $$);
%*/
}
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
@@ -2007,23 +2008,21 @@ arg : lhs '=' arg
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg
{
/*%%%*/
- yyerror("constant re-assignment");
- $$ = NEW_BEGIN(0);
+ $$ = NEW_COLON2($1, $3);
+ $$ = new_const_op_assign($$, $4, $5);
/*%
$$ = dispatch2(const_path_field, $1, $3);
$$ = dispatch3(opassign, $$, $4, $5);
- $$ = dispatch1(assign_error, $$);
%*/
}
| tCOLON3 tCONSTANT tOP_ASGN arg
{
/*%%%*/
- yyerror("constant re-assignment");
- $$ = NEW_BEGIN(0);
+ $$ = NEW_COLON3($2);
+ $$ = new_const_op_assign($$, $3, $4);
/*%
$$ = dispatch1(top_const_field, $2);
$$ = dispatch3(opassign, $$, $3, $4);
- $$ = dispatch1(assign_error, $$);
%*/
}
| backref tOP_ASGN arg
@@ -9364,6 +9363,27 @@ new_attr_op_assign_gen(struct parser_params *parser, NODE *lhs, ID attr, ID op,
fixpos(asgn, lhs);
return asgn;
}
+
+static NODE *
+new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs)
+{
+ NODE *asgn;
+
+ if (op == tOROP) {
+ op = 0;
+ }
+ else if (op == tANDOP) {
+ op = 1;
+ }
+ if (lhs) {
+ asgn = NEW_OP_CDECL(lhs, op, rhs);
+ }
+ else {
+ asgn = NEW_BEGIN(0);
+ }
+ fixpos(asgn, lhs);
+ return asgn;
+}
#else
static VALUE
new_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE op, VALUE rhs)