From 7ea675732ac1dac72f07756498706678d8725719 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 24 Dec 2012 15:59:31 +0000 Subject: 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 --- parse.y | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'parse.y') 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) -- cgit v1.2.3