ratio_lit.patch

A patch for the rational number literal - Takuto Hayashi, 08/01/2013 04:53 PM

Download (2.11 KB)

View differences:

parse.y
754 754
	keyword__ENCODING__
755 755

  
756 756
%token <id>   tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
757
%token <node> tINTEGER tFLOAT tSTRING_CONTENT tCHAR
757
%token <node> tINTEGER tFLOAT tRATIONAL tSTRING_CONTENT tCHAR
758 758
%token <node> tNTH_REF tBACK_REF
759 759
%token <num>  tREGEXP_END
760 760

  
......
2128 2128
			$$ = dispatch2(unary, ripper_intern("-@"), $$);
2129 2129
		    %*/
2130 2130
		    }
2131
		| tUMINUS_NUM tRATIONAL tPOW arg
2132
		    {
2133
		    /*%%%*/
2134
			$$ = NEW_CALL(call_bin_op($2, tPOW, $4), tUMINUS, 0);
2135
		    /*%
2136
			$$ = dispatch3(binary, $2, ripper_intern("**"), $4);
2137
			$$ = dispatch2(unary, ripper_intern("-@"), $$);
2138
		    %*/
2139
		    }
2131 2140
		| tUPLUS arg
2132 2141
		    {
2133 2142
		    /*%%%*/
......
4294 4303

  
4295 4304
numeric 	: tINTEGER
4296 4305
		| tFLOAT
4306
		| tRATIONAL
4297 4307
		| tUMINUS_NUM tINTEGER	       %prec tLOWEST
4298 4308
		    {
4299 4309
		    /*%%%*/
......
4310 4320
			$$ = dispatch2(unary, ripper_intern("-@"), $2);
4311 4321
		    %*/
4312 4322
		    }
4323
		| tUMINUS_NUM tRATIONAL	       %prec tLOWEST
4324
		    {
4325
		    /*%%%*/
4326
                        $$ = NEW_CALL($2, tUMINUS, 0);
4327
		    /*%
4328
			$$ = dispatch2(unary, ripper_intern("-@"), $2);
4329
		    %*/
4330
		    }
4313 4331
		;
4314 4332

  
4315 4333
user_variable	: tIDENTIFIER
......
7583 7601
	    }
7584 7602

  
7585 7603
	  decode_num:
7586
	    pushback(c);
7587 7604
	    if (nondigit) {
7588 7605
		char tmp[30];
7589 7606
	      trailing_uc:
......
7598 7615
		    errno = 0;
7599 7616
		}
7600 7617
                set_yylval_literal(DBL2NUM(d));
7618
                pushback(c);
7601 7619
		return tFLOAT;
7602 7620
	    }
7621
            if (c == 'r') {
7622
                NODE *args = NEW_ARRAY(NEW_STR(rb_str_new_cstr(tok())));
7623
                NODE *fcall = NEW_FCALL(rb_intern("Rational"), args);
7624
                set_yylval_node(fcall);
7625
                return tRATIONAL;
7626
            }
7603 7627
	    set_yylval_literal(rb_cstr_to_inum(tok(), 10, FALSE));
7628
            pushback(c);
7604 7629
	    return tINTEGER;
7605 7630
	}
7606 7631