From: Ian Jackson Date: Fri, 10 May 2024 12:35:16 +0000 (+0100) Subject: W X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=e8b76929858c5639c2b280139df2cea55c8e26cd;p=rust-experiments.git W --- diff --git a/macros/macros.rs b/macros/macros.rs index 70d8da7..8aa4032 100644 --- a/macros/macros.rs +++ b/macros/macros.rs @@ -8,7 +8,7 @@ pub fn dbg_dump(input: TokenStream) -> TokenStream { } #[proc_macro] -pub fn reconstruct_group(input: TokenStream) -> TokenStream { +pub fn reconstruct_groups(input: TokenStream) -> TokenStream { let mut output = TokenStream::new(); dbg!(&input); for tt in input { @@ -16,7 +16,8 @@ pub fn reconstruct_group(input: TokenStream) -> TokenStream { TokenTree::Group(g) => { let delim = g.delimiter(); dbg!(&delim); - TokenTree::Group(Group::new(delim, g.stream())) + let stream = reconstruct_groups(g.stream()); + TokenTree::Group(Group::new(delim, stream)) }, other => other, }; diff --git a/src/main.rs b/src/main.rs index 2dbd8ed..e44b451 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,12 +8,12 @@ macro_rules! one_plus_dbg { { $v:expr } => { dbg_dump!(1 + $v) } } macro_rules! one_plus_reconstruct { { $v:expr } => { - dbg_dump!(1 + reconstruct_group!($v)) + reconstruct_groups!(1 + $v) } } fn main() { println!("1 + (2<<3) should be 17"); -// println!("{} without proc_macro", one_plus!(2 << 3)); -// println!("{} dbg_dump", one_plus_dbg!(2 << 3)); + println!("{} without proc_macro", one_plus!(2 << 3)); + println!("{} dbg_dump", one_plus_dbg!(2 << 3)); println!("{} reconstruct", one_plus_reconstruct!(2 << 3)); }