wright/parser/
whitespace.rsuse super::{
error::{ParserError, ParserErrorKind},
Parser,
};
use crate::lexer::token::TokenTy;
pub fn optional_whitespace(parser: &mut Parser) {
parser.next_if_is(TokenTy::Whitespace);
}
pub fn require_whitespace(parser: &mut Parser) -> Result<(), ParserError> {
if parser.next_if_is(TokenTy::Whitespace).is_none() {
Err(ParserError {
kind: ParserErrorKind::ExpectedWhitespace,
location: parser
.peek_fragment()
.cloned()
.unwrap_or(parser.lexer().remaining.clone()),
help: None,
})
} else {
Ok(())
}
}