simplify scanning

main
Alpha Chen 2 years ago
parent 5e38b1ca95
commit 2f35505957
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -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> {

Loading…
Cancel
Save