diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-02-12 08:33:33 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-02-12 08:33:33 +0000 |
commit | 2c51dc50534827c79c6b5d1febb54d130167ea25 (patch) | |
tree | 7f6e2156517dc23c4067acd3a87d5ca237cb78c4 /parse.y | |
parent | b2345fece09ac142e33063a0a87e4f379e68467c (diff) | |
download | ruby-2c51dc50534827c79c6b5d1febb54d130167ea25.tar.gz |
parse.y: logop
* defs/id.def (predefined): add keywords `and` and `or`.
* parse.y (log_op): unify parser and ripper, and use tokens
instead of node types and symbols.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 29 |
1 files changed, 8 insertions, 21 deletions
@@ -410,7 +410,9 @@ 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)) static NODE *logop_gen(struct parser_params*,enum node_type,NODE*,NODE*); -#define logop(type,node1,node2) logop_gen(parser, (type), (node1), (node2)) +#define logop(type,node1,node2) \ + logop_gen(parser, (type)==tAND||(type)==tANDOP?NODE_AND:NODE_OR, \ + (node1), (node2)) static NODE *newline_node(NODE*); static void fixpos(NODE*,NODE*); @@ -565,6 +567,7 @@ static int id_is_var_gen(struct parser_params *parser, ID id); #define call_bin_op(recv,id,arg1) dispatch3(binary, (recv), STATIC_ID2SYM(id), (arg1)) #define match_op(node1,node2) call_bin_op((node1), idEqTilde, (node2)) #define call_uni_op(recv,id) dispatch2(unary, STATIC_ID2SYM(id), (recv)) +#define logop(type,node1,node2) call_bin_op((node1), TOKEN2ID(type), (node2)) #define node_assign(node1, node2) dispatch2(assign, (node1), (node2)) #define new_nil() Qnil @@ -1421,19 +1424,11 @@ command_rhs : command_call %prec tOP_ASGN expr : command_call | expr keyword_and expr { - /*%%%*/ - $$ = logop(NODE_AND, $1, $3); - /*% - $$ = dispatch3(binary, $1, ripper_intern("and"), $3); - %*/ + $$ = logop(tAND, $1, $3); } | expr keyword_or expr { - /*%%%*/ - $$ = logop(NODE_OR, $1, $3); - /*% - $$ = dispatch3(binary, $1, ripper_intern("or"), $3); - %*/ + $$ = logop(tOR, $1, $3); } | keyword_not opt_nl expr { @@ -2209,19 +2204,11 @@ arg : lhs '=' arg_rhs } | arg tANDOP arg { - /*%%%*/ - $$ = logop(NODE_AND, $1, $3); - /*% - $$ = dispatch3(binary, $1, TOKEN2VAL(tANDOP), $3); - %*/ + $$ = logop(tANDOP, $1, $3); } | arg tOROP arg { - /*%%%*/ - $$ = logop(NODE_OR, $1, $3); - /*% - $$ = dispatch3(binary, $1, TOKEN2VAL(tOROP), $3); - %*/ + $$ = logop(tOROP, $1, $3); } | keyword_defined opt_nl {in_defined = 1;} arg { |