From 3dc84e9f28daedbdfa72a465abe112224e622f3f Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 23 Oct 2022 16:23:02 -0700 Subject: [PATCH] mu --- rust/src/scanner.rs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/rust/src/scanner.rs b/rust/src/scanner.rs index 8a25f04..25dc98c 100644 --- a/rust/src/scanner.rs +++ b/rust/src/scanner.rs @@ -67,7 +67,7 @@ impl<'a> Scanner<'a> { self.source.get(self.current + 1).map(|&x| x as char) } - fn string(&'a mut self) -> Token<'a> { + fn string(&mut self) -> Token<'a> { while matches!(self.peek(), Some(c) if c != '"') { if self.peek() == Some('\n') { self.line += 1; @@ -85,7 +85,7 @@ impl<'a> Scanner<'a> { self.make_token(TokenKind::String) } - fn number(&'a mut self) -> Token<'a> { + fn number(&mut self) -> Token<'a> { while matches!(self.peek(), Some(c) if c.is_ascii_digit()) { self.advance(); } @@ -102,7 +102,7 @@ impl<'a> Scanner<'a> { self.make_token(TokenKind::Number) } - fn identifier(&mut self) -> Token { + fn identifier(&mut self) -> Token<'a> { while matches!(self.peek(), Some(c) if is_alpha(c) || c.is_ascii_digit()) { self.advance(); } @@ -139,7 +139,7 @@ impl<'a> Scanner<'a> { } } - fn make_token(&'a self, kind: TokenKind) -> Token<'a> { + fn make_token(&self, kind: TokenKind) -> Token<'a> { Token { kind: TokenKind::And, value: std::str::from_utf8(&self.source[..self.current]).unwrap(), @@ -156,18 +156,10 @@ impl<'a> Iterator for Scanner<'a> { self.peek()?; Some(match self.advance() { - // _ => self.make_token(TokenKind::And), - _ => Token { - kind: TokenKind::And, - value: std::str::from_utf8(&self.source[..self.current]).unwrap(), - line: self.line, - }, - }) - - // Some(match self.advance() { - // c if is_alpha(c) => self.identifier(), - // c if c.is_ascii_digit() => self.number(), - // '(' => self.make_token(TokenKind::LeftParen), + c if is_alpha(c) => self.identifier(), + c if c.is_ascii_digit() => self.number(), + // '(' => Token::new(self, TokenKind::LeftParen), + '(' => self.make_token(TokenKind::LeftParen), // ')' => self.make_token(TokenKind::RightParen), // '{' => self.make_token(TokenKind::LeftBrace), // '}' => self.make_token(TokenKind::RightBrace), @@ -207,8 +199,8 @@ impl<'a> Iterator for Scanner<'a> { // } // } // '"' => self.string(), - // _ => Token::error(&self, "Unexpected character."), - // }) + _ => Token::error(self, "Unexpected character."), + }) } }