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
//! This module defines the diagnostic conditions of the [`cells`](super)
//! feature, which provides tables of cells. Their identifiers have the form
//! `flm.cells.<condition>`. Every condition is an error.
//!
//! The lowering rule of the `cells` environment reads the table with
//! [`read_grid`](super::read_grid), which finds the mistakes in the table.
//! Both the general rule [`CellsRule`](super::lower::CellsRule) and the rule
//! [`CellsLatexRule`](super::latex::CellsLatexRule) of the `latex-recomposed`
//! backend report these mistakes each time they lower the table, so a
//! document gets the same reports on every backend. Each mistake causes only
//! a part of the table to be ignored or left out, and the rest of the table
//! is written as usual. The lowering rule [`OutsideRule`](super::lower::OutsideRule)
//! reports [`OutsideTable`] for a command of a table of cells that is written
//! outside of its place.
//!
//! These conditions are reported only when a table is lowered. The `check`
//! workflow ([`CHECK_WORKFLOW`](crate::stdlib::CHECK_WORKFLOW)) lowers no
//! table, and therefore does not report them.
//!
//! When a part of the document is left out of the output, the lowering rule
//! places a *dropped mark* in the output: a `flm.pres.dropped` node
//! ([`DroppedPayload`](crate::stdlib::backends::pres::DroppedPayload)),
//! which shows the reader of the output that something was left out. The
//! dropped marks for the mistakes in a table are placed immediately before
//! the table.
use DiagnosticInfo;
/// The error that is reported when the body of a `cells` environment contains
/// content outside of a cell (`flm.cells.content-outside-cell`).
///
/// The body of a `cells` environment may contain only the commands `\cell`,
/// `\celldata`, `\\`, `\rownames` and `\colnames`, together with whitespace,
/// blank lines and comments. Text and other content belong in a cell: in the
/// content of a `\cell`, as in `\cell{Some text}`, or in an entry of the data
/// of a `\celldata`, as in `\celldata{Some text & More text}`.
///
/// Reported by the lowering rule of the `cells` environment, on every
/// backend, at the content. The content is left out of the output, and a
/// dropped mark (`flm.pres.dropped`) is placed immediately before the table.
;
/// The error that is reported when the placement of a `\cell` or the mapping
/// of a `\celldata` is not valid (`flm.cells.bad-placement`).
///
/// The placement of a `\cell` is its optional argument `[…]`. It has the form
/// `[COL]` or `[ROW;COL]`. Each part is a number, a name declared with
/// `\rownames` or `\colnames`, `.` or nothing for the current row or column,
/// or `\merge{RANGE}` for a cell that spans several rows or columns, as in
/// `\cell[2;3]{…}` or `\cell[1;\merge{3-4}]{…}`.
///
/// The mapping of a `\celldata` is its optional argument `[…]`. It has the
/// form `[COLS]` or `[ROWS;COLS]`. Each part is a comma-separated list of
/// numbers, names, ranges and `\merge{RANGE}`, as in
/// `\celldata[3,2,1]{A & B & C}` or `\celldata[2-5]{A & B & C & D}`.
///
/// A range has the form `2-4`, or `2+3` for three rows or columns starting
/// at 2. Inside `\merge`, a range can also be a contiguous union such as
/// `1,2,3`.
/// Rows and columns are numbered from 1, and a number may be at most
/// [`MAX_CELLS_POSITIONS`](crate::stdlib::backends::pres::MAX_CELLS_POSITIONS).
/// The [documentation of the `cells` feature](super#placements-mappings-and-ranges)
/// describes placements, mappings and ranges in full.
///
/// Reported by the lowering rule of the `cells` environment, on every
/// backend, at the `\cell` or the `\celldata`. The message states what is
/// wrong. An invalid placement is ignored: the cell goes to the current row
/// and column, or, for a `\cell` that is an entry of a `\celldata`, to the
/// position of that entry. An invalid mapping is ignored as a whole, and the
/// data of the `\celldata` is placed from the current row and column on.
/// The error that is reported when the style argument `<…>` of a `\cell` or
/// a `\celldata` contains content other than text (`flm.cells.bad-styles`).
///
/// The style argument contains style tokens separated by whitespace. A style
/// token is the name of a cell style, optionally followed by a value in
/// braces, as in `\cell<H align{left}>{…}`. In a `\celldata`, commas separate
/// the tokens of successive entries of a row, as in
/// `\celldata<H l, H c>{One & Two}`. A token that is not the name of a cell
/// style is reported as [`UnknownStyle`].
///
/// Reported by the lowering rule of the `cells` environment, on every
/// backend, at the `\cell` or the `\celldata`. The whole style argument is
/// ignored.
;
/// The error that is reported when a style token is not the name of a cell
/// style declared in the registry (`flm.cells.unknown-style`).
///
/// Each style token of a `\cell` or a `\celldata` refers to a cell style
/// ([`CellStyle`](super::CellStyle)) by its name, as in `\cell<H l>{…}`. The
/// cell styles of a registry are the ones that the `cells` feature ships
/// ([`shipped`](super::shipped)), and the ones that other features contribute
/// to the service slot [`STYLES_SLOT`](super::STYLES_SLOT).
///
/// Reported by the lowering rule of the `cells` environment, on every
/// backend, at the token. The token is ignored, and the other tokens of the
/// cell are used.
/// The error that is reported when a style token has a missing or an invalid
/// value (`flm.cells.bad-style-value`).
///
/// A value is written in braces directly after the name of a cell style, and
/// each style name takes at most one value. A cell style of the structural
/// form ([`StyleForm::Structural`](super::StyleForm::Structural)) requires
/// one of the values of its [`Parameter`](super::Parameter), as in
/// `align{left}`, `head{column}` or `rule{below}`. A cell style of the fixed
/// form ([`StyleForm::Fixed`](super::StyleForm::Fixed)), such as `l`, `H` or
/// `green`, takes no value.
///
/// Reported by the lowering rule of the `cells` environment, on every
/// backend, at the token. The token is ignored, and the other tokens of the
/// cell are used. A value that does not follow a style name is reported at
/// the value, and ignored.
/// The error that is reported when an entry of `\rownames` or `\colnames` is
/// not valid (`flm.cells.bad-names`).
///
/// The argument of `\rownames` or `\colnames` is a comma-separated list of
/// names. The *k*-th entry is the name of row or column *k*, and an empty
/// entry gives no name, as in `\colnames{name,,city}`. A name begins with an
/// ASCII letter and contains only ASCII letters, digits and underscores. Each
/// row name and each column name may be declared only once, and each row or
/// column may have only one name.
///
/// Reported by the lowering rule of the `cells` environment, on every
/// backend, at the `\rownames` or the `\colnames`, once for each invalid
/// entry. The message states what is wrong. The invalid entry is ignored, and
/// the other entries are used.
/// The error that is reported when a cell covers a position that is already
/// covered by a cell earlier in the body of the table (`flm.cells.overlap`).
///
/// Each position of a table belongs to at most one cell. A cell covers more
/// than one position when it spans several rows or columns with `\merge`, as
/// in `\cell[1;\merge{3-4}]{…}`. When the data of a `\celldata` has more
/// entries than its mapping lists, the remaining entries are placed at the
/// last row or column of the mapping, where they overlap. An open last range,
/// as in `\celldata[2-]{…}`, instead continues one row or column per entry.
///
/// Reported by the lowering rule of the `cells` environment, on every
/// backend, at the later cell. The message gives the position of the earlier
/// cell. The later cell is left out of the output together with its content,
/// and a dropped mark (`flm.pres.dropped`) is placed immediately before the
/// table.
/// The error that is reported when a cell would make its table larger than
/// the largest size allowed (`flm.cells.too-large`).
///
/// The size of a table is its number of rows times its number of columns,
/// counted in positions. A table may have at most
/// [`MAX_CELLS_POSITIONS`](crate::stdlib::backends::pres::MAX_CELLS_POSITIONS)
/// positions (one million). This limit exists because each backend visits
/// every position of a table when it writes the table, and a single `\merge`
/// can span a very large number of rows or columns.
///
/// Reported by the lowering rule of the `cells` environment, on every
/// backend, at the cell. The cell is left out of the output together with its
/// content, and a dropped mark (`flm.pres.dropped`) is placed immediately
/// before the table.
/// The error that is reported when a `cells` environment contains no cell
/// (`flm.cells.empty`).
///
/// An empty entry of a `\celldata` adds no cell. A table also counts as empty
/// when every one of its cells is left out because it would make the table
/// too large ([`TooLarge`]).
///
/// Reported by the lowering rule of the `cells` environment, on every
/// backend, at the environment. Nothing is written for the table, except the
/// dropped marks for the parts of the table that were left out.
;
/// The error that is reported when a command of a table of cells is written
/// outside of its place (`flm.cells.outside-table`).
///
/// The commands of a table of cells, and the character `&`, must be written
/// in the following places:
///
/// - `\cell` directly in the body of a `cells` environment, or as an entry of
/// the data of a `\celldata`, as in `\celldata{A & \cell<H>{B}}`;
/// - `\celldata`, `\rownames` and `\colnames` directly in the body of a
/// `cells` environment;
/// - `\\` directly in the body of a `cells` environment, or directly in the
/// data of a `\celldata`;
/// - `&` directly in the data of a `\celldata`, as in `\celldata{A & B}`;
/// - `\merge` in the placement of a `\cell` or in the mapping of a
/// `\celldata`, as in `\cell[1;\merge{3-4}]{…}`.
///
/// Reported by the lowering rule [`OutsideRule`](super::lower::OutsideRule)
/// of the command, on every backend, at the command. A `\cell` expands to its
/// content, and a `\celldata` expands to its data as inline content. The
/// other commands expand to a dropped mark (`flm.pres.dropped`), and so does
/// a `\cell` or a `\celldata` whose last argument is missing.