summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-08 03:22:13 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-08 03:22:13 +0000
commitfbb5a9d967bb0e8b451f26d45dbd2eff8ab6b050 (patch)
tree45ceaa96817f3a6305af4908f8b7143e4d51e70b /parse.y
parent8ef39549c229ced92a9a340a5716e1f133fa26b6 (diff)
parse.y: Factor out special handling of a short-cut operator id
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y30
1 files changed, 9 insertions, 21 deletions
diff --git a/parse.y b/parse.y
index 784a4a82aa..c00c47cb73 100644
--- a/parse.y
+++ b/parse.y
@@ -495,6 +495,12 @@ static NODE *new_attr_op_assign_gen(struct parser_params *parser, NODE *lhs, ID
#define new_attr_op_assign(lhs, type, attr, op, rhs, location) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs), (location))
static NODE *new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs, const YYLTYPE *location);
#define new_const_op_assign(lhs, op, rhs, location) new_const_op_assign_gen(parser, (lhs), (op), (rhs), (location))
+static ID change_shortcut_operator_id(ID id)
+{
+ if (id == tOROP) return 0;
+ if (id == tANDOP) return 1;
+ return id;
+}
static NODE *const_path_field_gen(struct parser_params *parser, NODE *head, ID mid, const YYLTYPE *location);
#define const_path_field(w, n, location) const_path_field_gen(parser, w, n, location)
@@ -2108,13 +2114,7 @@ arg : lhs '=' arg_rhs
else {
args = arg_concat($3, $6, &@$);
}
- if ($5 == tOROP) {
- $5 = 0;
- }
- else if ($5 == tANDOP) {
- $5 = 1;
- }
- $$ = NEW_OP_ASGN1($1, $5, args, &@$);
+ $$ = NEW_OP_ASGN1($1, change_shortcut_operator_id($5), args, &@$);
fixpos($$, $1);
/*%
$1 = dispatch2(aref_field, $1, escape_Qundef($3));
@@ -10675,13 +10675,7 @@ new_attr_op_assign_gen(struct parser_params *parser, NODE *lhs,
{
NODE *asgn;
- if (op == tOROP) {
- op = 0;
- }
- else if (op == tANDOP) {
- op = 1;
- }
- asgn = NEW_OP_ASGN2(lhs, CALL_Q_P(atype), attr, op, rhs, location);
+ asgn = NEW_OP_ASGN2(lhs, CALL_Q_P(atype), attr, change_shortcut_operator_id(op), rhs, location);
fixpos(asgn, lhs);
return asgn;
}
@@ -10691,14 +10685,8 @@ new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rh
{
NODE *asgn;
- if (op == tOROP) {
- op = 0;
- }
- else if (op == tANDOP) {
- op = 1;
- }
if (lhs) {
- asgn = NEW_OP_CDECL(lhs, op, rhs, location);
+ asgn = NEW_OP_CDECL(lhs, change_shortcut_operator_id(op), rhs, location);
}
else {
asgn = NEW_BEGIN(0, location);