|
|
|
@ -22,15 +22,9 @@ impl<'a> Scanner<'a> {
|
|
|
|
|
return self.make_token(TokenKind::Eof);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let c = self.advance();
|
|
|
|
|
if is_alpha(c) {
|
|
|
|
|
return self.identifier();
|
|
|
|
|
}
|
|
|
|
|
if c.is_ascii_digit() {
|
|
|
|
|
return self.number();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return match c {
|
|
|
|
|
match self.advance() {
|
|
|
|
|
c if is_alpha(c) => self.identifier(),
|
|
|
|
|
c if c.is_ascii_digit() => self.number(),
|
|
|
|
|
'(' => self.make_token(TokenKind::LeftParen),
|
|
|
|
|
')' => self.make_token(TokenKind::RightParen),
|
|
|
|
|
'{' => self.make_token(TokenKind::LeftBrace),
|
|
|
|
@ -72,7 +66,7 @@ impl<'a> Scanner<'a> {
|
|
|
|
|
}
|
|
|
|
|
'"' => self.string(),
|
|
|
|
|
_ => self.error_token("Unexpected character."),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn make_token(&self, kind: TokenKind) -> Result<Token> {
|
|
|
|
|