macro_rules! impl_spanned_struct {
($name:ident $(<$lifetime:lifetime>)?) => {
impl$(<$lifetime>)? crate::pos::Spanned for $name$(<$lifetime>)? {
#[inline]
fn span(&self) -> &Span {
&self.span
}
}
};
}
macro_rules! impl_spanned_enum {
($name:ident $(<$lifetime:lifetime>)? { tuple: [$($tuple:ident,)*], unit: [$($unit:ident,)*], }) => {
impl$(<$lifetime>)? crate::pos::Spanned for $name$(<$lifetime>)? {
#[inline]
fn span(&self) -> &Span {
match self {
$(Self::$tuple(value) => value.span(),)*
$(Self::$unit => panic!("not implemented"),)*
}
}
}
};
}
macro_rules! impl_span_ignored_eq_struct {
($name:ident $(<$lifetime:lifetime>)? {}) => {
impl$(<$lifetime>)? crate::SpanIgnoredEq for $name$(<$lifetime>)? {
#[inline]
fn span_ignored_eq(&self, _other: &Self) -> bool {
true
}
}
};
($name:ident $(<$lifetime:lifetime>)? { $first:ident $(, $field:ident)* $(,)? }) => {
impl$(<$lifetime>)? crate::SpanIgnoredEq for $name$(<$lifetime>)? {
#[inline]
fn span_ignored_eq(&self, other: &Self) -> bool {
crate::SpanIgnoredEq::span_ignored_eq(&self.$first, &other.$first)
$(&& crate::SpanIgnoredEq::span_ignored_eq(&self.$field, &other.$field))*
}
}
};
}
macro_rules! impl_span_ignored_eq_enum {
($name:ident $(<$lifetime:lifetime>)? { tuple: [$($tuple:ident,)*], unit: [$($unit:ident,)*], }) => {
impl$(<$lifetime>)? crate::SpanIgnoredEq for $name$(<$lifetime>)? {
#[inline]
fn span_ignored_eq(&self, other: &Self) -> bool {
match (self, other) {
$((Self::$tuple(left), Self::$tuple(right)) => crate::SpanIgnoredEq::span_ignored_eq(left, right),)*
$((Self::$unit, Self::$unit) => true,)*
_ => false,
}
}
}
};
}
macro_rules! impl_enum_as_is {
($name:ident $(<$lifetime:lifetime>)? { tuple: [$($tuple:ident($tuple_ty:ty) => $is_tuple:ident, $as_tuple:ident,)*], unit: [$($unit:ident => $is_unit:ident,)*], }) => {
impl$(<$lifetime>)? $name$(<$lifetime>)? {
$(
#[doc = concat!("Checks whether this is [`", stringify!($tuple), "`](Self::", stringify!($tuple), ").")]
#[inline]
pub fn $is_tuple(&self) -> bool {
matches!(self, Self::$tuple(..))
}
#[doc = concat!("Returns [`Some`] with a reference to [`", stringify!($tuple), "`](Self::", stringify!($tuple), "), otherwise [`None`].")]
#[inline]
pub fn $as_tuple(&self) -> Option<&$tuple_ty> {
match self {
Self::$tuple(value) => Some(value),
_ => None,
}
}
)*
$(
#[doc = concat!("Checks whether this is [`", stringify!($unit), "`](Self::", stringify!($unit), ").")]
#[inline]
pub fn $is_unit(&self) -> bool {
matches!(self, Self::$unit)
}
)*
}
};
}
impl_spanned_struct!(Comment<'s>);
impl_spanned_enum!(CommentKind {
tuple: [],
unit: [Block, Line, ],
});
impl_spanned_struct!(TokenWithSpan<'s>);
impl_span_ignored_eq_struct!(Comment<'s> { content, kind, });
impl_span_ignored_eq_enum!(CommentKind {
tuple: [],
unit: [Block, Line, ],
});
impl_enum_as_is!(CommentKind {
tuple: [
],
unit: [Block => is_block, Line => is_line, ],
});
impl_enum_as_is!(Token<'s> {
tuple: [
Eof(Eof) => is_eof, as_eof,
Ampersand(Ampersand) => is_ampersand, as_ampersand,
Asterisk(Asterisk) => is_asterisk, as_asterisk,
AsteriskEqual(AsteriskEqual) => is_asterisk_equal, as_asterisk_equal,
At(At) => is_at, as_at,
AtKeyword(AtKeyword<'s>) => is_at_keyword, as_at_keyword,
AtLBraceVar(AtLBraceVar<'s>) => is_at_l_brace_var, as_at_l_brace_var,
BacktickCode(BacktickCode<'s>) => is_backtick_code, as_backtick_code,
Bar(Bar) => is_bar, as_bar,
BarBar(BarBar) => is_bar_bar, as_bar_bar,
BarEqual(BarEqual) => is_bar_equal, as_bar_equal,
CaretEqual(CaretEqual) => is_caret_equal, as_caret_equal,
Cdc(Cdc) => is_cdc, as_cdc,
Cdo(Cdo) => is_cdo, as_cdo,
Colon(Colon) => is_colon, as_colon,
ColonColon(ColonColon) => is_colon_colon, as_colon_colon,
Comma(Comma) => is_comma, as_comma,
Dedent(Dedent) => is_dedent, as_dedent,
Dimension(Dimension<'s>) => is_dimension, as_dimension,
DollarEqual(DollarEqual) => is_dollar_equal, as_dollar_equal,
DollarLBraceVar(DollarLBraceVar<'s>) => is_dollar_l_brace_var, as_dollar_l_brace_var,
DollarVar(DollarVar<'s>) => is_dollar_var, as_dollar_var,
Dot(Dot) => is_dot, as_dot,
DotDotDot(DotDotDot) => is_dot_dot_dot, as_dot_dot_dot,
Equal(Equal) => is_equal, as_equal,
EqualEqual(EqualEqual) => is_equal_equal, as_equal_equal,
Exclamation(Exclamation) => is_exclamation, as_exclamation,
ExclamationEqual(ExclamationEqual) => is_exclamation_equal, as_exclamation_equal,
GreaterThan(GreaterThan) => is_greater_than, as_greater_than,
GreaterThanEqual(GreaterThanEqual) => is_greater_than_equal, as_greater_than_equal,
Hash(Hash<'s>) => is_hash, as_hash,
HashLBrace(HashLBrace) => is_hash_l_brace, as_hash_l_brace,
Ident(Ident<'s>) => is_ident, as_ident,
Indent(Indent) => is_indent, as_indent,
LBrace(LBrace) => is_l_brace, as_l_brace,
LBracket(LBracket) => is_l_bracket, as_l_bracket,
LessThan(LessThan) => is_less_than, as_less_than,
LessThanEqual(LessThanEqual) => is_less_than_equal, as_less_than_equal,
Linebreak(Linebreak) => is_linebreak, as_linebreak,
LParen(LParen) => is_l_paren, as_l_paren,
Minus(Minus) => is_minus, as_minus,
Number(Number<'s>) => is_number, as_number,
NumberSign(NumberSign) => is_number_sign, as_number_sign,
Percent(Percent) => is_percent, as_percent,
Percentage(Percentage<'s>) => is_percentage, as_percentage,
Placeholder(Placeholder<'s>) => is_placeholder, as_placeholder,
Plus(Plus) => is_plus, as_plus,
PlusUnderscore(PlusUnderscore) => is_plus_underscore, as_plus_underscore,
Question(Question) => is_question, as_question,
RBrace(RBrace) => is_r_brace, as_r_brace,
RBracket(RBracket) => is_r_bracket, as_r_bracket,
RParen(RParen) => is_r_paren, as_r_paren,
Semicolon(Semicolon) => is_semicolon, as_semicolon,
Solidus(Solidus) => is_solidus, as_solidus,
Str(Str<'s>) => is_str, as_str,
StrTemplate(StrTemplate<'s>) => is_str_template, as_str_template,
Tilde(Tilde) => is_tilde, as_tilde,
TildeEqual(TildeEqual) => is_tilde_equal, as_tilde_equal,
UrlRaw(UrlRaw<'s>) => is_url_raw, as_url_raw,
UrlTemplate(UrlTemplate<'s>) => is_url_template, as_url_template,
],
unit: [],
});