parser: skip comments in peek

This commit is contained in:
2025-10-16 06:50:17 -04:00
parent 1998558468
commit 6da201f52f

View File

@@ -70,9 +70,12 @@ impl<'t> Parser<'t> {
pub fn peek(&mut self) -> PResult<&Token> { pub fn peek(&mut self) -> PResult<&Token> {
let next_tok = match self.next_tok.take() { let next_tok = match self.next_tok.take() {
Some(tok) => tok, Some(tok) => tok,
None => match self.lexer.scan() { None => loop {
Ok(tok) => tok, match self.lexer.scan() {
Err(e) => Err(ParseError::FromLexer(e))?, Ok(Token { kind: TKind::Comment, .. }) => {}
Ok(tok) => break tok,
Err(e) => Err(ParseError::FromLexer(e))?,
}
}, },
}; };
self.last_loc = next_tok.span; 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 { impl<'t> Parse<'t> for Pat {
type Prec = PPrec; type Prec = PPrec;
fn parse(p: &mut Parser<'t>, level: PPrec) -> PResult<Self> { fn parse(p: &mut Parser<'t>, level: PPrec) -> PResult<Self> {
while p.next_if(TKind::Comment).is_ok() {}
let tok = p.peek()?; let tok = p.peek()?;
// Prefix // Prefix
@@ -813,7 +815,6 @@ impl<'t> Parse<'t> for Expr {
/// The `level` parameter indicates the operator binding level of the expression. /// The `level` parameter indicates the operator binding level of the expression.
fn parse(p: &mut Parser<'t>, level: usize) -> PResult<Self> { fn parse(p: &mut Parser<'t>, level: usize) -> PResult<Self> {
const MIN: usize = Prec::MIN; const MIN: usize = Prec::MIN;
while p.next_if(TKind::Comment).is_ok() {}
// Prefix // Prefix
let tok = p.peek()?; let tok = p.peek()?;