use dbg-pls for parser snapshot tests

This commit is contained in:
nora 2022-06-26 15:20:20 +02:00
parent 31575cbdfb
commit e7597dab07
7 changed files with 246 additions and 333 deletions

View file

@ -1,3 +1,4 @@
use dbg_pls::{DebugPls, Formatter};
use peekmore::PeekMoreIterator;
use crate::{
@ -19,22 +20,28 @@ pub struct ParserError {
}
impl ParserError {
#[track_caller]
fn new(span: Span, message: String) -> Self {
Self { span, message }
}
#[track_caller]
fn eof() -> Self {
Self::new(Span::default(), "unexpected end of file".to_string())
}
#[track_caller]
fn unsupported(span: Span, token: &Tok<'_>) -> Self {
Self::new(span, format!("`{token}` is not supported"))
}
}
impl DebugPls for ParserError {
fn fmt(&self, f: Formatter<'_>) {
f.debug_struct("ParserError")
.field("span", &self.span)
.field("message", &self.message)
.finish();
}
}
type Result<T, E = ParserError> = std::result::Result<T, E>;
struct Parser<'src, I>