@@ -5,6 +5,8 @@ pub(crate) struct Customize {
5
5
pub parse : bool ,
6
6
pub debug : bool ,
7
7
pub constructors : bool ,
8
+ pub fold : bool ,
9
+ pub visit : bool ,
8
10
}
9
11
10
12
impl syn:: parse:: Parse for Customize {
@@ -13,35 +15,36 @@ impl syn::parse::Parse for Customize {
13
15
14
16
let token_stream: TokenStream = input. parse ( ) ?;
15
17
let mut tokens = token_stream. into_iter ( ) ;
16
- while let Some ( token) = tokens. next ( ) {
17
- match token {
18
- proc_macro2:: TokenTree :: Ident ( ident) if ident == "parse" => {
19
- if result. parse {
20
- return Err ( syn:: Error :: new ( ident. span ( ) , "already customizing parse" ) ) ;
21
- }
22
- result. parse = true ;
23
- }
24
18
25
- proc_macro2:: TokenTree :: Ident ( ident) if ident == "debug" => {
26
- if result. debug {
27
- return Err ( syn:: Error :: new ( ident. span ( ) , "already customizing debug" ) ) ;
28
- }
29
- result. debug = true ;
30
- }
19
+ while let Some ( token) = tokens. next ( ) {
20
+ macro_rules! match_customization_field_or_error {
21
+ ( $( $ident: ident, ) * ) => {
22
+ match token {
23
+ $(
24
+ proc_macro2:: TokenTree :: Ident ( ident) if ident == stringify!( $ident) => {
25
+ if result. $ident {
26
+ return Err ( syn:: Error :: new( ident. span( ) , & format!( "already customizing {}" , stringify!( $ident) ) ) ) ;
27
+ }
28
+ result. $ident = true ;
29
+ }
30
+ ) *
31
31
32
- proc_macro2:: TokenTree :: Ident ( ident) if ident == "constructors" => {
33
- if result. constructors {
34
- return Err ( syn:: Error :: new ( ident. span ( ) , "already customizing debug" ) ) ;
32
+ _ => {
33
+ return Err ( syn:: Error :: new(
34
+ token. span( ) ,
35
+ "unexpected token in customization" ,
36
+ ) ) ;
37
+ }
35
38
}
36
- result . constructors = true ;
37
- }
39
+ } ;
40
+ }
38
41
39
- _ => {
40
- return Err ( syn :: Error :: new (
41
- token . span ( ) ,
42
- "unexpected token in customization" ,
43
- ) ) ;
44
- }
42
+ match_customization_field_or_error ! {
43
+ parse ,
44
+ debug ,
45
+ constructors ,
46
+ fold ,
47
+ visit ,
45
48
}
46
49
47
50
if let Some ( token) = tokens. next ( ) {
0 commit comments