Skip to content

Commit 1f64296

Browse files
committed
Allow floats with unsigned exponent
1 parent 5b02ab7 commit 1f64296

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/tokenizer.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,20 @@ fn check_dec(value: &str) -> bool {
9595
}
9696

9797
fn check_exp(value: &str) -> bool {
98-
(value.starts_with('-') || value.starts_with('+')) &&
99-
value.len() >= 2 &&
100-
value[1..].chars().all(|x| x >= '0' && x <= '9')
98+
if value.len() == 0 {
99+
return false;
100+
}
101+
let first = value.chars().next().unwrap();
102+
if first != '-' && first != '+' && (first <= '0' || first >= '9') {
103+
return false;
104+
}
105+
return value[1..].chars().all(|x| x >= '0' && x <= '9');
101106
}
102107

103108
fn check_float(value: &str, exponent: Option<usize>, real: Option<usize>)
104109
-> bool
105110
{
111+
println!("Value {:?} {:?} {:?}", value, exponent, real);
106112
match (exponent, real) {
107113
(Some(e), Some(r)) if e < r => false,
108114
(Some(e), Some(r))
@@ -459,6 +465,8 @@ mod test {
459465
assert_eq!(tok_typ("a(x: 10.0) { b }"),
460466
[Name, Punctuator, Name, Punctuator, FloatValue, Punctuator,
461467
Punctuator, Name, Punctuator]);
468+
assert_eq!(tok_str("1.23e4"), ["1.23e4"]);
469+
assert_eq!(tok_typ("1.23e4"), [FloatValue]);
462470
}
463471

464472
// TODO(tailhook) fix errors in parser and check error message

0 commit comments

Comments
 (0)