Skip to content

Commit

Permalink
perf: do not need Token::Comment anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
caelansar committed Jul 13, 2024
1 parent bf61c64 commit 1332ad7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,16 @@ impl<'a> Lexer<'a> {
Token::SlashEq
}
Some('/') => {
self.skip_comment();
Token::Comment
self.read_char();
// a comment goes until the end of the line.
while let Some(ch) = self.ch {
if ch == '\n' {
break;
}
self.read_char();
}
// do not need to call read_char in this recursion
return self.next_token();
}
_ => Token::from_str(token.to_string().as_str()).unwrap(),
},
Expand Down
3 changes: 1 addition & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,7 @@ impl<'a> Parser<'a> {
.get(&self.current_token)
{
Some(parse_fn) => parse_fn(self),
None if self.current_token_is(&token::Token::Comment) => return None,
_ => {
None => {
self.no_prefix_parse_fn_error(&self.current_token.clone());
return None;
}
Expand Down
2 changes: 0 additions & 2 deletions src/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub enum Token {
Break,
Continue,
Return,
Comment,
And,
Or,
LeftShift,
Expand Down Expand Up @@ -166,7 +165,6 @@ impl fmt::Display for Token {
Token::For => write!(f, "for"),
Token::Return => write!(f, "return"),
Token::Illegal => write!(f, "ILLEGAL"),
Token::Comment => write!(f, "//comment"),
Token::Break => write!(f, "break"),
Token::Continue => write!(f, "continue"),
Token::And => write!(f, "&&"),
Expand Down

0 comments on commit 1332ad7

Please sign in to comment.