chiark / gitweb /
W
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 10 May 2024 12:35:16 +0000 (13:35 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 10 May 2024 12:35:16 +0000 (13:35 +0100)
macros/macros.rs
src/main.rs

index 70d8da7d583cf02f93ee2794586ebe6179715c9e..8aa40328c23a8982d94a95dd79139da3c29358b3 100644 (file)
@@ -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,
         };
index 2dbd8ed3956a431ae055db0174d3c377bf9b7f8b..e44b451ce42dd84dba6cb04a3d969be207cff472 100644 (file)
@@ -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));
 }