Lex true/false as 1/0
This commit is contained in:
parent
6816392173
commit
1f1f589dd4
17
src/lexer.rs
17
src/lexer.rs
@ -123,6 +123,23 @@ impl<'a> Lexer<'a> {
|
|||||||
'(' => tokens.push(Token::LParen),
|
'(' => tokens.push(Token::LParen),
|
||||||
')' => tokens.push(Token::RParen),
|
')' => tokens.push(Token::RParen),
|
||||||
|
|
||||||
|
'a'..='z' | 'A'..='Z' | '_' => {
|
||||||
|
let mut ident = String::from(ch);
|
||||||
|
|
||||||
|
// Do as long as a next char exists and it is a valid ident char
|
||||||
|
while let Some('a'..='z' | 'A'..='Z' | '_' | '0'..='9') = self.peek() {
|
||||||
|
// The next char is verified to be Some, so unwrap is safe
|
||||||
|
ident.push(self.next().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
match ident.as_str() {
|
||||||
|
"true" => tokens.push(Token::I64(1)),
|
||||||
|
"false" => tokens.push(Token::I64(0)),
|
||||||
|
_ => panic!("Lexer encountered unknown ident: '{}'", ident),
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: Don't panic, keep calm
|
//TODO: Don't panic, keep calm
|
||||||
_ => panic!("Lexer encountered unexpected char: '{}'", ch),
|
_ => panic!("Lexer encountered unexpected char: '{}'", ch),
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user