Tokenize number literals

TODO: expand this bit of code to handle 0x12, etc. syntax
This commit is contained in:
greg 2016-01-07 01:09:18 -08:00
parent 8662a3ba0e
commit 71aef379d3

View File

@ -68,7 +68,20 @@ pub fn tokenize(input: &str) -> Option<Vec<Token>> {
}
StrLiteral(buffer)
} else if is_digit(&c) {
NumLiteral(45.0)
let mut buffer = String::with_capacity(20);
buffer.push(c);
loop {
if iter.peek().map_or(false, |x| is_digit(x) || *x == '.') {
let n = iter.next().unwrap();
buffer.push(n);
} else {
break;
}
}
match buffer.parse::<f64>() {
Ok(f) => NumLiteral(f),
Err(_) => return None
}
} else {
Identifier("DUMMY".to_string())
};