wiwi_macro_proc/
with_cloned.rs

1// use proc_macro2::{ Group, Ident, Spacing, Span, TokenStream, TokenTree };
2use proc_macro2::{ Spacing, Span, TokenStream, TokenTree };
3// use quote::quote;
4use syn::Error;
5// use syn::parse::Parse;
6
7pub fn with_cloned(input: TokenStream) -> Result<TokenStream, TokenStream> {
8	let mut iter = input.into_iter();
9
10	loop {
11		match iter.next() {
12			Some(TokenTree::Ident(ident)) => {
13				match &*ident.to_string() {
14					"_" => {
15						match iter.next() {
16							Some(TokenTree::Punct(punct)) if punct.as_char() == '=' && punct.spacing() == Spacing::Joint => { /* ok */ }
17							Some(tt) => {
18								return Err(Error::new_spanned(tt, "unexpected token").into_compile_error())
19							}
20							None => {
21								return Err(Error::new(Span::call_site(), "unexpected end of macro input").into_compile_error())
22							}
23						}
24						match iter.next() {
25							Some(TokenTree::Punct(punct)) if punct.as_char() == '>' && punct.spacing() == Spacing::Alone => { /* ok */ }
26							Some(tt) => {
27								return Err(Error::new_spanned(tt, "unexpected token").into_compile_error())
28							}
29							None => {
30								return Err(Error::new(Span::call_site(), "unexpected end of macro input").into_compile_error())
31							}
32						}
33					}
34					"mut" => {
35					}
36					_ident => {}
37				}
38				// return Err(Error::new_spanned(ident, &*hh).into_compile_error())
39			}
40
41			Some(TokenTree::Group(_group)) => {}
42
43			Some(TokenTree::Punct(_punct)) => {
44				// return Error::new_spanned(
45				// 	punct,
46				// 	"unexpected token"
47				// ).into_compile_error()
48			}
49
50			Some(TokenTree::Literal(_literal)) => {
51				// return Err(Error::new_spanned(
52				// 	literal,
53				// 	"unexpected literal"
54				// ).into_compile_error())
55			}
56
57			None => {
58				return Err(Error::new(
59					Span::call_site(),
60					"unexpected end of macro invocation"
61				).into_compile_error())
62			}
63		}
64	}
65}