Skip to content

Commit 4f826d8

Browse files
committed
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
1 parent 14fcb13 commit 4f826d8

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/comp/syntax/parse/lexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ fn scan_number(c: char, rdr: reader) -> token::token {
240240
}
241241
}
242242
let is_float = false;
243-
if rdr.curr() == '.' {
243+
if rdr.curr() == '.' && !(is_alpha(rdr.next()) || rdr.next() == '_') {
244244
is_float = true;
245245
rdr.bump();
246246
let dec_part = scan_digits(rdr, 10u);

src/libcore/float.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ fn from_str(num: str) -> float {
173173
}
174174

175175
if c == '.' {//Examine decimal part
176-
let decimal = 1.f;
176+
let decimal = 1f;
177177
while(pos < len) {
178178
let char_range = str::char_range_at(num, pos);
179179
c = char_range.ch;
180180
pos = char_range.next;
181181
alt c {
182182
'0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' {
183-
decimal /= 10.f;
183+
decimal /= 10f;
184184
total += (((c as int) - ('0' as int)) as float)*decimal;
185185
}
186186
'e' | 'E' {

src/libstd/json.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ fn from_str_float(s: str) -> (option::t<json>, str) {
171171
let pos = 0u;
172172
let len = str::byte_len(s);
173173
let res = 0f;
174-
let neg = 1.f;
174+
let neg = 1f;
175175

176176
alt str::char_at(s, 0u) {
177177
'-' {
178-
neg = -1.f;
178+
neg = -1f;
179179
pos = 1u;
180180
}
181181
'+' {
@@ -205,15 +205,15 @@ fn from_str_float(s: str) -> (option::t<json>, str) {
205205
ret (some(num(neg * res)), str::char_slice(s, pos, str::char_len(s)));
206206
}
207207

208-
let dec = 1.f;
208+
let dec = 1f;
209209
while (pos < len) {
210210
let opos = pos;
211211
let chr = str::char_range_at(s, pos);
212212
let c = chr.ch;
213213
pos = chr.next;
214214
alt c {
215215
'0' to '9' {
216-
dec /= 10.f;
216+
dec /= 10f;
217217
res += (((c as int) - ('0' as int)) as float) * dec;
218218
}
219219
_ { ret (some(num(neg * res)),

src/test/run-pass/float2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77
let d = 1E6;
88
let e = 3.0f32;
99
let f = 5.9f64;
10-
let g = 1.e6f32;
10+
let g = 1e6f32;
1111
let h = 1.0e7f64;
1212
let i = 1.0E7f64;
1313
let j = 3.1e+9;

0 commit comments

Comments
 (0)