Number separator _
This commit is contained in:
parent
7a69efc240
commit
ed2ae144dd
12
src/lexer.rs
12
src/lexer.rs
@ -40,10 +40,20 @@ impl<'a> Lexer<'a> {
|
|||||||
let mut sval = String::from(ch);
|
let mut sval = String::from(ch);
|
||||||
|
|
||||||
// Do as long as a next char exists and it is a numeric char
|
// Do as long as a next char exists and it is a numeric char
|
||||||
while let Some('0'..='9') = self.peek() {
|
while let Some(ch) = self.peek() {
|
||||||
// The next char is verified to be Some, so unwrap is safe
|
// The next char is verified to be Some, so unwrap is safe
|
||||||
|
match ch {
|
||||||
|
// Underscore is a separator, so remove it but don't add to number
|
||||||
|
'_' => {
|
||||||
|
self.next().unwrap();
|
||||||
|
}
|
||||||
|
'0'..='9' => {
|
||||||
sval.push(self.next().unwrap());
|
sval.push(self.next().unwrap());
|
||||||
}
|
}
|
||||||
|
// Next char is not a number, so stop and finish the number token
|
||||||
|
_ => break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: We only added numeric chars to the string, but the conversion could still fail
|
// TODO: We only added numeric chars to the string, but the conversion could still fail
|
||||||
tokens.push(Token::I64(sval.parse().unwrap()));
|
tokens.push(Token::I64(sval.parse().unwrap()));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user