remove is_at_end

main
Alpha Chen 2 years ago
parent 7baa16ee8e
commit ce9eb0de17
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -18,7 +18,7 @@ impl<'a> Scanner<'a> {
pub fn scan(&mut self) -> Result<Token> {
self.skip_whitespace();
if self.is_at_end() {
if self.peek().is_none() {
return self.make_token(TokenKind::Eof);
}
@ -75,10 +75,6 @@ impl<'a> Scanner<'a> {
};
}
fn is_at_end(&self) -> bool {
self.current == self.source.len()
}
fn make_token(&self, kind: TokenKind) -> Result<Token> {
Ok(Token {
kind,
@ -101,11 +97,7 @@ impl<'a> Scanner<'a> {
}
fn is_match(&mut self, expected: char) -> bool {
if self.is_at_end() {
return false;
}
if self.source[self.current] as char != expected {
if self.peek() != Some(expected) {
return false;
}
@ -146,11 +138,7 @@ impl<'a> Scanner<'a> {
}
fn peek_next(&mut self) -> Option<char> {
if self.is_at_end() {
None
} else {
Some(self.source[self.current + 1] as char)
}
self.source.get(self.current + 1).map(|&x| x as char)
}
fn string(&mut self) -> Result<Token> {
@ -161,7 +149,7 @@ impl<'a> Scanner<'a> {
self.advance();
}
if self.is_at_end() {
if self.peek().is_none() {
return self.error_token("Unterminated string.");
}

Loading…
Cancel
Save