From 6da201f52ff4d2950389ba4a6aca7a71d33794cf Mon Sep 17 00:00:00 2001 From: John Date: Thu, 16 Oct 2025 06:50:17 -0400 Subject: [PATCH] parser: skip comments in peek --- src/parser.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 2dc7cd8..30a4fb3 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -70,9 +70,12 @@ impl<'t> Parser<'t> { pub fn peek(&mut self) -> PResult<&Token> { let next_tok = match self.next_tok.take() { Some(tok) => tok, - None => match self.lexer.scan() { - Ok(tok) => tok, - Err(e) => Err(ParseError::FromLexer(e))?, + None => loop { + match self.lexer.scan() { + Ok(Token { kind: TKind::Comment, .. }) => {} + Ok(tok) => break tok, + Err(e) => Err(ParseError::FromLexer(e))?, + } }, }; self.last_loc = next_tok.span; @@ -286,7 +289,6 @@ fn pat_from_infix(token: &Token) -> Option<(PatPs, PPrec)> { impl<'t> Parse<'t> for Pat { type Prec = PPrec; fn parse(p: &mut Parser<'t>, level: PPrec) -> PResult { - while p.next_if(TKind::Comment).is_ok() {} let tok = p.peek()?; // Prefix @@ -813,7 +815,6 @@ impl<'t> Parse<'t> for Expr { /// The `level` parameter indicates the operator binding level of the expression. fn parse(p: &mut Parser<'t>, level: usize) -> PResult { const MIN: usize = Prec::MIN; - while p.next_if(TKind::Comment).is_ok() {} // Prefix let tok = p.peek()?;