Project

General

Profile

Feature #14799 ยป beginless-range.patch

mame (Yusuke Endoh), 05/31/2018 11:33 AM

View differences:

defs/id.def
78 78
token_ops = %[\
79 79
  Dot2          ..      DOT2
80 80
  Dot3          ...     DOT3
81
  BDot2         ..      BDOT2
82
  BDot3         ...     BDOT3
81 83
  UPlus         +@      UPLUS
82 84
  UMinus        -@      UMINUS
83 85
  Pow           **      POW
parse.y
862 862
%token tNMATCH		RUBY_TOKEN(NMATCH) "!~"
863 863
%token tDOT2		RUBY_TOKEN(DOT2)   ".."
864 864
%token tDOT3		RUBY_TOKEN(DOT3)   "..."
865
%token tBDOT2		RUBY_TOKEN(BDOT2)   "(.."
866
%token tBDOT3		RUBY_TOKEN(BDOT3)   "(..."
865 867
%token tAREF		RUBY_TOKEN(AREF)   "[]"
866 868
%token tASET		RUBY_TOKEN(ASET)   "[]="
867 869
%token tLSHFT		RUBY_TOKEN(LSHFT)  "<<"
......
1930 1932
		    /*% %*/
1931 1933
		    /*% ripper: dot3!($1, Qnil) %*/
1932 1934
		    }
1935
		| tBDOT2 primary
1936
		    {
1937
		    /*%%%*/
1938
                        YYLTYPE loc;
1939
                        loc.beg_pos = @1.beg_pos;
1940
                        loc.end_pos = @1.beg_pos;
1941

  
1942
			value_expr($2);
1943
			$$ = NEW_DOT2(new_nil(&loc), $2, &@$);
1944
		    /*% %*/
1945
		    /*% ripper: dot2!(Qnil, $2) %*/
1946
		    }
1947
		| tBDOT3 primary
1948
		    {
1949
		    /*%%%*/
1950
                        YYLTYPE loc;
1951
                        loc.beg_pos = @1.beg_pos;
1952
                        loc.end_pos = @1.beg_pos;
1953

  
1954
			value_expr($2);
1955
			$$ = NEW_DOT3(new_nil(&loc), $2, &@$);
1956
		    /*% %*/
1957
		    /*% ripper: dot3!(Qnil, $2) %*/
1958
		    }
1933 1959
		| arg '+' arg
1934 1960
		    {
1935 1961
			$$ = call_bin_op(p, $1, '+', $3, &@2, &@$);
......
8021 8047
	return warn_balanced('-', "-", "unary operator");
8022 8048

  
8023 8049
      case '.':
8024
	SET_LEX_STATE(EXPR_BEG);
8025 8050
	if ((c = nextc(p)) == '.') {
8051
	    int n;
8026 8052
	    if ((c = nextc(p)) == '.') {
8027
		return tDOT3;
8053
		n = IS_BEG() ? tBDOT3 : tDOT3;
8054
		SET_LEX_STATE(EXPR_BEG);
8055
		return n;
8028 8056
	    }
8057
	    n = IS_BEG() ? tBDOT2 : tDOT2;
8029 8058
	    pushback(p, c);
8030
	    return tDOT2;
8059
	    SET_LEX_STATE(EXPR_BEG);
8060
	    return n;
8031 8061
	}
8062
	SET_LEX_STATE(EXPR_BEG);
8032 8063
	pushback(p, c);
8033 8064
	if (c != -1 && ISDIGIT(c)) {
8034 8065
	    yyerror0("no .<digit> floating literal anymore; put 0 before dot");
range.c
37 37
static void
38 38
range_init(VALUE range, VALUE beg, VALUE end, VALUE exclude_end)
39 39
{
40
    if ((!FIXNUM_P(beg) || !FIXNUM_P(end)) && !NIL_P(end)) {
40
    if ((!FIXNUM_P(beg) || !FIXNUM_P(end)) && !NIL_P(beg) && !NIL_P(end)) {
41 41
	VALUE v;
42 42

  
43 43
	v = rb_funcall(beg, id_cmp, 1, end);
......
1282 1282
	    VALUE rb_str_include_range_p(VALUE beg, VALUE end, VALUE val, VALUE exclusive);
1283 1283
	    return rb_str_include_range_p(beg, end, val, RANGE_EXCL(range));
1284 1284
	}
1285
        else if (NIL_P(beg)) {
1286
	    VALUE r = rb_funcall(val, id_cmp, 1, end);
1287
	    if (NIL_P(r)) return Qfalse;
1288
	    if (rb_cmpint(r, val, end) <= 0) return Qtrue;
1289
	    return Qfalse;
1290
        }
1285 1291
	else if (NIL_P(end)) {
1286 1292
	    VALUE r = rb_funcall(beg, id_cmp, 1, val);
1287 1293
	    if (NIL_P(r)) return Qfalse;
......
1321 1327
static VALUE
1322 1328
r_cover_p(VALUE range, VALUE beg, VALUE end, VALUE val)
1323 1329
{
1324
    if (r_less(beg, val) <= 0) {
1330
    if (NIL_P(beg) || r_less(beg, val) <= 0) {
1325 1331
	int excl = EXCL(range);
1326 1332
	if (NIL_P(end) || r_less(val, end) <= -excl)
1327 1333
	    return Qtrue;