1 macro_rules
! ast_struct
{
4 struct $name
:ident
#full $($rest:tt)*
6 #[cfg(feature = "full")]
7 #[cfg_attr(feature = "extra-traits", derive(Debug, Eq, PartialEq, Hash))]
8 #[cfg_attr(feature = "clone-impls", derive(Clone))]
9 $
($attrs_pub
)* struct $name $
($rest
)*
11 #[cfg(not(feature = "full"))]
12 #[cfg_attr(feature = "extra-traits", derive(Debug, Eq, PartialEq, Hash))]
13 #[cfg_attr(feature = "clone-impls", derive(Clone))]
14 $
($attrs_pub
)* struct $name
{
18 #[cfg(all(not(feature = "full"), feature = "printing"))]
19 impl ::quote
::ToTokens
for $name
{
20 fn to_tokens(&self, _
: &mut ::proc_macro2
::TokenStream
) {
28 struct $name
:ident
#manual_extra_traits $($rest:tt)*
30 #[cfg_attr(feature = "extra-traits", derive(Debug))]
31 #[cfg_attr(feature = "clone-impls", derive(Clone))]
32 $
($attrs_pub
)* struct $name $
($rest
)*
37 struct $name
:ident
#manual_extra_traits_debug $($rest:tt)*
39 #[cfg_attr(feature = "clone-impls", derive(Clone))]
40 $
($attrs_pub
)* struct $name $
($rest
)*
45 struct $name
:ident $
($rest
:tt
)*
47 #[cfg_attr(feature = "extra-traits", derive(Debug, Eq, PartialEq, Hash))]
48 #[cfg_attr(feature = "clone-impls", derive(Clone))]
49 $
($attrs_pub
)* struct $name $
($rest
)*
53 strip_attrs_pub
!(ast_struct
!($
($t
)*));
57 macro_rules
! ast_enum
{
58 // Drop the `#no_visit` attribute, if present.
61 enum $name
:ident
#no_visit $($rest:tt)*
63 ast_enum
!([$
($attrs_pub
)*] enum $name $
($rest
)*);
68 enum $name
:ident
#manual_extra_traits $($rest:tt)*
70 #[cfg_attr(feature = "extra-traits", derive(Debug))]
71 #[cfg_attr(feature = "clone-impls", derive(Clone))]
72 $
($attrs_pub
)* enum $name $
($rest
)*
77 enum $name
:ident $
($rest
:tt
)*
79 #[cfg_attr(feature = "extra-traits", derive(Debug, Eq, PartialEq, Hash))]
80 #[cfg_attr(feature = "clone-impls", derive(Clone))]
81 $
($attrs_pub
)* enum $name $
($rest
)*
85 strip_attrs_pub
!(ast_enum
!($
($t
)*));
89 macro_rules
! ast_enum_of_structs
{
91 $
(#[$enum_attr:meta])*
92 $
pub:ident $
enum:ident $name
:ident
#$tag:ident $body:tt
95 ast_enum
!($
(#[$enum_attr])* $pub $enum $name #$tag $body);
96 ast_enum_of_structs_impl
!($
pub $
enum $name $body $
($remaining
)*);
100 $
(#[$enum_attr:meta])*
101 $
pub:ident $
enum:ident $name
:ident $body
:tt
104 ast_enum
!($
(#[$enum_attr])* $pub $enum $name $body);
105 ast_enum_of_structs_impl
!($
pub $
enum $name $body $
($remaining
)*);
109 macro_rules
! ast_enum_of_structs_impl
{
111 $
pub:ident $
enum:ident $name
:ident
{
113 $
(#[$variant_attr:meta])*
114 $variant
:ident $
( ($member
:ident
) )*,
120 check_keyword_matches
!(pub $
pub);
121 check_keyword_matches
!(enum $
enum);
124 ast_enum_from_struct
!($name
::$variant
, $member
);
127 #[cfg(feature = "printing")]
128 generate_to_tokens
! {
132 $name { $($variant $($member)*,)* }
137 macro_rules
! ast_enum_from_struct
{
138 // No From<TokenStream> for verbatim variants.
139 ($name
:ident
::Verbatim
, $member
:ident
) => {}
;
141 ($name
:ident
::$variant
:ident
, $member
:ident
) => {
142 impl From
<$member
> for $name
{
143 fn from(e
: $member
) -> $name
{
150 #[cfg(feature = "printing")]
151 macro_rules
! generate_to_tokens
{
152 (do_not_generate_to_tokens $
($foo
:tt
)*) => ();
154 (($
($arms
:tt
)*) $tokens
:ident $name
:ident { $variant:ident, $($next:tt)*}
) => {
156 ($
($arms
)* $name
::$variant
=> {}
)
157 $tokens $name { $($next)* }
161 (($
($arms
:tt
)*) $tokens
:ident $name
:ident { $variant:ident $member:ident, $($next:tt)*}
) => {
163 ($
($arms
)* $name
::$
variant(_e
) => _e
.to_tokens($tokens
),)
164 $tokens $name { $($next)* }
168 (($
($arms
:tt
)*) $tokens
:ident $name
:ident {}
) => {
169 impl ::quote
::ToTokens
for $name
{
170 fn to_tokens(&self, $tokens
: &mut ::proc_macro2
::TokenStream
) {
179 macro_rules
! strip_attrs_pub
{
180 ($mac
:ident
!($
(#[$m:meta])* $pub:ident $($t:tt)*)) => {
181 check_keyword_matches
!(pub $
pub);
183 $mac
!([$
(#[$m])* $pub] $($t)*);
187 macro_rules
! check_keyword_matches
{
188 (struct struct) => {}
;