mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
b2345fece0
commit
2c51dc5053
2 changed files with 10 additions and 21 deletions
|
@ -44,6 +44,8 @@ firstline, predefined = __LINE__+1, %[\
|
||||||
mesg
|
mesg
|
||||||
exception
|
exception
|
||||||
not NOT
|
not NOT
|
||||||
|
and AND
|
||||||
|
or OR
|
||||||
|
|
||||||
_ UScore
|
_ UScore
|
||||||
"/*NULL*/" NULL
|
"/*NULL*/" NULL
|
||||||
|
|
29
parse.y
29
parse.y
|
@ -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_if(cc,left,right) new_if_gen(parser, (cc), (left), (right))
|
||||||
#define new_unless(cc,left,right) new_if_gen(parser, (cc), (right), (left))
|
#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*);
|
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 NODE *newline_node(NODE*);
|
||||||
static void fixpos(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 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 match_op(node1,node2) call_bin_op((node1), idEqTilde, (node2))
|
||||||
#define call_uni_op(recv,id) dispatch2(unary, STATIC_ID2SYM(id), (recv))
|
#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 node_assign(node1, node2) dispatch2(assign, (node1), (node2))
|
||||||
|
|
||||||
#define new_nil() Qnil
|
#define new_nil() Qnil
|
||||||
|
@ -1421,19 +1424,11 @@ command_rhs : command_call %prec tOP_ASGN
|
||||||
expr : command_call
|
expr : command_call
|
||||||
| expr keyword_and expr
|
| expr keyword_and expr
|
||||||
{
|
{
|
||||||
/*%%%*/
|
$$ = logop(tAND, $1, $3);
|
||||||
$$ = logop(NODE_AND, $1, $3);
|
|
||||||
/*%
|
|
||||||
$$ = dispatch3(binary, $1, ripper_intern("and"), $3);
|
|
||||||
%*/
|
|
||||||
}
|
}
|
||||||
| expr keyword_or expr
|
| expr keyword_or expr
|
||||||
{
|
{
|
||||||
/*%%%*/
|
$$ = logop(tOR, $1, $3);
|
||||||
$$ = logop(NODE_OR, $1, $3);
|
|
||||||
/*%
|
|
||||||
$$ = dispatch3(binary, $1, ripper_intern("or"), $3);
|
|
||||||
%*/
|
|
||||||
}
|
}
|
||||||
| keyword_not opt_nl expr
|
| keyword_not opt_nl expr
|
||||||
{
|
{
|
||||||
|
@ -2209,19 +2204,11 @@ arg : lhs '=' arg_rhs
|
||||||
}
|
}
|
||||||
| arg tANDOP arg
|
| arg tANDOP arg
|
||||||
{
|
{
|
||||||
/*%%%*/
|
$$ = logop(tANDOP, $1, $3);
|
||||||
$$ = logop(NODE_AND, $1, $3);
|
|
||||||
/*%
|
|
||||||
$$ = dispatch3(binary, $1, TOKEN2VAL(tANDOP), $3);
|
|
||||||
%*/
|
|
||||||
}
|
}
|
||||||
| arg tOROP arg
|
| arg tOROP arg
|
||||||
{
|
{
|
||||||
/*%%%*/
|
$$ = logop(tOROP, $1, $3);
|
||||||
$$ = logop(NODE_OR, $1, $3);
|
|
||||||
/*%
|
|
||||||
$$ = dispatch3(binary, $1, TOKEN2VAL(tOROP), $3);
|
|
||||||
%*/
|
|
||||||
}
|
}
|
||||||
| keyword_defined opt_nl {in_defined = 1;} arg
|
| keyword_defined opt_nl {in_defined = 1;} arg
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue