Tokenize number literals
TODO: expand this bit of code to handle 0x12, etc. syntax
This commit is contained in:
parent
8662a3ba0e
commit
71aef379d3
@ -68,7 +68,20 @@ pub fn tokenize(input: &str) -> Option<Vec<Token>> {
|
|||||||
}
|
}
|
||||||
StrLiteral(buffer)
|
StrLiteral(buffer)
|
||||||
} else if is_digit(&c) {
|
} 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 {
|
} else {
|
||||||
Identifier("DUMMY".to_string())
|
Identifier("DUMMY".to_string())
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user