提交 4f826d81 编写于 作者: M Marijn Haverbeke

Make 1.f parse as a field access on the integer 1

A dot is only considered part of a number when not followed by a letter

Closes #1306
上级 14fcb135
......@@ -240,7 +240,7 @@ fn scan_number(c: char, rdr: reader) -> token::token {
}
}
let is_float = false;
if rdr.curr() == '.' {
if rdr.curr() == '.' && !(is_alpha(rdr.next()) || rdr.next() == '_') {
is_float = true;
rdr.bump();
let dec_part = scan_digits(rdr, 10u);
......
......@@ -173,14 +173,14 @@ fn from_str(num: str) -> float {
}
if c == '.' {//Examine decimal part
let decimal = 1.f;
let decimal = 1f;
while(pos < len) {
let char_range = str::char_range_at(num, pos);
c = char_range.ch;
pos = char_range.next;
alt c {
'0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' {
decimal /= 10.f;
decimal /= 10f;
total += (((c as int) - ('0' as int)) as float)*decimal;
}
'e' | 'E' {
......
......@@ -171,11 +171,11 @@ fn from_str_float(s: str) -> (option::t<json>, str) {
let pos = 0u;
let len = str::byte_len(s);
let res = 0f;
let neg = 1.f;
let neg = 1f;
alt str::char_at(s, 0u) {
'-' {
neg = -1.f;
neg = -1f;
pos = 1u;
}
'+' {
......@@ -205,7 +205,7 @@ fn from_str_float(s: str) -> (option::t<json>, str) {
ret (some(num(neg * res)), str::char_slice(s, pos, str::char_len(s)));
}
let dec = 1.f;
let dec = 1f;
while (pos < len) {
let opos = pos;
let chr = str::char_range_at(s, pos);
......@@ -213,7 +213,7 @@ fn from_str_float(s: str) -> (option::t<json>, str) {
pos = chr.next;
alt c {
'0' to '9' {
dec /= 10.f;
dec /= 10f;
res += (((c as int) - ('0' as int)) as float) * dec;
}
_ { ret (some(num(neg * res)),
......
......@@ -7,7 +7,7 @@ fn main() {
let d = 1E6;
let e = 3.0f32;
let f = 5.9f64;
let g = 1.e6f32;
let g = 1e6f32;
let h = 1.0e7f64;
let i = 1.0E7f64;
let j = 3.1e+9;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册