use super::{Trailing, UnexpectedToken};
use crate::{Lexer, Token, punct::*};
macro_rules! alias {
(
$(
$(#[$attr:meta])*
$name:ident
), +$(,)?
) => {
paste::paste! {
$(
$(#[$attr])*
pub type [< UnexpectedTrailing $name >] <'inp, L, Lang = ()> = UnexpectedTrailingOf<'inp, $name, L, Lang>;
impl<T, Kind, S> UnexpectedToken<'_, T, Kind, S, Trailing<$name>> {
#[doc = "Create a new `UnexpectedToken` error indicating a trailing `" $name "` was found."]
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn [< trailing_ $name:snake>](
span: S,
token: T,
) -> Self {
Self::[< trailing_ $name:snake _of>](span, token)
}
}
impl<T, Kind, S, Lang> UnexpectedToken<'_, T, Kind, S, Trailing<$name, Lang>> {
#[doc = "Create a new `UnexpectedToken` error indicating a trailing `" $name "` was found for the given langauge."]
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn [< trailing_ $name:snake _of>](
span: S,
token: T,
) -> Self {
Self::trailing_of(span, token)
}
}
impl<T, Kind, S, Lang> ::core::fmt::Debug for UnexpectedToken<'_, T, Kind, S, Trailing<$name, Lang>>
where
S: ::core::fmt::Debug,
T: ::core::fmt::Debug,
Lang: ?Sized,
{
#[cfg_attr(not(tarpaulin), inline(always))]
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct(stringify!([< UnexpectedTrailing $name >]))
.field("span", &self.span)
.field("found", &self.found)
.finish()
}
}
impl<T, Kind, S, Lang> ::core::fmt::Display for UnexpectedToken<'_, T, Kind, S, Trailing<$name, Lang>>
where
S: ::core::fmt::Display,
Lang: ?Sized,
{
#[cfg_attr(not(tarpaulin), inline(always))]
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
write!(
f,
"unexpected trailing {} token at {}",
stringify!([< $name: snake >]),
self.span
)
}
}
impl<T, Kind, S, Lang> ::core::error::Error for UnexpectedToken<'_, T, Kind, S, Trailing<$name, Lang>>
where
S: ::core::fmt::Display + ::core::fmt::Debug,
T: ::core::fmt::Debug,
Lang: ?Sized,
{
}
)*
}
};
}
alias! {
Comma,
Dot,
Underscore,
Pipe,
Ampersand,
Hyphen,
DoubleColon,
}
pub type UnexpectedTrailingOf<'inp, Sep, L, Lang = ()> = UnexpectedToken<
'inp,
<L as Lexer<'inp>>::Token,
<<L as Lexer<'inp>>::Token as Token<'inp>>::Kind,
<L as Lexer<'inp>>::Span,
Trailing<Sep, Lang>,
>;