wright/parser/
whitespace.rs1use super::{
4 Parser,
5 error::{ParserError, ParserErrorKind},
6};
7use crate::lexer::token::TokenTy;
8
9pub fn optional_whitespace(parser: &mut Parser) {
12 while parser.peek_variant() == Some(TokenTy::Whitespace) {
13 parser.advance(1);
14 }
15}
16
17pub fn require_whitespace(parser: &mut Parser) -> Result<(), ParserError> {
21 match parser.next_if_is(TokenTy::Whitespace) {
22 Some(_) => {
23 optional_whitespace(parser);
25 Ok(())
26 }
27
28 None => Err(ParserError {
29 kind: ParserErrorKind::ExpectedWhitespace,
30 location: parser.peek_fragment_or_rest_cloned(),
31 help: None,
32 }),
33 }
34}