aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-11 02:12:57 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-11 02:12:57 +0000
commit3abd291326eeb856ff8100ad5d49a50b03d21205 (patch)
treed9fe81d1cadd421ad8389677312788ddc4a24850 /parse.y
parent39dcc209e22dd272ff6a4bb8dcca5c412e58a0d1 (diff)
downloadruby-3abd291326eeb856ff8100ad5d49a50b03d21205.tar.gz
parse.y: const declaration macro
* parse.y (const_decl): unify parser and ripper code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y63
1 files changed, 19 insertions, 44 deletions
diff --git a/parse.y b/parse.y
index c229e625dc..5857d155f9 100644
--- a/parse.y
+++ b/parse.y
@@ -488,6 +488,9 @@ static NODE *new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID
#define const_path_field(w, n) NEW_COLON2(w, n)
#define top_const_field(n) NEW_COLON3(n)
+#define const_decl(path) ( \
+ ((in_def || in_single) ? yyerror("dynamic constant assignment") : (void)0), \
+ NEW_CDECL(0, 0, (path)))
static NODE *kwd_append(NODE*, NODE*);
@@ -554,6 +557,8 @@ static VALUE new_attr_op_assign_gen(struct parser_params *parser, VALUE lhs, VAL
#define new_const_op_assign(lhs, op, rhs) new_op_assign(lhs, op, rhs)
#define const_path_field(w, n) dispatch2(const_path_field, (w), (n))
#define top_const_field(n) dispatch1(top_const_field, (n))
+static VALUE const_decl_gen(struct parser_params *parser, VALUE path);
+#define const_decl(path) const_decl_gen(parser, path)
static VALUE parser_reg_compile(struct parser_params*, VALUE, int, VALUE *);
@@ -1782,31 +1787,11 @@ mlhs_node : user_variable
}
| primary_value tCOLON2 tCONSTANT
{
- /*%%%*/
- if (in_def || in_single)
- yyerror("dynamic constant assignment");
- $$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
- /*%
- $$ = dispatch2(const_path_field, $1, $3);
- if (in_def || in_single) {
- $$ = dispatch1(assign_error, $$);
- ripper_error();
- }
- %*/
+ $$ = const_decl(const_path_field($1, $3));
}
| tCOLON3 tCONSTANT
{
- /*%%%*/
- if (in_def || in_single)
- yyerror("dynamic constant assignment");
- $$ = NEW_CDECL(0, 0, NEW_COLON3($2));
- /*%
- $$ = dispatch1(top_const_field, $2);
- if (in_def || in_single) {
- $$ = dispatch1(assign_error, $$);
- ripper_error();
- }
- %*/
+ $$ = const_decl(top_const_field($2));
}
| backref
{
@@ -1873,31 +1858,11 @@ lhs : user_variable
}
| primary_value tCOLON2 tCONSTANT
{
- /*%%%*/
- if (in_def || in_single)
- yyerror("dynamic constant assignment");
- $$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
- /*%
- $$ = dispatch2(const_path_field, $1, $3);
- if (in_def || in_single) {
- $$ = dispatch1(assign_error, $$);
- ripper_error();
- }
- %*/
+ $$ = const_decl(const_path_field($1, $3));
}
| tCOLON3 tCONSTANT
{
- /*%%%*/
- if (in_def || in_single)
- yyerror("dynamic constant assignment");
- $$ = NEW_CDECL(0, 0, NEW_COLON3($2));
- /*%
- $$ = dispatch1(top_const_field, $2);
- if (in_def || in_single) {
- $$ = dispatch1(assign_error, $$);
- ripper_error();
- }
- %*/
+ $$ = const_decl(top_const_field($2));
}
| backref
{
@@ -10304,6 +10269,16 @@ new_attr_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE type, VALU
VALUE recv = dispatch3(field, lhs, type, attr);
return dispatch3(opassign, recv, op, rhs);
}
+
+static VALUE
+const_decl_gen(struct parser_params *parser, VALUE path)
+{
+ if (in_def || in_single) {
+ dispatch1(assign_error, path);
+ ripper_error();
+ }
+ return path;
+}
#endif
static void