1 macro_rules
! ast_struct
{
4 struct $name
:ident
#full $($rest:tt)*
6 #[cfg(feature = "full")]
7 $
($attrs_pub
)* struct $name $
($rest
)*
9 #[cfg(not(feature = "full"))]
10 $
($attrs_pub
)* struct $name
{
11 _noconstruct
: ::std
::marker
::PhantomData
<::proc_macro2
::Span
>,
14 #[cfg(all(not(feature = "full"), feature = "printing"))]
15 impl ::quote
::ToTokens
for $name
{
16 fn to_tokens(&self, _
: &mut ::proc_macro2
::TokenStream
) {
24 struct $name
:ident $
($rest
:tt
)*
26 $
($attrs_pub
)* struct $name $
($rest
)*
30 strip_attrs_pub
!(ast_struct
!($
($t
)*));
34 macro_rules
! ast_enum
{
35 // Drop the `#no_visit` attribute, if present.
38 enum $name
:ident
#no_visit $($rest:tt)*
40 ast_enum
!([$
($attrs_pub
)*] enum $name $
($rest
)*);
45 enum $name
:ident $
($rest
:tt
)*
47 $
($attrs_pub
)* enum $name $
($rest
)*
51 strip_attrs_pub
!(ast_enum
!($
($t
)*));
55 macro_rules
! ast_enum_of_structs
{
57 $
(#[$enum_attr:meta])*
58 $
pub:ident $
enum:ident $name
:ident
#$tag:ident $body:tt
61 ast_enum
!($
(#[$enum_attr])* $pub $enum $name #$tag $body);
62 ast_enum_of_structs_impl
!($
pub $
enum $name $body $
($remaining
)*);
66 $
(#[$enum_attr:meta])*
67 $
pub:ident $
enum:ident $name
:ident $body
:tt
70 ast_enum
!($
(#[$enum_attr])* $pub $enum $name $body);
71 ast_enum_of_structs_impl
!($
pub $
enum $name $body $
($remaining
)*);
75 macro_rules
! ast_enum_of_structs_impl
{
77 $
pub:ident $
enum:ident $name
:ident
{
79 $
(#[$variant_attr:meta])*
80 $variant
:ident $
( ($
($member
:ident
)::+) )*,
86 check_keyword_matches
!(pub $
pub);
87 check_keyword_matches
!(enum $
enum);
90 ast_enum_from_struct
!($name
::$variant
, $
($member
)::+);
93 #[cfg(feature = "printing")]
98 $name { $($variant $($($member)::+)*,)* }
103 macro_rules
! ast_enum_from_struct
{
104 // No From<TokenStream> for verbatim variants.
105 ($name
:ident
::Verbatim
, $member
:ident
) => {}
;
107 // No From<TokenStream> for private variants.
108 ($name
:ident
::$variant
:ident
, crate::private
) => {}
;
110 ($name
:ident
::$variant
:ident
, $member
:ident
) => {
111 impl From
<$member
> for $name
{
112 fn from(e
: $member
) -> $name
{
119 #[cfg(feature = "printing")]
120 macro_rules
! generate_to_tokens
{
121 (do_not_generate_to_tokens $
($foo
:tt
)*) => ();
123 (($
($arms
:tt
)*) $tokens
:ident $name
:ident { $variant:ident, $($next:tt)*}
) => {
125 ($
($arms
)* $name
::$variant
=> {}
)
126 $tokens $name { $($next)* }
130 (($
($arms
:tt
)*) $tokens
:ident $name
:ident { $variant:ident $member:ident, $($next:tt)*}
) => {
132 ($
($arms
)* $name
::$
variant(_e
) => _e
.to_tokens($tokens
),)
133 $tokens $name { $($next)* }
137 (($
($arms
:tt
)*) $tokens
:ident $name
:ident { $variant:ident crate::private, $($next:tt)*}
) => {
139 ($
($arms
)* $name
::$
variant(_
) => unreachable
!(),)
140 $tokens $name { $($next)* }
144 (($
($arms
:tt
)*) $tokens
:ident $name
:ident {}
) => {
145 #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
146 impl ::quote
::ToTokens
for $name
{
147 fn to_tokens(&self, $tokens
: &mut ::proc_macro2
::TokenStream
) {
156 macro_rules
! strip_attrs_pub
{
157 ($mac
:ident
!($
(#[$m:meta])* $pub:ident $($t:tt)*)) => {
158 check_keyword_matches
!(pub $
pub);
160 $mac
!([$
(#[$m])* $pub] $($t)*);
164 macro_rules
! check_keyword_matches
{
165 (struct struct) => {}
;