ruby-changes:34761
From: nobu <ko1@a...>
Date: Thu, 17 Jul 2014 13:30:34 +0900 (JST)
Subject: [ruby-changes:34761] nobu:r46844 (trunk): parse.y: parse_rational
nobu 2014-07-17 13:30:21 +0900 (Thu, 17 Jul 2014) New Revision: 46844 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46844 Log: parse.y: parse_rational * parse.y (parse_rational): extract from parse_numeric(). Modified files: trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 46843) +++ parse.y (revision 46844) @@ -6938,6 +6938,17 @@ parser_prepare(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L6938 space_seen && !ISSPACE(c) && \ (ambiguous_operator(op, syn), 0))) +static VALUE +parse_rational(struct parser_params *parser, char *str, int len, int seen_point) +{ + VALUE v; + char *point = &str[seen_point]; + size_t fraclen = len-seen_point-1; + memmove(point, point+1, fraclen+1); + v = rb_cstr_to_inum(str, 10, FALSE); + return rb_rational_new(v, rb_int_positive_pow(10, fraclen)); +} + static int parse_numeric(struct parser_params *parser, int c) { @@ -7156,12 +7167,8 @@ parse_numeric(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/parse.y#L7167 suffix = number_literal_suffix(seen_e ? NUM_SUFFIX_I : NUM_SUFFIX_ALL); if (suffix & NUM_SUFFIX_R) { - char *point = &tok()[seen_point]; - size_t fraclen = toklen()-seen_point-1; type = tRATIONAL; - memmove(point, point+1, fraclen+1); - v = rb_cstr_to_inum(tok(), 10, FALSE); - v = rb_rational_new(v, rb_int_positive_pow(10, fraclen)); + v = parse_rational(parser, tok(), toklen(), seen_point); } else { double d = strtod(tok(), 0); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/