Jason Macnak | bbac34b | 2020-03-25 01:28:44 +0000 | [diff] [blame^] | 1 | use std::env; |
| 2 | use std::fs::File; |
| 3 | use std::io::Write; |
| 4 | use std::iter; |
| 5 | use std::path::Path; |
| 6 | |
| 7 | /* |
| 8 | #[doc(hidden)] |
| 9 | #[macro_export] |
| 10 | macro_rules! count { |
| 11 | () => { proc_macro_call_0!() }; |
| 12 | (!) => { proc_macro_call_1!() }; |
| 13 | (!!) => { proc_macro_call_2!() }; |
| 14 | ... |
| 15 | } |
| 16 | */ |
| 17 | |
| 18 | fn 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 | } |