blob: b4aec63e4c87c7fb7d26e0e3c3a42663b06e6c68 [file] [log] [blame]
Jason Macnakbbac34b2020-03-25 01:28:44 +00001use std::env;
2use std::fs::File;
3use std::io::Write;
4use std::iter;
5use std::path::Path;
6
7/*
8#[doc(hidden)]
9#[macro_export]
10macro_rules! count {
11 () => { proc_macro_call_0!() };
12 (!) => { proc_macro_call_1!() };
13 (!!) => { proc_macro_call_2!() };
14 ...
15}
16*/
17
18fn main() {
19 let out_dir = env::var("OUT_DIR").unwrap();
20 let dest_path = Path::new(&out_dir).join("count.rs");
21 let mut f = File::create(&dest_path).unwrap();
22
23 let mut content = String::new();
24 content += "
25 #[doc(hidden)]
26 #[macro_export]
27 macro_rules! count {
28 ";
29 for i in 0..=64 {
30 let bangs = iter::repeat("!").take(i).collect::<String>();
31 content += &format!("({}) => {{ proc_macro_call_{}!() }};", bangs, i);
32 }
33 content += "
34 ($(!)+) => {
35 compile_error!(\"this macro does not support >64 nested macro invocations\")
36 };
37 }
38 ";
39
40 f.write_all(content.as_bytes()).unwrap();
41}