aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-11 01:24:24 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-11 01:24:24 +0000
commit39dcc209e22dd272ff6a4bb8dcca5c412e58a0d1 (patch)
tree981841f1a0c669e7d52fb57d99df6179ec6853f4 /parse.y
parent76f91539a2abbe53c8fe8f8a4124c3f40c994426 (diff)
downloadruby-39dcc209e22dd272ff6a4bb8dcca5c412e58a0d1.tar.gz
parse.y: const field macros
* parse.y (const_path_field, top_const_field): unify parser and ripper code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y29
1 files changed, 10 insertions, 19 deletions
diff --git a/parse.y b/parse.y
index 70d246a32c..c229e625dc 100644
--- a/parse.y
+++ b/parse.y
@@ -486,6 +486,9 @@ static NODE *new_attr_op_assign_gen(struct parser_params *parser, NODE *lhs, ID
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))
+#define const_path_field(w, n) NEW_COLON2(w, n)
+#define top_const_field(n) NEW_COLON3(n)
+
static NODE *kwd_append(NODE*, NODE*);
static NODE *new_hash_gen(struct parser_params *parser, NODE *hash);
@@ -515,7 +518,7 @@ static void parser_heredoc_dedent(struct parser_params*,NODE*);
#define get_id(id) (id)
#define get_value(val) (val)
-#else
+#else /* RIPPER */
#define NODE_RIPPER NODE_CDECL
static inline VALUE
@@ -548,6 +551,9 @@ static int id_is_var_gen(struct parser_params *parser, ID id);
static VALUE new_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE op, VALUE rhs);
static VALUE new_attr_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE type, VALUE attr, VALUE op, VALUE rhs);
#define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs))
+#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 parser_reg_compile(struct parser_params*, VALUE, int, VALUE *);
@@ -1304,13 +1310,8 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
}
| primary_value tCOLON2 tCONSTANT tOP_ASGN command_call
{
- /*%%%*/
- $$ = NEW_COLON2($1, $3);
+ $$ = const_path_field($1, $3);
$$ = new_const_op_assign($$, $4, $5);
- /*%
- $$ = dispatch2(const_path_field, $1, $3);
- $$ = dispatch3(opassign, $$, $4, $5);
- %*/
}
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
{
@@ -2097,23 +2098,13 @@ arg : lhs '=' arg_rhs
}
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg
{
- /*%%%*/
- $$ = NEW_COLON2($1, $3);
+ $$ = const_path_field($1, $3);
$$ = new_const_op_assign($$, $4, $5);
- /*%
- $$ = dispatch2(const_path_field, $1, $3);
- $$ = dispatch3(opassign, $$, $4, $5);
- %*/
}
| tCOLON3 tCONSTANT tOP_ASGN arg
{
- /*%%%*/
- $$ = NEW_COLON3($2);
+ $$ = top_const_field($2);
$$ = new_const_op_assign($$, $3, $4);
- /*%
- $$ = dispatch1(top_const_field, $2);
- $$ = dispatch3(opassign, $$, $3, $4);
- %*/
}
| backref tOP_ASGN arg
{