tamer: parse::error: Describe unexpected token of input

When Parser has a unhandled dead state and fails due to an unexpected token
of input, we should display what we interpreted that token as.

DEV-7145
main
Mike Gerwitz 2022-07-29 10:00:59 -04:00
parent 18803ea576
commit 0edb21429d
1 changed files with 3 additions and 2 deletions

View File

@ -22,6 +22,7 @@
use super::Token;
use crate::{
diagnose::{Annotate, AnnotatedSpan, Diagnostic},
fmt::{DisplayWrapper, TtQuote},
span::Span,
};
use std::{error::Error, fmt::Display};
@ -122,8 +123,8 @@ impl<T: Token, E: Diagnostic + PartialEq> Display for ParseError<T, E> {
Self::UnexpectedEof(_, desc) => {
write!(f, "unexpected end of input while {desc}")
}
Self::UnexpectedToken(_, desc) => {
write!(f, "unexpected input while {desc}")
Self::UnexpectedToken(tok, desc) => {
write!(f, "unexpected {} while {desc}", TtQuote::wrap(tok))
}
// This is not really something the user should have to deal
// with,