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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
//! This module defines the diagnostic conditions that are reported while a
//! document is lowered for a backend (see [backends, lowering, and
//! outputs](crate::guide::concepts_overview#backends-lowering-and-outputs)).
//! The identifiers of most of these conditions begin with `flm.lowering.`.
//! Two conditions have other identifiers: [`ContentNotCharacters`]
//! (`flm.verbatim.content-not-characters`) and [`MathUnprocessed`]
//! (`flm.math.unprocessed`).
//!
//! Each of these conditions is reported as an Error diagnostic, and the
//! lowering then continues with the rest of the document. The lowering driver
//! ([`driver`](mod@super::driver)) handles a problem in one of two ways:
//!
//! - **At one node.** The node is replaced by a `flm.pres.unsupported` node
//! without children, the error is reported at the node, and the rest of
//! the tree is lowered as usual. [`UnsupportedElement`], [`NoRule`],
//! [`RuleFailed`] and [`RegionNotFound`] are handled this way.
//! - **For the whole tree.** The lowering of the tree stops, and the error is
//! reported at the root of the tree. The tree has no entry in the table of
//! lowered trees of the backend ([`LoweredTrees`](super::LoweredTrees)), so
//! the backend writes no output for this tree. [`RoundsExceeded`],
//! [`NestingTooDeep`] and [`LoweringFailed`] are handled this way.
//!
//! The other three conditions, [`FieldNotRead`], [`ContentNotCharacters`] and
//! [`MathUnprocessed`], are reported by lowering rules. The documentation of
//! each of them states what is written in place of the content.
use DiagnosticInfo;
/// The error that is reported when a document contains an element that the
/// backend cannot render (`flm.lowering.unsupported-element`).
///
/// A backend cannot render an element when it neither writes the element
/// natively nor has a lowering rule for it. If a document can contain such
/// an element, building the plan for the backend fails
/// ([`PlanError::Incomplete`](crate::core::plan::PlanError::Incomplete)),
/// unless the element is listed for this backend in
/// [`PlanRequest::unsupported`](crate::core::plan::PlanRequest#structfield.unsupported).
/// In that case the plan builds, and this error is reported for each
/// occurrence of the element in the document.
///
/// Reported by the lowering driver at each node of the element. The node is
/// replaced by a `flm.pres.unsupported` node without children, so its
/// content does not appear in the output.
///
/// An element that the backend cannot render and that is not listed in
/// `PlanRequest::unsupported` is reported as [`NoRule`].
/// The error that is reported when a lowering rule fails at a node
/// (`flm.lowering.rule-failed`).
///
/// A lowering rule fails when it returns a
/// [`LowerError`](crate::core::lowering::LowerError). This error is usually
/// caused by a fault of the rule. For instance, the rule reads a table or an
/// option that it did not declare, stages a presentation element that is not
/// listed in its `produces` declaration, or finds a node structure that it
/// does not expect. A rule also fails when a [synthesized
/// value](crate::guide::concepts_overview#synthesized-values) that it splices
/// ([`Lowerer::splice`](crate::core::lowering::Lowerer::splice)) cannot be
/// brought up to date.
///
/// Reported by the lowering driver at the node. The node is replaced by a
/// `flm.pres.unsupported` node without children.
///
/// Some kinds of `LowerError` are handled differently:
///
/// - [`LowerError::Refused`](crate::core::lowering::LowerError::Refused): the
/// diagnostic that the error contains is reported in place of this error,
/// and the node is replaced in the same way. A rule returns this error to
/// report a problem of the document in terms that the author can act on,
/// as the user-definitions feature does with
/// [`KeptTemplateDeclaresPoint`](crate::stdlib::features::userdefs::kept::KeptTemplateDeclaresPoint).
/// - [`LowerError::RegionNotFound`](crate::core::lowering::LowerError::RegionNotFound)
/// is reported as [`RegionNotFound`].
/// - [`LowerError::Build`](crate::core::lowering::LowerError::Build) stops the
/// lowering of the whole tree, and is reported as [`LoweringFailed`].
/// The error that is reported when a lowering rule calls
/// [`Lowerer::lower_region`](crate::core::lowering::Lowerer::lower_region)
/// for a node region that does not exist (id
/// `flm.lowering.region-not-found`).
///
/// A node region is an argument or a content slot of a node
/// ([`NodeRegion`](crate::core::lowering::NodeRegion)). A rule calls
/// `lower_region` to lower a node region of another node at the position of
/// its own node, for instance the content that a
/// [`ContentPointer`](super::ContentPointer) refers to. The node region does
/// not exist when no document tree and no synthesized value that is being
/// lowered has the given tree identifier, when that tree has no node at the
/// given address, or when the node has no such argument or slot.
///
/// A document cannot cause this error: it is caused by the stage or the rule
/// that created the reference to the node region, for instance a stage that
/// built a synthesized value containing a content pointer.
///
/// Reported by the lowering driver at the node whose rule called
/// `lower_region`. The node is replaced by a `flm.pres.unsupported` node
/// without children. The function
/// [`lower_content_pointer`](super::lower_content_pointer) handles this error
/// differently: it reports the error at the content pointer node and returns
/// an empty list of staged nodes, so that the content pointer node is not
/// replaced.
/// The error that is reported when the lowering reaches a node of an element
/// that the backend cannot render and that is not listed as unrenderable in
/// the plan request (id `flm.lowering.no-rule`).
///
/// The backend does not write the element natively, and no lowering rule is
/// selected for the element. Building the plan checks that the backend can
/// render every element that can occur in a document
/// ([`FlmRegistry::occurrable_elements`](crate::core::registry::FlmRegistry::occurrable_elements)).
/// This error can therefore occur only for an element that this check does
/// not cover, for instance a template placeholder that remains in the tree
/// after the expansion of user definitions.
///
/// A document cannot cause this error: it is caused by a fault of the
/// program, in a feature, a rewrite or an extension. This is the difference
/// from [`UnsupportedElement`], which is reported for an element that the
/// plan request lists as unrenderable, and whose message is addressed to the
/// author of the document.
///
/// Reported by the lowering driver at the node. The node is replaced by a
/// `flm.pres.unsupported` node without children.
/// The error that is reported when the lowering of a tree reaches the maximum
/// number of rounds and the tree still contains elements that the backend
/// does not write natively (id `flm.lowering.rounds-exceeded`).
///
/// The lowering rewrites a tree in rounds. Each round applies the selected
/// lowering rules to the nodes of the elements that the backend does not
/// write natively, and the next round processes the resulting tree. The
/// maximum number of rounds is computed from the `produces` declarations of
/// the selected rules ([`rank`](super::rank)).
///
/// This error indicates a fault of a lowering rule. For instance, a rule that
/// returns [`Lowering::Default`](crate::core::lowering::Lowering::Default) for
/// an element that the backend does not write natively leaves the element in
/// the tree for the next round.
///
/// Reported by the lowering driver at the root of the tree. The tree has no
/// lowered form.
/// The error that is reported when the lowering of a tree fails as a whole
/// (`flm.lowering.failed`).
///
/// This happens when an error that cannot be handled at one node occurs
/// during the lowering, such as
/// [`LowerError::Build`](crate::core::lowering::LowerError::Build) for a node
/// that cannot be built. It also happens when the lowered tree cannot be
/// stored in the table of lowered trees of the backend
/// ([`LoweredTrees`](super::LoweredTrees)).
///
/// Reported at the root of the tree, by the lowering driver or by the
/// lowering stage ([`LoweringStage`](super::LoweringStage)). The tree has no
/// lowered form.
/// The error that is reported when a tree is nested too deeply to be lowered
/// (`flm.lowering.nesting-too-deep`).
///
/// The lowering walks the tree recursively. The recursion guard limits the
/// depth of every recursive walk of a tree in the library (see [the recursion
/// guard and worker
/// threads](crate::guide::concepts_overview#the-recursion-guard-and-worker-threads)).
/// This error is reported when the guard does not allow the lowering to
/// descend one more level. The other walks report conditions of their own:
/// parsing and the rewrites report `flm.blocks.nesting-too-deep`, and
/// bringing a synthesized value up to date reports
/// `flm.synth.nesting-too-deep`.
///
/// Reported by the lowering driver at the root of the tree. The tree has no
/// lowered form.
/// The error that is reported when a field reaches the lowering
/// (`flm.lowering.field-not-read`).
///
/// A field is a macro that a construct absorbs as data, not as content, such
/// as a `\label` written after a heading or a `\tag` on an equation line (see
/// [fields: data a construct
/// reads](crate::guide::concepts_overview#fields-data-a-construct-reads)).
/// The fields of a construct are read by the feature that defines the
/// construct, and the lowering rule of the construct must not lower them. A
/// field that reaches the lowering has therefore not been read.
///
/// A document cannot cause this error: it is caused by the lowering rule of
/// the construct that absorbed the field.
///
/// Reported by [`FieldRule`](super::FieldRule), the lowering rule of fields
/// on every backend, at the field. The field expands to nothing.
/// The error that is reported when the content of a verbatim region is not
/// plain characters (`flm.verbatim.content-not-characters`).
///
/// A verbatim region is text in which no character has a markup meaning, such
/// as the argument of `\verbcode` (see [verbatim
/// regions](crate::guide::concepts_overview#verbatim-regions)). Its content
/// is plain characters when it consists only of text, comments and brace
/// groups whose content is plain characters in turn. A brace group
/// contributes its content without the braces.
///
/// The text that an author writes in a verbatim region is always plain
/// characters. Other content gets there through a user definition whose
/// template places one of its arguments in a verbatim region. A call of
/// such a definition must pass plain characters in this argument. For
/// instance, if the template of `\code` is `\verbcode{#1}`, the call can be
/// `\code{x = y + 1}`.
///
/// Reported by [`read_verbatim_content`](super::read_verbatim_content), which
/// every lowering rule that stages verbatim content calls, at the command or
/// environment that contains the verbatim region. The verbatim region then
/// contains the source text of its whole content, markup included, as
/// characters. The same happens on every backend.
/// The error that is reported when a math group or a display-math
/// environment is lowered on a backend for which no feature processes
/// mathematics (id `flm.math.unprocessed`).
///
/// A math group is mathematics written as `\(…\)`, `$…$` or `\[…\]`. Math
/// groups and display-math environments are lowered by the rules of a
/// feature that processes mathematics, for example the feature of the
/// package [`math-passthrough`](crate::math_passthrough). When no such rule
/// is registered for the backend, the mathematics is lowered by a rule of
/// last resort, which reports this error. A rule of last resort is selected
/// only when it is the only rule for the element on the backend. The rule of
/// last resort is [`MathGroupRule`](super::MathGroupRule) for a math group,
/// and
/// [`UnprocessedEnvironmentRule`](crate::stdlib::features::math::unprocessed::UnprocessedEnvironmentRule)
/// of the `math` feature for a display-math environment.
///
/// Reported at each math group or display-math environment that a rule of
/// last resort lowers. The content of the mathematics is lowered as ordinary
/// content, inside a `flm.pres.span` node of role `flm.math` and kind
/// `inline` or `display`.
;