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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
use crateContext;
use crateArgument;
use crateDirectiveError;
use Cow;
/// A template directive that can be executed to produce output.
///
/// Directives are the executable components of a compiled template. Each directive
/// represents a unit of work that can be performed during template rendering, such as:
/// - Outputting literal text
/// - Substituting variable values
/// - Repeating patterns
/// - Conditional branching
///
/// Directives are trait objects stored in the compiled template and executed
/// sequentially during the `format` operation.
/// A directive that produces no output.
///
/// Used as a placeholder when parsing encounters an empty or invalid expression
/// that should be silently ignored rather than causing a compilation error.
///
/// # Examples
///
/// An empty directive always returns an empty string regardless of context.
;
/// A directive that outputs a literal string.
///
/// This is used for the static portions of a template that don't involve
/// any variable substitution or dynamic behavior. The string is stored
/// as a `Cow` to enable zero-copy when possible.
///
/// # Examples
///
/// ```text
/// Template: "Hello {name}!"
/// Produces three directives:
/// 1. LiteralDirective("Hello ")
/// 2. ReplaceDirective(name)
/// 3. LiteralDirective("!")
/// ```
;
/// A directive that substitutes a variable or evaluates an expression.
///
/// This is the most common directive type, used for simple variable replacement
/// like `{name}` or literal values like `{"hello"}`.
///
/// # Examples
///
/// ```text
/// Template: "{username}"
/// With context: username = "Alice"
/// Produces: "Alice"
/// ```
///
/// # Errors
///
/// Returns an error if the argument cannot be resolved (e.g., variable not found).
;
/// A directive that repeats a pattern a specified number of times.
///
/// Syntax: `{pattern:count}` where:
/// - `pattern` is the string to repeat (variable or literal)
/// - `count` is the number of repetitions (variable or literal integer)
///
/// # Examples
///
/// ```text
/// Template: "{'*':3}"
/// Produces: "***"
///
/// Template: "{char:n}"
/// With context: char = "-", n = 5
/// Produces: "-----"
/// ```
///
/// # Errors
///
/// Returns an error if:
/// - The pattern argument cannot be resolved to a string
/// - The count argument cannot be resolved to an integer
;
/// A directive that performs conditional branching (ternary operator).
///
/// Evaluates a condition and returns one of two values based on the result.
/// Syntax: `{condition ? true_value : false_value}`
///
/// The condition can be:
/// - A boolean variable
/// - A boolean literal
/// - A comparison expression (e.g., `x == 5`, `a > b`)
/// - A NOT expression (e.g., `!active`)
///
/// # Examples
///
/// ```text
/// Template: "{active ? 'yes' : 'no'}"
/// With context: active = true
/// Produces: "yes"
///
/// Template: "{count > 0 ? 'items' : 'empty'}"
/// With context: count = 5
/// Produces: "items"
/// ```
///
/// # Errors
///
/// Returns an error if:
/// - The condition cannot be resolved to a boolean
/// - The selected branch argument cannot be resolved