Skip to content

Commit

Permalink
fix: attempted to fix out of bounds error
Browse files Browse the repository at this point in the history
  • Loading branch information
xNaCly committed Apr 2, 2023
1 parent 66169a6 commit 3b4d96e
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,17 @@ impl Parser {
}

fn peek(&self) -> char {
if !self.at_end() {
return self.input.chars().nth(self.pos + 1).expect("couldn't peek");
}
'\0'
self.input.chars().nth(self.pos + 1).unwrap_or('\0')
}

fn peek_equals(&self, character: char) -> bool {
self.peek() == character
}

fn advance(&mut self) {
if !self.at_end() || self.pos + 1 <= self.input.len() {
if !self.at_end() && self.pos + 1 <= self.input.len() {
self.pos += 1;
self.current_char = self
.input
.chars()
.nth(self.pos)
.expect("could not get next character");
self.current_char = self.input.chars().nth(self.pos).unwrap_or('\0');
self.line_pos += 1;
}
}
Expand Down

0 comments on commit 3b4d96e

Please sign in to comment.