From 2f3550595773957fb7f0a994cbc32a5fd2424078 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Tue, 18 Oct 2022 15:24:21 -0700 Subject: [PATCH] simplify scanning --- rust/src/scanner.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/rust/src/scanner.rs b/rust/src/scanner.rs index 69e0977..d8c9121 100644 --- a/rust/src/scanner.rs +++ b/rust/src/scanner.rs @@ -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 {