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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#![recursion_limit = "128"]
#![feature(proc_macro)]
#[macro_use]
extern crate quote;
#[macro_use]
extern crate syn;
extern crate proc_macro;
extern crate proc_macro2;
mod args;
mod parser;
use proc_macro::TokenStream;
use syn::punctuated::Punctuated;
#[derive(Debug, Clone)]
struct KvPair(syn::Ident, syn::Expr);
#[derive(Debug, Clone)]
struct Opt(Punctuated<KvPair, Token![,]>);
#[derive(Debug, Clone)]
struct List(Punctuated<syn::Expr, Token![,]>);
#[derive(Debug, Clone)]
struct Args(Punctuated<Arg, Token![,]>);
#[derive(Debug, Clone)]
struct ToComma(proc_macro2::TokenStream);
#[derive(Debug, Clone)]
enum Arg {
Expr(syn::Expr),
Opt(Opt),
Bad(ToComma),
}
#[proc_macro]
pub fn args(input: TokenStream) -> TokenStream {
let body = if input.is_empty() {
quote! { Term::new() }
} else {
args::process(input)
};
let expanded = quote!({
#[allow(unused_imports)]
use reql::{Term, IntoArg, Arg};
#body
});
expanded.into()
}