diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-24 15:59:31 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-24 15:59:31 +0000 |
commit | 7ea675732ac1dac72f07756498706678d8725719 (patch) | |
tree | e6a405332d045f861a5ec13e253bdcfc56ffbf5c /parse.y | |
parent | d2fa4d7118b4b064cd84a7b1dbf37ae0ff6c1883 (diff) | |
download | ruby-7ea675732ac1dac72f07756498706678d8725719.tar.gz |
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.y | 38 |
1 files changed, 29 insertions, 9 deletions
@@ -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) |