Ignore comments in .cton files.

The lexer still recognizes comments and generates tokens for them. They may be
useful for test annotations at some point.
This commit is contained in:
Jakob Stoklund Olesen
2016-07-05 12:49:34 -07:00
parent a985bc18bc
commit 74038d153c

View File

@@ -135,17 +135,23 @@ impl<'a> Parser<'a> {
// Get the current lookahead token, after making sure there is one. // Get the current lookahead token, after making sure there is one.
fn token(&mut self) -> Option<Token<'a>> { fn token(&mut self) -> Option<Token<'a>> {
if self.lookahead == None { while self.lookahead == None {
match self.lex.next() { match self.lex.next() {
Some(Ok(lexer::LocatedToken { token, location })) => { Some(Ok(lexer::LocatedToken { token, location })) => {
self.lookahead = Some(token); match token {
Token::Comment(_) => {
// Ignore comments.
}
_ => self.lookahead = Some(token),
}
self.loc = location; self.loc = location;
} }
Some(Err(lexer::LocatedError { error, location })) => { Some(Err(lexer::LocatedError { error, location })) => {
self.lex_error = Some(error); self.lex_error = Some(error);
self.loc = location; self.loc = location;
break;
} }
None => {} None => break,
} }
} }
return self.lookahead; return self.lookahead;