aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-12 04:20:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-12 04:20:35 +0000
commitfebbdffea55458cd2173c0e021bec295b8f45f00 (patch)
treefc55a73a8ffa4d97e2c4cbe2ba3ce4680c9ad076 /parse.y
parent0e48697a3889103878c6142cb2297f7da43eaae4 (diff)
downloadruby-febbdffea55458cd2173c0e021bec295b8f45f00.tar.gz
parse.y: call_uni_op
* defs/id.def (predefined): add keyword `not`. * parse.y (call_uni_op): unify parser and ripper, and use IDs instead of tokens. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y52
1 files changed, 15 insertions, 37 deletions
diff --git a/parse.y b/parse.y
index 653e444af9..3f431018c1 100644
--- a/parse.y
+++ b/parse.y
@@ -405,6 +405,7 @@ static NODE* node_newnode(struct parser_params *, enum node_type, VALUE, VALUE,
static NODE *cond_gen(struct parser_params*,NODE*,int);
#define cond(node) cond_gen(parser, (node), FALSE)
#define method_cond(node) cond_gen(parser, (node), TRUE)
+#define new_nil() NEW_NIL()
static NODE *new_if_gen(struct parser_params*,NODE*,NODE*,NODE*);
#define new_if(cc,left,right) new_if_gen(parser, (cc), (left), (right))
#define new_unless(cc,left,right) new_if_gen(parser, (cc), (right), (left))
@@ -560,8 +561,11 @@ static VALUE assignable_gen(struct parser_params*,VALUE);
static int id_is_var_gen(struct parser_params *parser, ID id);
#define id_is_var(id) id_is_var_gen(parser, (id))
+#define method_cond(node) (node)
+#define call_uni_op(recv,id) dispatch2(unary, STATIC_ID2SYM(id), (recv))
#define node_assign(node1, node2) dispatch2(assign, (node1), (node2))
+#define new_nil() Qnil
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))
@@ -633,6 +637,12 @@ static int dvar_curr_gen(struct parser_params*,ID);
static int lvar_defined_gen(struct parser_params*, ID);
#define lvar_defined(id) lvar_defined_gen(parser, (id))
+#ifdef RIPPER
+# define METHOD_NOT idNOT
+#else
+# define METHOD_NOT '!'
+#endif
+
#define RE_OPTION_ONCE (1<<16)
#define RE_OPTION_ENCODING_SHIFT 8
#define RE_OPTION_ENCODING(e) (((e)&0xff)<<RE_OPTION_ENCODING_SHIFT)
@@ -1425,19 +1435,11 @@ expr : command_call
}
| keyword_not opt_nl expr
{
- /*%%%*/
- $$ = call_uni_op(method_cond($3), '!');
- /*%
- $$ = dispatch2(unary, ripper_intern("not"), $3);
- %*/
+ $$ = call_uni_op(method_cond($3), METHOD_NOT);
}
| '!' command_call
{
- /*%%%*/
$$ = call_uni_op(method_cond($2), '!');
- /*%
- $$ = dispatch2(unary, TOKEN2VAL('!'), $2);
- %*/
}
| arg
;
@@ -2158,19 +2160,11 @@ arg : lhs '=' arg_rhs
}
| tUPLUS arg
{
- /*%%%*/
- $$ = call_uni_op($2, tUPLUS);
- /*%
- $$ = dispatch2(unary, TOKEN2VAL(tUPLUS), $2);
- %*/
+ $$ = call_uni_op($2, idUPlus);
}
| tUMINUS arg
{
- /*%%%*/
- $$ = call_uni_op($2, tUMINUS);
- /*%
- $$ = dispatch2(unary, TOKEN2VAL(tUMINUS), $2);
- %*/
+ $$ = call_uni_op($2, idUMinus);
}
| arg '|' arg
{
@@ -2278,19 +2272,11 @@ arg : lhs '=' arg_rhs
}
| '!' arg
{
- /*%%%*/
$$ = call_uni_op(method_cond($2), '!');
- /*%
- $$ = dispatch2(unary, TOKEN2VAL('!'), $2);
- %*/
}
| '~' arg
{
- /*%%%*/
$$ = call_uni_op($2, '~');
- /*%
- $$ = dispatch2(unary, TOKEN2VAL('~'), $2);
- %*/
}
| arg tLSHFT arg
{
@@ -2763,19 +2749,11 @@ primary : literal
}
| keyword_not '(' expr rparen
{
- /*%%%*/
- $$ = call_uni_op(method_cond($3), '!');
- /*%
- $$ = dispatch2(unary, ripper_intern("not"), $3);
- %*/
+ $$ = call_uni_op(method_cond($3), METHOD_NOT);
}
| keyword_not '(' rparen
{
- /*%%%*/
- $$ = call_uni_op(method_cond(NEW_NIL()), '!');
- /*%
- $$ = dispatch2(unary, ripper_intern("not"), Qnil);
- %*/
+ $$ = call_uni_op(method_cond(new_nil()), METHOD_NOT);
}
| fcall brace_block
{