aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-11 02:20:34 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-11 02:20:34 +0000
commit6123774c605af5956c204968490099e79f70f81c (patch)
tree8856429c7abcd1eb5d81fc1d1e3b70202d8a4465 /parse.y
parent3abd291326eeb856ff8100ad5d49a50b03d21205 (diff)
downloadruby-6123774c605af5956c204968490099e79f70f81c.tar.gz
parse.y: backref_assign_error
* parse.y (backref_assign_error): unify parser and ripper code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y55
1 files changed, 23 insertions, 32 deletions
diff --git a/parse.y b/parse.y
index 5857d155f9..d8e4d05a1d 100644
--- a/parse.y
+++ b/parse.y
@@ -492,6 +492,9 @@ static NODE *new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID
((in_def || in_single) ? yyerror("dynamic constant assignment") : (void)0), \
NEW_CDECL(0, 0, (path)))
+#define var_field(n) (n)
+#define backref_assign_error(n, a) (rb_backref_error(n), NEW_BEGIN(0))
+
static NODE *kwd_append(NODE*, NODE*);
static NODE *new_hash_gen(struct parser_params *parser, NODE *hash);
@@ -560,6 +563,10 @@ static VALUE new_attr_op_assign_gen(struct parser_params *parser, VALUE lhs, VAL
static VALUE const_decl_gen(struct parser_params *parser, VALUE path);
#define const_decl(path) const_decl_gen(parser, path)
+#define var_field(n) dispatch1(var_field, (n))
+static VALUE backref_assign_error_gen(struct parser_params *parser, VALUE a);
+#define backref_assign_error(n, a) backref_assign_error_gen(parser, (a))
+
static VALUE parser_reg_compile(struct parser_params*, VALUE, int, VALUE *);
#endif /* !RIPPER */
@@ -1325,14 +1332,8 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
}
| backref tOP_ASGN command_call
{
- /*%%%*/
- rb_backref_error($1);
- $$ = NEW_BEGIN(0);
- /*%
- $$ = dispatch2(assign, dispatch1(var_field, $1), $3);
- $$ = dispatch1(assign_error, $$);
- ripper_error();
- %*/
+ $1 = var_field($1);
+ $$ = backref_assign_error($1, node_assign($1, $3));
}
| lhs '=' mrhs
{
@@ -1795,14 +1796,8 @@ mlhs_node : user_variable
}
| backref
{
- /*%%%*/
- rb_backref_error($1);
- $$ = NEW_BEGIN(0);
- /*%
- $$ = dispatch1(var_field, $1);
- $$ = dispatch1(assign_error, $$);
- ripper_error();
- %*/
+ $1 = var_field($1);
+ $$ = backref_assign_error($1, $1);
}
;
@@ -1866,13 +1861,8 @@ lhs : user_variable
}
| backref
{
- /*%%%*/
- rb_backref_error($1);
- $$ = NEW_BEGIN(0);
- /*%
- $$ = dispatch1(assign_error, $1);
- ripper_error();
- %*/
+ $1 = var_field($1);
+ $$ = backref_assign_error($1, $1);
}
;
@@ -2073,15 +2063,8 @@ arg : lhs '=' arg_rhs
}
| backref tOP_ASGN arg
{
- /*%%%*/
- rb_backref_error($1);
- $$ = NEW_BEGIN(0);
- /*%
- $$ = dispatch1(var_field, $1);
- $$ = dispatch3(opassign, $$, $2, $3);
- $$ = dispatch1(assign_error, $$);
- ripper_error();
- %*/
+ $1 = var_field($1);
+ $$ = backref_assign_error($1, new_op_assign($1, $2, $3));
}
| arg tDOT2 arg
{
@@ -10279,6 +10262,14 @@ const_decl_gen(struct parser_params *parser, VALUE path)
}
return path;
}
+
+static VALUE
+backref_assign_error_gen(struct parser_params *parser, VALUE a)
+{
+ a = dispatch1(assign_error, a);
+ ripper_error();
+ return a;
+}
#endif
static void