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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//! **Quip** adds expression interpolation to several quasi-quoting macros:
//!
//! - [`quote::quote!`] → [`quip!`]
//! - [`quote::quote_spanned!`] → [`quip_spanned!`]
//! - [`syn::parse_quote!`] → [`parse_quip!`]
//! - [`syn::parse_quote_spanned!`] → [`parse_quip_spanned!`]
//!
//! # Setup
//!
//! Add this to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! quip = "0.2.0"
//! quote = "1" # For `quip!` and `quip_spanned!`.
//! syn = "2" # For `parse_quip!` and `parse_quip_spanned!`.
//! ```
//!
//! # Syntax
//!
//! All Quip macros use `#{...}` for expression interpolation, where `...` must
//! evaluate to a type implementing [`quote::ToTokens`]. All other aspects,
//! including repetition and hygiene, behave identically to the underlying
//! macro.
//!
//! ```
//! # {} /*
//! quip! {
//! impl Clone for #{item.name} {
//! fn clone(&self) -> Self {
//! Self {
//! #(#{item.members}: self.#{item.members}.clone(),)*
//! }
//! }
//! }
//! }
//! # */
//! ```
//!
//! # Behind the Scenes
//!
//! Quip scans tokens and transforms each expression interpolation `#{...}` into
//! a variable interpolation `#...` by binding the expression to a temporary
//! variable. The macro then passes the transformed tokens to the underlying
//! quasi-quotation macro.
//!
//! ```
//! # {} /*
//! quip! {
//! impl MyTrait for #{item.name} {}
//! }
//! # */
//! ```
//!
//! The code above expands to:
//!
//! ```
//! # {} /*
//! match (&item.name,) {
//! (__interpolation0,) => {
//! ::quote::quote! {
//! impl MyTrait for #__interpolation0 {}
//! }
//! }
//! }
//! # */
//! ```
//!
//! [`quote::quote!`]: https://docs.rs/quote/latest/quote/macro.quote.html
//! [`quote::quote_spanned!`]: https://docs.rs/quote/latest/quote/macro.quote_spanned.html
//! [`syn::parse_quote!`]: https://docs.rs/syn/latest/syn/macro.parse_quote.html
//! [`syn::parse_quote_spanned!`]: https://docs.rs/syn/latest/syn/macro.parse_quote_spanned.html
//!
//! [`quote::ToTokens`]: https://docs.rs/quote/latest/quote/trait.ToTokens.html
use TokenStream;
use quote;
/// Adds expression interpolation to [`quote::quote!`].
///
/// # Setup
///
/// This macro requires the [`quote`] crate as an additional dependency. Add
/// this to your `Cargo.toml`:
///
/// ```toml
/// [dependencies]
/// quip = "0.2.0"
/// quote = "1"
/// ```
///
/// [`quote::quote!`]: https://docs.rs/quote/latest/quote/macro.quote.html
/// [`quote`]: https://crates.io/crates/quote
/// Adds expression interpolation to [`quote::quote_spanned!`].
///
/// # Setup
///
/// This macro requires the [`quote`] crate as an additional dependency. Add
/// this to your `Cargo.toml`:
///
/// ```toml
/// [dependencies]
/// quip = "0.2.0"
/// quote = "1"
/// ```
///
/// [`quote::quote_spanned!`]: https://docs.rs/quote/latest/quote/macro.quote_spanned.html
/// [`quote`]: https://crates.io/crates/quote
/// Adds expression interpolation to [`syn::parse_quote!`].
///
/// # Setup
///
/// This macro requires the [`syn`] crate as an additional dependency. Add this
/// to your `Cargo.toml`:
///
/// ```toml
/// [dependencies]
/// quip = "0.2.0"
/// syn = "2"
/// ```
///
/// [`syn::parse_quote!`]: https://docs.rs/syn/latest/syn/macro.parse_quote.html
/// [`syn`]: https://crates.io/crates/syn
/// Adds expression interpolation to [`syn::parse_quote_spanned!`].
///
/// # Setup
///
/// This macro requires the [`syn`] crate as an additional dependency. Add this
/// to your `Cargo.toml`:
///
/// ```toml
/// [dependencies]
/// quip = "0.2.0"
/// syn = "2"
/// ```
///
/// [`syn::parse_quote_spanned!`]: https://docs.rs/syn/latest/syn/macro.parse_quote_spanned.html
/// [`syn`]: https://crates.io/crates/syn