ruby-changes:45537
From: nobu <ko1@a...>
Date: Sun, 12 Feb 2017 17:33:40 +0900 (JST)
Subject: [ruby-changes:45537] nobu:r57610 (trunk): parse.y: logop
nobu 2017-02-12 17:33:33 +0900 (Sun, 12 Feb 2017) New Revision: 57610 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57610 Log: 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. Modified files: trunk/defs/id.def trunk/parse.y Index: defs/id.def =================================================================== --- defs/id.def (revision 57609) +++ defs/id.def (revision 57610) @@ -44,6 +44,8 @@ firstline, predefined = __LINE__+1, %[\ https://github.com/ruby/ruby/blob/trunk/defs/id.def#L44 mesg exception not NOT + and AND + or OR _ UScore "/*NULL*/" NULL Index: parse.y =================================================================== --- parse.y (revision 57609) +++ parse.y (revision 57610) @@ -410,7 +410,9 @@ static NODE *new_if_gen(struct parser_pa https://github.com/ruby/ruby/blob/trunk/parse.y#L410 #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_p https://github.com/ruby/ruby/blob/trunk/parse.y#L567 #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_A https://github.com/ruby/ruby/blob/trunk/parse.y#L1424 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 https://github.com/ruby/ruby/blob/trunk/parse.y#L2204 } | 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 { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/