Skip to content

Commit

Permalink
Combine generate_to_tokens and ast_enum_of_structs_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 15, 2024
1 parent 7ab886f commit fa5fb53
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,8 @@ macro_rules! ast_enum_of_structs {

$(#[$enum_attr])* $pub $enum $name $body

ast_enum_of_structs_impl!($name $body);

#[cfg(feature = "printing")]
generate_to_tokens!(() tokens $name $body);
};
}

macro_rules! ast_enum_of_structs_impl {
(
$name:ident {
$(
$(#[cfg $cfg_attr:tt])*
$(#[doc $($doc_attr:tt)*])*
$variant:ident $( ($member:ident) )*,
)*
}
) => {
$($(
ast_enum_from_struct!($name::$variant, $member);
)*)*
ast_enum_of_structs_impl!(() tokens $name $body);
};
}

Expand All @@ -97,7 +79,7 @@ macro_rules! ast_enum_from_struct {
}

#[cfg(feature = "printing")]
macro_rules! generate_to_tokens {
macro_rules! ast_enum_of_structs_impl {
(
($($arms:tt)*) $tokens:ident $name:ident {
$(#[cfg $cfg_attr:tt])*
Expand All @@ -106,7 +88,7 @@ macro_rules! generate_to_tokens {
$($next:tt)*
}
) => {
generate_to_tokens!(
ast_enum_of_structs_impl!(
($($arms)* $(#[cfg $cfg_attr])* $name::$variant => {})
$tokens $name { $($next)* }
);
Expand All @@ -120,7 +102,8 @@ macro_rules! generate_to_tokens {
$($next:tt)*
}
) => {
generate_to_tokens!(
ast_enum_from_struct!($name::$variant, $member);
ast_enum_of_structs_impl!(
($($arms)* $(#[cfg $cfg_attr])* $name::$variant(_e) => _e.to_tokens($tokens),)
$tokens $name { $($next)* }
);
Expand Down

0 comments on commit fa5fb53

Please sign in to comment.