use super::NodeParserResult;
use crate::parser::{
error::{ParserError, ParserErrorVariant},
lexer::tokens::{CommentTy, TokenTy},
state::ParserState,
};
#[rustfmt::skip] pub fn ignore_whitespace_and_comments(parser_state: &mut ParserState) -> NodeParserResult<()> {
while let Some(peeked_token_ty) = parser_state.peek_token_ty() {
match peeked_token_ty {
| TokenTy::Whitespace
| TokenTy::SingleLineComment { comment_type: CommentTy::Normal }
| TokenTy::MultilineComment { comment_type: CommentTy::Normal, is_terminated: true }
=> {
let _ = parser_state.next_token();
}
TokenTy::MultilineComment { is_terminated: false, .. } => {
return Err(ParserError {
byte_range: parser_state.peek_byte_range(),
ty: ParserErrorVariant::UnterminatedMultilineComment,
})
}
_ => {
return Ok(());
}
}
}
Ok(())
}