take 2, 100% fewer variable name conflicts
This commit is contained in:
parent
01666cefb9
commit
18c6892df3
@ -282,6 +282,19 @@ impl<'a> Iterator for TokenIterator<'a> {
|
||||
result.push(nxt);
|
||||
self.char_stream.next();
|
||||
}
|
||||
'.' => {
|
||||
result.push(nxt);
|
||||
self.char_stream.next();
|
||||
while let Some(&nxt_float) = self.char_stream.peek() {
|
||||
match nxt_float {
|
||||
'0'...'9' => {
|
||||
result.push(nxt_float);
|
||||
self.char_stream.next();
|
||||
}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
@ -290,6 +303,8 @@ impl<'a> Iterator for TokenIterator<'a> {
|
||||
|
||||
if let Ok(val) = out.parse::<i64>() {
|
||||
return Some(Token::IntConst(val));
|
||||
} else if let Ok(val) = out.parse::<f64>() {
|
||||
return Some(Token::FloatConst(val));
|
||||
}
|
||||
return Some(Token::LexErr(LexError::MalformedNumber));
|
||||
}
|
||||
@ -318,18 +333,7 @@ impl<'a> Iterator for TokenIterator<'a> {
|
||||
"break" => return Some(Token::Break),
|
||||
"return" => return Some(Token::Return),
|
||||
"fn" => return Some(Token::Fn),
|
||||
x => {
|
||||
match out.starts_with("f") {
|
||||
false => return Some(Token::Identifier(x.to_string())),
|
||||
true => {
|
||||
if let Ok(f) = (&out[1..]).to_owned().replace("_", ".").parse::<f64>() {
|
||||
return Some(Token::FloatConst(f));
|
||||
} else {
|
||||
return Some(Token::Identifier(x.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
x => return Some(Token::Identifier(x.to_string())),
|
||||
}
|
||||
}
|
||||
'"' => {
|
||||
|
@ -406,19 +406,19 @@ fn test_array_with_structs() {
|
||||
fn test_float() {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
if let Ok(result) = engine.eval::<bool>("let x = f0_0; let y = f1_0; x < y") {
|
||||
if let Ok(result) = engine.eval::<bool>("let x = 0.0; let y = 1.0; x < y") {
|
||||
assert!(result);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
if let Ok(result) = engine.eval::<bool>("let x = f0_0; let y = f1_0; x > y") {
|
||||
if let Ok(result) = engine.eval::<bool>("let x = 0.0; let y = 1.0; x > y") {
|
||||
assert!(!result);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
if let Ok(result) = engine.eval::<f64>("let x = f9_9999; x") {
|
||||
if let Ok(result) = engine.eval::<f64>("let x = 9.9999; x") {
|
||||
assert_eq!(result, 9.9999);
|
||||
} else {
|
||||
assert!(false);
|
||||
@ -464,7 +464,7 @@ fn struct_with_float() {
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
if let Ok(result) = engine.eval::<f64>("let ts = new_ts(); ts.x = f10_1001; ts.x") {
|
||||
if let Ok(result) = engine.eval::<f64>("let ts = new_ts(); ts.x = 10.1001; ts.x") {
|
||||
assert_eq!(result, 10.1001);
|
||||
} else {
|
||||
assert!(false);
|
||||
|
Loading…
Reference in New Issue
Block a user