Skip to content

Commit

Permalink
✨ add support for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KPMGE committed Mar 26, 2024
1 parent d06b73c commit 2d112ab
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@ impl Lexer {
'}' => Token::RightBrace,
'+' => Token::Plus,
'-' => Token::Minus,
'*' => Token::Asterisk,
'<' => Token::LessThan,
'>' => Token::GreaterThan,
',' => Token::Comma,
'/' => Token::Slash,
';' => Token::Semicolon,
'"' => Token::String(self.read_string()),
'*' => Token::Asterisk,
'/' => {
if self.peek_char(self.read_position).unwrap() == '*' {
self.skip_comments();
return self.next_token();
}
Token::Slash
}
'=' => match self.peek_char(self.read_position) {
Some('=') => {
self.read_char();
Expand Down Expand Up @@ -169,6 +175,19 @@ impl Lexer {
break;
}
}

fn skip_comments(&mut self) {
while let (Some(ch), Some(next_ch)) =
(self.current_char, self.peek_char(self.read_position))
{
if ch == '*' && next_ch == '/' {
break;
}
self.read_char();
}
self.read_char();
self.read_char();
}
}

trait IsLetter {
Expand Down

0 comments on commit 2d112ab

Please sign in to comment.