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