1
Fork 0

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
This commit is contained in:
Marijn Haverbeke 2011-12-16 10:11:00 +01:00
parent 14fcb135a9
commit 4f826d81f6
4 changed files with 8 additions and 8 deletions

View file

@ -240,7 +240,7 @@ fn scan_number(c: char, rdr: reader) -> token::token {
} }
} }
let is_float = false; let is_float = false;
if rdr.curr() == '.' { if rdr.curr() == '.' && !(is_alpha(rdr.next()) || rdr.next() == '_') {
is_float = true; is_float = true;
rdr.bump(); rdr.bump();
let dec_part = scan_digits(rdr, 10u); let dec_part = scan_digits(rdr, 10u);

View file

@ -173,14 +173,14 @@ fn from_str(num: str) -> float {
} }
if c == '.' {//Examine decimal part if c == '.' {//Examine decimal part
let decimal = 1.f; let decimal = 1f;
while(pos < len) { while(pos < len) {
let char_range = str::char_range_at(num, pos); let char_range = str::char_range_at(num, pos);
c = char_range.ch; c = char_range.ch;
pos = char_range.next; pos = char_range.next;
alt c { alt c {
'0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' { '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; total += (((c as int) - ('0' as int)) as float)*decimal;
} }
'e' | 'E' { 'e' | 'E' {

View file

@ -171,11 +171,11 @@ fn from_str_float(s: str) -> (option::t<json>, str) {
let pos = 0u; let pos = 0u;
let len = str::byte_len(s); let len = str::byte_len(s);
let res = 0f; let res = 0f;
let neg = 1.f; let neg = 1f;
alt str::char_at(s, 0u) { alt str::char_at(s, 0u) {
'-' { '-' {
neg = -1.f; neg = -1f;
pos = 1u; 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))); ret (some(num(neg * res)), str::char_slice(s, pos, str::char_len(s)));
} }
let dec = 1.f; let dec = 1f;
while (pos < len) { while (pos < len) {
let opos = pos; let opos = pos;
let chr = str::char_range_at(s, 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; pos = chr.next;
alt c { alt c {
'0' to '9' { '0' to '9' {
dec /= 10.f; dec /= 10f;
res += (((c as int) - ('0' as int)) as float) * dec; res += (((c as int) - ('0' as int)) as float) * dec;
} }
_ { ret (some(num(neg * res)), _ { ret (some(num(neg * res)),

View file

@ -7,7 +7,7 @@ fn main() {
let d = 1E6; let d = 1E6;
let e = 3.0f32; let e = 3.0f32;
let f = 5.9f64; let f = 5.9f64;
let g = 1.e6f32; let g = 1e6f32;
let h = 1.0e7f64; let h = 1.0e7f64;
let i = 1.0E7f64; let i = 1.0E7f64;
let j = 3.1e+9; let j = 3.1e+9;