1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// use proc_macro::TokenStream;
// use syn::*;
// use syn::ItemFn;
// use quote::*;
// /// https://docs.rs/syn/latest/syn/macro.parse_macro_input.html
// pub fn fn_proc_macro_impl(_input: TokenStream) -> TokenStream {
// let output_token_stream_str = "fn foo() -> u32 { 42 }";
// let output = output_token_stream_str.parse().unwrap();
// let ast_item_fn: ItemFn = parse_str::<ItemFn>(output_token_stream_str).unwrap();
// viz_ast(ast_item_fn);
// output
// }
// fn viz_ast(ast: ItemFn) {
// // Simply dump the AST to the console.
// let ast_clone = ast.clone();
// eprintln!("{} => {}", style_primary("Debug::ast"), ast_clone);
// // Parse AST to dump some items to the console.
// let ItemFn {
// attrs,
// vis,
// sig,
// block,
// } = ast;
// eprintln!(
// "{} ast_item_fn < attrs.len:{}, vis:{}, sig:'{}' stmt: '{}' >",
// style_primary("=>"),
// style_prompt(&attrs.len().to_string()),
// style_prompt(match vis {
// syn::Visibility::Public(_) => "public",
// syn::Visibility::Crate(_) => "crate",
// syn::Visibility::Restricted(_) => "restricted",
// syn::Visibility::Inherited => "inherited",
// }),
// style_prompt(&sig.ident.to_string()),
// style_prompt(&match block.stmts.first() {
// Some(stmt) => {
// let expr_str = stmt.to_token_stream().to_string().clone();
// expr_str
// }
// None => "empty".to_string(),
// }),
// );
// }