Feature #14799 ยป beginless-range.patch
defs/id.def | ||
---|---|---|
token_ops = %[\
|
||
Dot2 .. DOT2
|
||
Dot3 ... DOT3
|
||
BDot2 .. BDOT2
|
||
BDot3 ... BDOT3
|
||
UPlus +@ UPLUS
|
||
UMinus -@ UMINUS
|
||
Pow ** POW
|
parse.y | ||
---|---|---|
%token tNMATCH RUBY_TOKEN(NMATCH) "!~"
|
||
%token tDOT2 RUBY_TOKEN(DOT2) ".."
|
||
%token tDOT3 RUBY_TOKEN(DOT3) "..."
|
||
%token tBDOT2 RUBY_TOKEN(BDOT2) "(.."
|
||
%token tBDOT3 RUBY_TOKEN(BDOT3) "(..."
|
||
%token tAREF RUBY_TOKEN(AREF) "[]"
|
||
%token tASET RUBY_TOKEN(ASET) "[]="
|
||
%token tLSHFT RUBY_TOKEN(LSHFT) "<<"
|
||
... | ... | |
/*% %*/
|
||
/*% ripper: dot3!($1, Qnil) %*/
|
||
}
|
||
| tBDOT2 primary
|
||
{
|
||
/*%%%*/
|
||
YYLTYPE loc;
|
||
loc.beg_pos = @1.beg_pos;
|
||
loc.end_pos = @1.beg_pos;
|
||
value_expr($2);
|
||
$$ = NEW_DOT2(new_nil(&loc), $2, &@$);
|
||
/*% %*/
|
||
/*% ripper: dot2!(Qnil, $2) %*/
|
||
}
|
||
| tBDOT3 primary
|
||
{
|
||
/*%%%*/
|
||
YYLTYPE loc;
|
||
loc.beg_pos = @1.beg_pos;
|
||
loc.end_pos = @1.beg_pos;
|
||
value_expr($2);
|
||
$$ = NEW_DOT3(new_nil(&loc), $2, &@$);
|
||
/*% %*/
|
||
/*% ripper: dot3!(Qnil, $2) %*/
|
||
}
|
||
| arg '+' arg
|
||
{
|
||
$$ = call_bin_op(p, $1, '+', $3, &@2, &@$);
|
||
... | ... | |
return warn_balanced('-', "-", "unary operator");
|
||
case '.':
|
||
SET_LEX_STATE(EXPR_BEG);
|
||
if ((c = nextc(p)) == '.') {
|
||
int n;
|
||
if ((c = nextc(p)) == '.') {
|
||
return tDOT3;
|
||
n = IS_BEG() ? tBDOT3 : tDOT3;
|
||
SET_LEX_STATE(EXPR_BEG);
|
||
return n;
|
||
}
|
||
n = IS_BEG() ? tBDOT2 : tDOT2;
|
||
pushback(p, c);
|
||
return tDOT2;
|
||
SET_LEX_STATE(EXPR_BEG);
|
||
return n;
|
||
}
|
||
SET_LEX_STATE(EXPR_BEG);
|
||
pushback(p, c);
|
||
if (c != -1 && ISDIGIT(c)) {
|
||
yyerror0("no .<digit> floating literal anymore; put 0 before dot");
|
range.c | ||
---|---|---|
static void
|
||
range_init(VALUE range, VALUE beg, VALUE end, VALUE exclude_end)
|
||
{
|
||
if ((!FIXNUM_P(beg) || !FIXNUM_P(end)) && !NIL_P(end)) {
|
||
if ((!FIXNUM_P(beg) || !FIXNUM_P(end)) && !NIL_P(beg) && !NIL_P(end)) {
|
||
VALUE v;
|
||
v = rb_funcall(beg, id_cmp, 1, end);
|
||
... | ... | |
VALUE rb_str_include_range_p(VALUE beg, VALUE end, VALUE val, VALUE exclusive);
|
||
return rb_str_include_range_p(beg, end, val, RANGE_EXCL(range));
|
||
}
|
||
else if (NIL_P(beg)) {
|
||
VALUE r = rb_funcall(val, id_cmp, 1, end);
|
||
if (NIL_P(r)) return Qfalse;
|
||
if (rb_cmpint(r, val, end) <= 0) return Qtrue;
|
||
return Qfalse;
|
||
}
|
||
else if (NIL_P(end)) {
|
||
VALUE r = rb_funcall(beg, id_cmp, 1, val);
|
||
if (NIL_P(r)) return Qfalse;
|
||
... | ... | |
static VALUE
|
||
r_cover_p(VALUE range, VALUE beg, VALUE end, VALUE val)
|
||
{
|
||
if (r_less(beg, val) <= 0) {
|
||
if (NIL_P(beg) || r_less(beg, val) <= 0) {
|
||
int excl = EXCL(range);
|
||
if (NIL_P(end) || r_less(val, end) <= -excl)
|
||
return Qtrue;
|