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
use ;
use Parser;
use ;
/// Build a [`moxy::token::TokenStream`] at runtime from a template, in the style
/// of `quote!`.
///
/// The macro expands to a block that constructs and returns a `TokenStream`.
/// Interpolations and control flow are evaluated against the surrounding scope:
///
/// - `{{ expr }}` splices the runtime value of `expr` (via [`moxy::token::ToTokens`]),
/// preserving its source spans.
/// - `@for (binding in iter) { … }`, `@if (cond) { … } @else { … }`, and
/// `@match (expr) { pat => { … }, … }` run as real control flow, appending to
/// the output as they execute.
///
/// # Example
///
/// ```ignore
/// let items = vec!["a", "b", "c"];
/// let tokens = template! {
/// @for (item in items) {
/// {{ item }}
/// }
/// };
/// assert_eq!(tokens.to_string(), "a b c");
/// ```
///
/// A malformed template produces a span-targeted compile error.
/// Concatenates the tokens inside each `{{ ... }}` marker into a single
/// identifier at compile time, passing all other tokens through unchanged.
///
/// Use it to mint identifier *names* in declaration position — something the
/// runtime [`moxy::token::ident!`] macro cannot do. Segments are taken by token
/// text (not evaluated), then validated as a Rust identifier.
///
/// # Example
///
/// ```ignore
/// paste! {
/// fn {{ get_ value }}() -> u32 { 7 } // expands to: fn get_value() -> u32 { 7 }
/// }
/// assert_eq!(get_value(), 7);
/// ```
///
/// A `{{ ... }}` that does not concatenate to a valid identifier produces a
/// span-targeted compile error.