Alpha Chen 2 years ago
parent e8f5059c9b
commit 3dc84e9f28
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -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."),
})
}
}

Loading…
Cancel
Save