flm_core/lang/mint/decl.rs
1//! The declaration types a feature fills in to say what can be written in a
2//! document: elements and their syntax, fallbacks, scoped packages and
3//! overrides.
4//!
5//! A declaration is plain data. [`mint_packages`](super::mint_packages) builds
6//! the techy packages and specifications that a parse uses from the
7//! declarations (see the [module documentation](super) for this work, called
8//! minting). A feature constructs its declarations itself and hands them to
9//! its feature builder, which records the feature as their owner:
10//!
11//! - [`ElementDef`], an element and the syntax it is written in
12//! ([`SyntaxDef`]), passed to
13//! [`FeatureBuilder::element`](crate::core::registry::FeatureBuilder::element);
14//! a declaration is available in text mode unless it lists its parsing
15//! modes ([`ElementDef::modes`]);
16//! - [`FallbackDef`], what a macro or an environment that no declaration
17//! defines means in given parsing modes, passed to
18//! [`FeatureBuilder::fallback`](crate::core::registry::FeatureBuilder::fallback);
19//! - [`ScopedPackageDef`], a set of element declarations available only inside
20//! certain environment bodies and arguments, passed to
21//! [`FeatureBuilder::scoped_package`](crate::core::registry::FeatureBuilder::scoped_package);
22//! - [`OverrideDef`], a feature's statement that its definition of a name
23//! replaces another feature's, made with
24//! [`FeatureBuilder::override_callable`](crate::core::registry::FeatureBuilder::override_callable).
25//!
26//! The two types to read first are [`SyntaxDef`], which says how an element is
27//! written, and [`ArgDef`], which declares one argument: the parser that reads
28//! it ([`FlmArgumentParser`], most often one of the standard kinds of
29//! [`ArgStdKind`]) and what the declaration says around the parser (name,
30//! parsing mode, layout, opaque wrapper, scoped packages, documentation).
31//! [`BodyDef`] does the
32//! same for an environment's body. Settings given as data write an argument
33//! declaration as a map, whose syntax is a standard kind written as data or a
34//! short text standing for one, an argument code; see [`super::codes`].
35
36use std::fmt;
37use std::sync::Arc;
38
39use techy::latexlike::Mode;
40
41use crate::model::element::ElementSpec;
42use crate::model::names::{FeatureName, Name};
43use crate::lang::flm::FlmCallableType;
44use crate::lang::mint::codes::{ArgCode, ArgData};
45use crate::lang::mint::parsers::{
46 ArgStdKind, FlmArgumentParser, FlmBodyParser, IntoFlmArgumentParser, IntoFlmBodyParser,
47};
48use crate::lang::verbatim::FlmVerbatimBehavior;
49
50/// A callable kind: one of the three forms in which an element can be written
51/// in a document, a macro, an environment or a special character sequence.
52///
53/// [`SyntaxDef::kind`] returns it for a syntax; [`OverrideDef`] and
54/// [`Symbol`](super::Symbol) use it to say which form a name belongs to. Its
55/// `Display` text (`macro`, `environment`, `specials`) appears in error
56/// messages and in the [registry digest](crate::model::digest) (the hash of
57/// everything about a registry that can change what processing produces).
58///
59/// It is written to data with `Serialize`; see [serialized
60/// forms](crate::core::registry#serialized-forms).
61#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
62#[derive(serde::Serialize, schemars::JsonSchema)]
63#[serde(rename_all = "lowercase")]
64pub enum CallableKind {
65 /// A macro: `\name{…}`.
66 Macro,
67 /// An environment: `\begin{name}…\end{name}`.
68 Environment,
69 /// A special character sequence, recognized wherever it appears rather than
70 /// after an escape character (`~`, `---`).
71 Specials,
72}
73
74impl CallableKind {
75 /// Returns the callable type of the FLM language ([`FlmCallableType`])
76 /// under which a name of this kind is registered in a techy package.
77 pub fn callable_type(self) -> FlmCallableType {
78 match self {
79 CallableKind::Macro => FlmCallableType::Macro,
80 CallableKind::Environment => FlmCallableType::Environment,
81 CallableKind::Specials => FlmCallableType::Specials,
82 }
83 }
84}
85
86impl fmt::Display for CallableKind {
87 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
88 f.write_str(match self {
89 CallableKind::Macro => "macro",
90 CallableKind::Environment => "environment",
91 CallableKind::Specials => "specials",
92 })
93 }
94}
95
96/// The declaration of one **tack-on field**: a macro that a construct absorbs
97/// as data after its own arguments, as `\section{…}` absorbs the `\label{…}`
98/// written after it.
99///
100/// A construct accepts its tack-on fields through its tack-on argument, an
101/// argument declared as [`ArgStdKind::TackOn`] with the list of fields,
102/// usually its last. A field is written like a macro, but its name is not
103/// defined as a command anywhere: only the construct that declares the field
104/// accepts it, and only where that construct's tack-on argument stands.
105///
106/// A field is **data that the declaring construct reads**, not content: its
107/// node is a macro node named as the field is written, carrying the language's
108/// field element ([`FIELD`](crate::lang::structural::FIELD)), the same element
109/// for every field, and the construct that declared the field is its only
110/// reader. The declaration is data only: a name, arguments, whether the field
111/// repeats, and documentation. See the [`field`](super::field) module and
112/// [fields](crate::guide::concepts_overview#fields-data-a-construct-reads).
113///
114/// Settings given as data declare a field in the structured syntax `tack-on`
115/// of its tack-on argument ([the kind as data](ArgStdKind#the-kind-as-data)).
116#[derive(Debug, Clone, PartialEq, Eq)]
117pub struct TackOnField {
118 /// The field's name, without the escape character (`label`), distinct
119 /// from the names of the other fields of its tack-on argument.
120 pub name: String,
121 /// The field's own arguments, in the order they are written.
122 pub args: Vec<ArgDef>,
123 /// Whether the field may be written more than once after one construct.
124 pub repeatable: bool,
125 /// Documentation of the field. The library does not act on it; the
126 /// registry keeps it with the declaration
127 /// ([`FlmRegistry::declarations`](crate::core::registry::FlmRegistry::declarations))
128 /// for a program that describes what an author may write.
129 pub docs: String,
130}
131
132impl TackOnField {
133 /// Declares a field written `\name`, taking the given arguments, which may
134 /// be written at most once after the construct;
135 /// [`TackOnField::repeatable`] allows it more than once.
136 pub fn new(name: impl Into<String>, args: Vec<ArgDef>) -> TackOnField {
137 TackOnField { name: name.into(), args, repeatable: false, docs: String::new() }
138 }
139
140 /// Builder: the field may be written more than once after one construct.
141 pub fn repeatable(mut self) -> TackOnField {
142 self.repeatable = true;
143 self
144 }
145
146 /// Builder: sets the field's documentation.
147 pub fn docs(mut self, docs: impl Into<String>) -> TackOnField {
148 self.docs = crate::kept_docs(docs);
149 self
150 }
151}
152
153/// How the [block-structure pass](crate::lang::rewrites::blocks) lays out an
154/// argument's content: as inline
155/// content, as a region of blocks, or as whichever of the two the content
156/// calls for.
157///
158/// Inline content is running text (words, formulas, commands such as
159/// `\emph{…}`) with no paragraph inside it. A region of blocks holds
160/// paragraphs and block-level constructs such as lists. The layout belongs to
161/// the command's declaration ([`ArgDef::layout`]); an author cannot choose it
162/// where the command is written.
163///
164/// An argument declared with an opaque wrapper ([`ArgDef::opaque_wrapper`])
165/// takes only [`Inline`](ArgLayout::Inline): the block-structure pass carries
166/// its content over as written, so no other layout could take effect. An
167/// argument read in mathematics mode is an [opaque
168/// region](crate::guide::concepts_overview#opaque-regions), which the
169/// block-structure pass carries over untouched, so it may not be declared
170/// [`Blocks`](ArgLayout::Blocks). Minting reports a declaration that breaks
171/// either rule
172/// ([`MintError::LayoutOnOpaqueWrappedArgument`](super::MintError::LayoutOnOpaqueWrappedArgument),
173/// [`MintError::BlocksOnMathArgument`](super::MintError::BlocksOnMathArgument)).
174/// A layout declared on an argument whose reader yields raw text or places
175/// its content under an opaque wrapper by construction (a verbatim argument, a
176/// characters-only group) is not reported; it has no effect, since the
177/// argument's content is an opaque region.
178///
179/// [`arg_layout_of`](super::arg_layout_of) returns the declared layout of an
180/// argument of a parsed node;
181/// [`argument_holds_blocks`](crate::lang::rewrites::blocks::argument_holds_blocks)
182/// returns whether an argument holds blocks, before and after the
183/// block-structure pass alike.
184#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, serde::Deserialize, serde::Serialize)]
185#[derive(schemars::JsonSchema)]
186#[serde(rename_all = "kebab-case")]
187pub enum ArgLayout {
188 /// Inline content: no paragraph is built inside it, and a blank line in it
189 /// is an error, reported and read as one space. The default.
190 #[default]
191 Inline,
192 /// A region of blocks: paragraphs are built inside it, exactly as in an
193 /// environment body declared [`BodyLayout::Blocks`]. Content written on
194 /// one line becomes one paragraph.
195 Blocks,
196 /// Inferred from the content: a region of blocks when the content holds a
197 /// blank line (a paragraph break) or a block-level construct such as a
198 /// list, inline content otherwise. This is the rule a fragment laid out
199 /// [`InlineOrBlocks`](crate::model::doc::FragmentLayout::InlineOrBlocks)
200 /// applies to its top level.
201 InlineOrBlocks,
202}
203
204/// The declaration of one argument of a macro, an environment or a special
205/// character sequence: the parser that reads it, the name it can be read by,
206/// the parsing mode it is read in, how its content is laid out, whether its
207/// content is kept as written under an opaque wrapper, the scoped packages
208/// available inside it, documentation, and what it holds (its role).
209///
210/// The parser is one field among the others ([`ArgDef::kind`]): one of the
211/// standard argument kinds ([`ArgStdKind`]) for the forms FLM provides, or a
212/// parser of a feature's own ([`FlmArgumentParser`]) for a syntax they cannot
213/// express. Either way, minting applies the name, mode, layout, opaque wrapper
214/// and scoped packages declared here around the parser.
215///
216/// Give an argument a name whenever anything reads it: reading by name keeps
217/// working when the argument list changes later, reading by position does not.
218///
219/// An argument may also state its **role**: what the text written for it
220/// holds (a label, a citation key, the path of a file), as a dotted name
221/// that a feature registers in the registry's namespace of argument roles.
222/// The role describes the argument for a reader of the registry; parsing and
223/// processing do not read it. See [`ArgDef::role`].
224///
225/// [`ArgDef::new`], [`ArgDef::named`], [`ArgDef::mandatory`] and
226/// [`ArgDef::optional`] create a declaration; the builder methods
227/// [`mode`](ArgDef::mode), [`layout`](ArgDef::layout),
228/// [`blocks`](ArgDef::blocks), [`with_opaque_wrapper`](ArgDef::with_opaque_wrapper),
229/// [`scoped`](ArgDef::scoped), [`docs`](ArgDef::docs) and
230/// [`role`](ArgDef::role) each change one thing. Settings given as data write
231/// an argument as its argument code, or as a map of its syntax (a structured
232/// syntax, the standard kind written as data, or a code) with the argument's
233/// name, parsing mode, layout, opaque wrapper, scoped packages, documentation
234/// and role ([`ArgData`], which converts into an `ArgDef` through `TryFrom`;
235/// see [`super::codes`]).
236///
237/// Two declarations are equal (`PartialEq`) when every field is equal, the
238/// code they were read from included ([`ArgDef::code`]). Their parsers are
239/// compared by the bytes that identify them
240/// ([`FlmArgumentParser::identity`]), which differ for any two parsers that
241/// read differently.
242#[derive(Debug, Clone, serde::Deserialize)]
243#[derive(schemars::JsonSchema)]
244#[serde(try_from = "ArgData")]
245#[schemars(with = "ArgData")]
246pub struct ArgDef {
247 /// The name the argument can be read by, when it has one.
248 pub name: Option<String>,
249 /// The parser that reads the argument and tells FLM what it needs to know
250 /// about the argument beyond reading it ([`FlmArgumentParser`]). It is a
251 /// shared object, so cloning a declaration shares its parser.
252 /// [`ArgDef::new`] and [`ArgDef::named`] build it from a standard kind or
253 /// from a parser of one's own.
254 pub kind: Arc<dyn FlmArgumentParser>,
255 /// The parsing mode the argument is read in; `None` reads it in the mode
256 /// the command itself is written in. See [`ArgDef::mode`].
257 pub mode: Option<Mode>,
258 /// How the [block-structure pass](crate::lang::rewrites::blocks) lays out
259 /// the argument's content; inline by default. See [`ArgDef::layout`].
260 pub layout: ArgLayout,
261 /// Whether minting places the argument's content under an **opaque
262 /// wrapper**: a group of the class
263 /// [`FlmGroupType::OpaqueWrapper`](crate::lang::FlmGroupType::OpaqueWrapper),
264 /// with no delimiters of its own, staged over what the argument's reader
265 /// read. The [block-structure pass](crate::lang::rewrites::blocks) carries
266 /// the content of such a group over as written, with no whitespace
267 /// collapsed and no typographic substitution made, so the element that
268 /// declared the argument reads it as typed; it reads it through the same
269 /// content nodes as without the wrapper. `false` by default; set it with
270 /// [`ArgDef::with_opaque_wrapper`].
271 ///
272 /// The wrapper is placed around whatever the argument's reader read, for
273 /// every kind and for a parser of one's own. The reader of a
274 /// characters-only group ([`ArgStdKind::CharsGroup`]) places one by
275 /// construction, whatever this field says. A verbatim argument places its
276 /// content under a verbatim group, which the block-structure pass carries
277 /// over in the same way.
278 ///
279 /// An argument declared with an opaque wrapper may not take a layout other
280 /// than [`ArgLayout::Inline`]; minting reports one as
281 /// [`MintError::LayoutOnOpaqueWrappedArgument`](super::MintError::LayoutOnOpaqueWrappedArgument).
282 /// A scoped package declared on it is attached as on any argument
283 /// ([`ArgDef::scoped`]).
284 pub opaque_wrapper: bool,
285 /// The names of the [scoped packages](ScopedPackageDef) whose
286 /// declarations are available inside this argument. See
287 /// [`ArgDef::scoped`].
288 pub scoped: Vec<Name>,
289 /// Documentation of the argument. The library does not act on it; the
290 /// registry keeps it with the declaration
291 /// ([`FlmRegistry::declarations`](crate::core::registry::FlmRegistry::declarations))
292 /// for a program that describes what an author may write.
293 pub docs: String,
294 /// The **argument role**: what the argument holds, beyond how it is
295 /// written, as a registered dotted name such as `flm.refs.target` (the
296 /// label a reference points to). `None`, the default, says nothing about
297 /// what the argument holds. See [`ArgDef::role`].
298 pub role: Option<Name>,
299 /// The argument code the declaration was read from, with the kind it
300 /// stands for; see [`ArgDef::code`].
301 pub(super) code: Option<ArgCode>,
302}
303
304impl ArgDef {
305 /// Creates the declaration of an argument read by `kind`, with no name, so
306 /// that it can be read only by position. Its content is inline
307 /// ([`ArgLayout::Inline`]) and not placed under an opaque wrapper by the
308 /// declaration, it is read in the mode the command is written in, and no
309 /// scoped package is available inside it.
310 ///
311 /// `kind` is a standard kind (`ArgDef::new(ArgStdKind::Star)`), a parser
312 /// of one's own passed by value, or a parser already shared as
313 /// `Arc<dyn FlmArgumentParser>`; [`IntoFlmArgumentParser`] converts all
314 /// three.
315 pub fn new(kind: impl IntoFlmArgumentParser) -> ArgDef {
316 ArgDef {
317 name: None,
318 kind: kind.into_flm_argument_parser(),
319 mode: None,
320 layout: ArgLayout::Inline,
321 opaque_wrapper: false,
322 scoped: Vec::new(),
323 docs: String::new(),
324 role: None,
325 code: None,
326 }
327 }
328
329 /// The argument code this declaration was read from: `"["`, `"r()"`. A
330 /// declaration has one when it was made from a code, by
331 /// [`arg_def_from_code`](super::arg_def_from_code) (every reader of
332 /// settings given as data reads its codes through it) or from a code
333 /// read already ([`ArgCode`], through `From`). `None` for a declaration
334 /// built from a standard kind or a parser ([`ArgDef::new`] and the
335 /// constructors built on it), and for one read from a structured syntax,
336 /// whose standard kind the parser returns
337 /// ([`FlmArgumentParser::std_kind`]).
338 ///
339 /// A program that writes a declaration back as data writes it in the
340 /// form it was read from, so that it reads back the same:
341 ///
342 /// - a declaration read from a code writes this code: the parser object
343 /// alone does not say which code chose it (`{` and `m` choose the same
344 /// parser);
345 /// - any other declaration whose parser is a standard kind writes the
346 /// structured syntax, the kind written as data under the key `syntax`
347 /// (see [`ArgStdKind`]); this covers a declaration read from a
348 /// structured syntax and one built in Rust from a standard kind;
349 /// - a declaration whose parser is a feature's own writes neither, and
350 /// does not read back.
351 ///
352 /// [`ArgDataFields`](super::ArgDataFields)' conversion from an `ArgDef`
353 /// follows this rule. The builder methods leave the code as it is; a
354 /// caller that replaces [`kind`](ArgDef::kind) after reading a code makes
355 /// the code describe a parser the declaration no longer holds.
356 ///
357 /// ```
358 /// use flm_core::lang::mint::{arg_def_from_code, ArgDef, ArgStdKind};
359 ///
360 /// assert_eq!(arg_def_from_code("m").unwrap().code(), Some("m"));
361 /// assert_eq!(ArgDef::new(ArgStdKind::Mandatory).code(), None);
362 /// ```
363 pub fn code(&self) -> Option<&str> {
364 self.code.as_ref().map(ArgCode::as_str)
365 }
366
367 /// The argument code this declaration was read from, with the standard
368 /// kind it stands for ([`ArgCode`]); `None` where [`ArgDef::code`] is
369 /// `None`. A program that holds declarations in a form of its own takes
370 /// the code from here, already read, and makes the declaration again from
371 /// it through `From`, without reading the code again.
372 pub fn arg_code(&self) -> Option<&ArgCode> {
373 self.code.as_ref()
374 }
375
376 /// Creates the declaration of an argument read by `kind`, which can be
377 /// read by `name`. Everything else is as for [`ArgDef::new`].
378 pub fn named(name: impl Into<String>, kind: impl IntoFlmArgumentParser) -> ArgDef {
379 ArgDef { name: Some(name.into()), ..ArgDef::new(kind) }
380 }
381
382 /// Creates the declaration of a mandatory `{…}` argument named `name`;
383 /// shorthand for `ArgDef::named(name, ArgStdKind::Mandatory)`.
384 pub fn mandatory(name: impl Into<String>) -> ArgDef {
385 ArgDef::named(name, ArgStdKind::Mandatory)
386 }
387
388 /// Creates the declaration of an optional `[…]` argument named `name`;
389 /// shorthand for `ArgDef::named(name, ArgStdKind::Optional)`.
390 pub fn optional(name: impl Into<String>) -> ArgDef {
391 ArgDef::named(name, ArgStdKind::Optional)
392 }
393
394 /// Builder: sets the parsing mode the argument is read in. Without it,
395 /// the argument is read in the mode the command is written in.
396 ///
397 /// `Mode::Math` reads the argument as mathematics wherever the command is
398 /// written. `Mode::Text` restores the innermost non-mathematics context
399 /// that encloses the command, with its mode and its token rules; this is
400 /// how `\text{…}` inside mathematics holds ordinary document content.
401 /// Outside mathematics, `Mode::Text` changes nothing. The two values mean
402 /// the same on an environment's body ([`BodyDef::mode`]).
403 pub fn mode(mut self, mode: Mode) -> ArgDef {
404 self.mode = Some(mode);
405 self
406 }
407
408 /// Builder: sets how the [block-structure
409 /// pass](crate::lang::rewrites::blocks) lays out the argument's content: inline
410 /// content (the default), a region of blocks, or whichever of the two the content
411 /// calls for. See [`ArgLayout`].
412 ///
413 /// An argument declared with an opaque wrapper
414 /// ([`ArgDef::with_opaque_wrapper`]) may not take a layout other than
415 /// [`ArgLayout::Inline`], and an argument read in mathematics mode may not
416 /// take [`ArgLayout::Blocks`]. Minting reports a declaration that breaks
417 /// either rule
418 /// ([`MintError::LayoutOnOpaqueWrappedArgument`](super::MintError::LayoutOnOpaqueWrappedArgument),
419 /// [`MintError::BlocksOnMathArgument`](super::MintError::BlocksOnMathArgument))
420 /// and lays the argument out inline.
421 ///
422 /// ```
423 /// use flm_core::lang::mint::{ArgDef, ArgLayout};
424 ///
425 /// // A note whose text may be one line of running text or several
426 /// // paragraphs, as the author writes it.
427 /// let text = ArgDef::mandatory("text").layout(ArgLayout::InlineOrBlocks);
428 /// assert_eq!(text.layout, ArgLayout::InlineOrBlocks);
429 /// ```
430 pub fn layout(mut self, layout: ArgLayout) -> ArgDef {
431 self.layout = layout;
432 self
433 }
434
435 /// Builder: the argument's content is a region of blocks; shorthand for
436 /// `.layout(ArgLayout::Blocks)`.
437 pub fn blocks(self) -> ArgDef {
438 self.layout(ArgLayout::Blocks)
439 }
440
441 /// Builder: places the argument's content under an opaque wrapper
442 /// ([`ArgDef::opaque_wrapper`], which states what the wrapper does and
443 /// what the declaration then admits), for an argument whose text the
444 /// element reads as typed, such as a citation key or the target of a
445 /// link.
446 pub fn with_opaque_wrapper(mut self) -> ArgDef {
447 self.opaque_wrapper = true;
448 self
449 }
450
451 /// Builder: makes the declarations of one more [scoped
452 /// package](ScopedPackageDef), given by name, available inside this
453 /// argument, as [`BodyDef::scoped`] does for an environment's body.
454 ///
455 /// This is how a command gives one of its arguments commands of its own:
456 /// a note whose optional argument accepts `\label{…}`, while `\label` is
457 /// not defined in the running text. While the argument is parsed, the
458 /// scoped package is the innermost techy package of the parsing state's
459 /// scope stack, so its declarations shadow any other definition of the
460 /// same names inside the argument.
461 ///
462 /// Some feature must declare a scoped package of that name; the order in
463 /// which the features register does not matter. A name that no feature
464 /// declares is reported as
465 /// [`MintError::UnknownScopedPackage`](super::MintError::UnknownScopedPackage),
466 /// unless the feature that refers to it declared the name as a peer
467 /// ([`FeatureBuilder::peer_scoped_package`](crate::core::registry::FeatureBuilder::peer_scoped_package)).
468 /// A package that another feature owns may be absent from a registry; the
469 /// argument then makes no command available through it, and a command
470 /// the package would define is an unknown command there. Scoped packages
471 /// that refer to each other in a cycle are reported as
472 /// [`MintError::ScopedPackageCycle`](super::MintError::ScopedPackageCycle).
473 ///
474 /// The package is attached to the parsing state of the argument whatever
475 /// its reader. Inside a reading that recognizes no command, such as a
476 /// characters-only group or a verbatim argument, its declarations are not
477 /// reachable, and nothing is reported.
478 ///
479 /// ```
480 /// use flm_core::lang::mint::ArgDef;
481 ///
482 /// let labels = ArgDef::optional("labels").scoped("my.labels");
483 /// assert_eq!(labels.scoped, ["my.labels"]);
484 /// ```
485 pub fn scoped(mut self, package: impl Into<Name>) -> ArgDef {
486 self.scoped.push(package.into());
487 self
488 }
489
490 /// Builder: sets the argument's documentation.
491 pub fn docs(mut self, docs: impl Into<String>) -> ArgDef {
492 self.docs = crate::kept_docs(docs);
493 self
494 }
495
496 /// Builder: sets the argument's **role**, the registered name of what the
497 /// argument holds, replacing any role set before.
498 ///
499 /// The syntax of an argument says how it is written (a group of
500 /// characters, raw text up to a closing brace); its role says what the
501 /// written text is: a label, a citation key, the path of an image file. A
502 /// program that describes the language reads the role, for example to
503 /// show that the argument of `\ref` and the argument of `\eqref` hold the
504 /// same kind of thing. Parsing and processing do not read it, and the
505 /// role is not an input of the [registry digest](crate::model::digest).
506 ///
507 /// A role is an entity of the registry, in a namespace of its own, the
508 /// *argument roles*. A feature declares a role with
509 /// [`FeatureBuilder::argument_role`](crate::core::registry::FeatureBuilder::argument_role),
510 /// giving its name and a description. A feature may set a role that
511 /// another feature declares; when that feature may be absent from a
512 /// registry, the feature using the role declares it as a peer
513 /// ([`FeatureBuilder::peer_argument_role`](crate::core::registry::FeatureBuilder::peer_argument_role)).
514 /// When the registry is built, a role that no feature declares, and that
515 /// the feature setting it did not declare as a peer, is refused as a
516 /// [`BuildError::UndeclaredArgumentRole`](crate::core::registry::BuildError::UndeclaredArgumentRole).
517 ///
518 /// ```
519 /// use flm_core::lang::mint::{ArgDef, ArgStdKind};
520 ///
521 /// let target = ArgDef::named("target", ArgStdKind::CharsGroup).role("flm.refs.target");
522 /// assert_eq!(target.role.as_ref().map(|name| name.as_str()), Some("flm.refs.target"));
523 /// assert!(ArgDef::mandatory("text").role.is_none());
524 /// ```
525 // A role is a fact of the declaration, which the declaring feature knows; a
526 // registered name gives each role an owner, a description and a listing.
527 pub fn role(mut self, name: impl Into<Name>) -> ArgDef {
528 self.role = Some(name.into());
529 self
530 }
531}
532
533impl PartialEq for ArgDef {
534 fn eq(&self, other: &ArgDef) -> bool {
535 self.name == other.name
536 && self.kind.identity() == other.kind.identity()
537 && self.mode == other.mode
538 && self.layout == other.layout
539 && self.opaque_wrapper == other.opaque_wrapper
540 && self.scoped == other.scoped
541 && self.docs == other.docs
542 && self.role == other.role
543 && self.code == other.code
544 }
545}
546
547impl Eq for ArgDef {}
548
549/// How the [block-structure pass](crate::lang::rewrites::blocks) lays out an
550/// environment's body: as inline content, as a region of blocks, or according
551/// to the element's block role.
552///
553/// [`Inline`](BodyLayout::Inline) and [`Blocks`](BodyLayout::Blocks) take
554/// precedence over the element's block role; [`FromRole`](BodyLayout::FromRole)
555/// follows it. A verbatim body ([`BodyDef::verbatim`]), a body declared with
556/// an opaque wrapper ([`BodyDef::opaque_wrapper`]) and a body read in
557/// mathematics mode are [opaque
558/// regions](crate::guide::concepts_overview#opaque-regions): the
559/// block-structure pass carries them over untouched, regardless of their
560/// layout. A body declared with an opaque wrapper may not declare a layout
561/// other than [`FromRole`](BodyLayout::FromRole)
562/// ([`MintError::LayoutOnOpaqueWrappedBody`](super::MintError::LayoutOnOpaqueWrappedBody)).
563///
564/// It is written to data with `Serialize`; see [serialized
565/// forms](crate::core::registry#serialized-forms).
566#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
567#[derive(serde::Serialize, schemars::JsonSchema)]
568#[serde(rename_all = "kebab-case")]
569pub enum BodyLayout {
570 /// The body is inline content: no paragraph is built inside it, and a blank
571 /// line in it is an error.
572 Inline,
573 /// The body is a region of blocks: paragraphs are built inside it.
574 Blocks,
575 /// The body follows the element's block role: a region of blocks for an
576 /// element whose role is [`BlockRole::Block`](crate::model::aspects::BlockRole::Block),
577 /// inline content otherwise. This is the default, so that a body's layout
578 /// follows from what the element is.
579 #[default]
580 FromRole,
581}
582
583/// The declaration of an environment's body: how it is laid out, which parser
584/// reads it, which parsing mode it is read in, whether its content is kept as
585/// written under an opaque wrapper, and which scoped packages are available
586/// inside it.
587///
588/// [`BodyDef::new`] (the same as `BodyDef::default()`) declares a body laid
589/// out by the element's block role, read the ordinary way, read in the mode
590/// the environment is written in, with no opaque wrapper and with no scoped
591/// package; each builder method changes one of these.
592///
593/// The body parser is one field among the others ([`BodyDef::parser`]): a body
594/// that is not read the ordinary way (raw text, or content a feature checks as
595/// it reads it) holds the object that reads it, and minting applies the
596/// layout, mode, opaque wrapper and scoped packages declared here around that
597/// object.
598#[derive(Debug, Clone, Default)]
599pub struct BodyDef {
600 /// How the [block-structure pass](crate::lang::rewrites::blocks) lays out
601 /// the body.
602 pub layout: BodyLayout,
603 /// The parser that reads the body, when the body is not read the ordinary
604 /// way (content up to and including `\end{name}`). See
605 /// [`BodyDef::parser`].
606 pub parser: Option<Arc<dyn FlmBodyParser>>,
607 /// The parsing mode the body is read in: `Some(Mode::Math)` for an
608 /// equation-like environment, `Some(Mode::Text)` to restore the
609 /// non-mathematics context that encloses the mathematics, `None` to read
610 /// the body in the mode the environment is written in.
611 pub mode: Option<Mode>,
612 /// Whether minting places the body's content under an opaque wrapper, as
613 /// [`ArgDef::opaque_wrapper`] does for an argument: a group of the class
614 /// [`FlmGroupType::OpaqueWrapper`](crate::lang::FlmGroupType::OpaqueWrapper),
615 /// whose content the [block-structure pass](crate::lang::rewrites::blocks)
616 /// carries over as written. The wrapper is placed around whatever reads
617 /// the body, the declared parser or the ordinary reading, and the content
618 /// designated as the body's stays the same nodes. `false` by default; set
619 /// it with [`BodyDef::with_opaque_wrapper`].
620 ///
621 /// A body declared with an opaque wrapper may not declare a layout other
622 /// than [`BodyLayout::FromRole`]; minting reports one as
623 /// [`MintError::LayoutOnOpaqueWrappedBody`](super::MintError::LayoutOnOpaqueWrappedBody).
624 /// A scoped package declared on it is attached as on any body
625 /// ([`BodyDef::scoped`]).
626 pub opaque_wrapper: bool,
627 /// The names of the [scoped packages](ScopedPackageDef) whose
628 /// declarations are available inside this body, such as the package that
629 /// defines `\item` inside a list environment. See [`BodyDef::scoped`].
630 pub scoped: Vec<Name>,
631}
632
633impl BodyDef {
634 /// Creates the declaration of a body read the ordinary way, laid out by
635 /// the element's block role ([`BodyLayout::FromRole`]), read in the mode
636 /// the environment is written in, with no opaque wrapper and no scoped
637 /// package. The same as `BodyDef::default()`.
638 pub fn new() -> BodyDef {
639 BodyDef::default()
640 }
641
642 /// Builder: sets how the body is laid out.
643 pub fn layout(mut self, layout: BodyLayout) -> BodyDef {
644 self.layout = layout;
645 self
646 }
647
648 /// Builder: the body is a region of blocks; shorthand for
649 /// `.layout(BodyLayout::Blocks)`.
650 pub fn blocks(self) -> BodyDef {
651 self.layout(BodyLayout::Blocks)
652 }
653
654 /// Builder: the body is raw text, read by FLM's verbatim reader
655 /// ([`crate::lang::verbatim`]), which places the content under a group of
656 /// the verbatim class; shorthand for
657 /// `.parser(FlmVerbatimBehavior::new())`.
658 pub fn verbatim(self) -> BodyDef {
659 self.parser(FlmVerbatimBehavior::new())
660 }
661
662 /// Builder: sets the parser that reads the body ([`FlmBodyParser`]), for
663 /// a body not read the ordinary way: FLM's verbatim reader
664 /// ([`BodyDef::verbatim`]), or a feature's own parser, such as one that
665 /// reads the ordinary content and then checks it.
666 ///
667 /// Only the parser's reading of the body is used: the environment's
668 /// arguments are those of the declaration, the body is read under the
669 /// mode and the scoped packages declared here, and what the parser read
670 /// is placed under an opaque wrapper when the declaration asks for one
671 /// ([`BodyDef::with_opaque_wrapper`]).
672 ///
673 /// `parser` is a parser passed by value, or one already shared as
674 /// `Arc<dyn FlmBodyParser>` by several declarations; [`IntoFlmBodyParser`]
675 /// converts both.
676 pub fn parser(mut self, parser: impl IntoFlmBodyParser) -> BodyDef {
677 self.parser = Some(parser.into_flm_body_parser());
678 self
679 }
680
681 /// Builder: sets the parsing mode the body is read in. `Mode::Math` and
682 /// `Mode::Text` mean what they mean for an argument ([`ArgDef::mode`]).
683 pub fn mode(mut self, mode: Mode) -> BodyDef {
684 self.mode = Some(mode);
685 self
686 }
687
688 /// Builder: places the body's content under an opaque wrapper
689 /// ([`BodyDef::opaque_wrapper`], which states what the wrapper does and
690 /// what the declaration then admits).
691 pub fn with_opaque_wrapper(mut self) -> BodyDef {
692 self.opaque_wrapper = true;
693 self
694 }
695
696 /// Builder: makes the declarations of one more scoped package, given by
697 /// name, available inside the body. Some feature must declare a
698 /// [`ScopedPackageDef`] of that name; the rules are those of
699 /// [`ArgDef::scoped`].
700 pub fn scoped(mut self, package: impl Into<Name>) -> BodyDef {
701 self.scoped.push(package.into());
702 self
703 }
704}
705
706/// How an element is written in the source: as a macro, an environment, a
707/// file-inclusion macro, a special character sequence, or not at all.
708///
709/// Each form holds its list of argument declarations ([`ArgDef`]), and an
710/// environment also holds a body declaration ([`BodyDef`]). A syntax the
711/// standard argument kinds cannot express is still one of these forms: its
712/// argument, or its body, holds a parser of the feature's own
713/// ([`FlmArgumentParser`], [`FlmBodyParser`]), with its name, layout,
714/// documentation, mode and scoped packages declared like any other. Only these
715/// declarations reach techy: minting builds every specification from them.
716#[derive(Debug, Clone)]
717pub enum SyntaxDef {
718 /// A macro taking the given arguments, registered under each of the
719 /// declaration's names.
720 Macro {
721 /// The arguments, in the order they are written.
722 args: Vec<ArgDef>,
723 },
724 /// An environment taking the given arguments, written after `\begin{name}`,
725 /// and the given body; registered under each of the declaration's names.
726 Environment {
727 /// The arguments, in the order they are written.
728 args: Vec<ArgDef>,
729 /// What the body is.
730 body: BodyDef,
731 },
732 /// A macro that brings the content of another file into the document,
733 /// written `\input{reference}`. One of the given arguments must be named
734 /// [`REFERENCE_ARGUMENT`](crate::lang::input::REFERENCE_ARGUMENT); it holds
735 /// the reference as plain characters, and minting reports a declaration
736 /// without it as
737 /// [`MintError::NoReferenceArgument`](super::MintError::NoReferenceArgument).
738 /// The macro is registered under each of the declaration's names and
739 /// parsed by the language's own inclusion parser ([`crate::lang::input`]),
740 /// which asks the [input resolver](crate::lang::InputResolver) on the
741 /// [parse driver](crate::lang::FlmDriver) for the file and parses the
742 /// file's content where the command is written.
743 Inclusion {
744 /// The arguments, in the order they are written.
745 args: Vec<ArgDef>,
746 },
747 /// A special character sequence with the given trigger and arguments. The
748 /// declaration lists no name: the trigger is how the sequence is written.
749 Specials {
750 /// The character sequence that triggers it.
751 trigger: String,
752 /// The arguments, in the order they are written.
753 args: Vec<ArgDef>,
754 },
755 /// No syntax: the element is never parsed, and only a rewrite or a
756 /// lowering stage creates nodes of it, such as a heading's number or a
757 /// pointer to another node's argument. The declaration lists no name.
758 Synthesized,
759}
760
761impl SyntaxDef {
762 /// Returns the callable kind this syntax is registered under (a
763 /// file-inclusion macro is a macro); `None` for
764 /// [`SyntaxDef::Synthesized`], which is not registered.
765 pub fn kind(&self) -> Option<CallableKind> {
766 match self {
767 SyntaxDef::Macro { .. } | SyntaxDef::Inclusion { .. } => Some(CallableKind::Macro),
768 SyntaxDef::Environment { .. } => Some(CallableKind::Environment),
769 SyntaxDef::Specials { .. } => Some(CallableKind::Specials),
770 SyntaxDef::Synthesized => None,
771 }
772 }
773
774 /// Returns the argument declarations of this syntax, in the order they are
775 /// written; empty for [`SyntaxDef::Synthesized`], which takes none.
776 ///
777 /// ```
778 /// use flm_core::lang::mint::{ArgDef, SyntaxDef};
779 ///
780 /// let syntax = SyntaxDef::Macro { args: vec![ArgDef::mandatory("text")] };
781 /// assert_eq!(syntax.args().len(), 1);
782 /// assert!(SyntaxDef::Synthesized.args().is_empty());
783 /// ```
784 pub fn args(&self) -> &[ArgDef] {
785 match self {
786 SyntaxDef::Macro { args }
787 | SyntaxDef::Environment { args, .. }
788 | SyntaxDef::Inclusion { args }
789 | SyntaxDef::Specials { args, .. } => args,
790 SyntaxDef::Synthesized => &[],
791 }
792 }
793}
794
795/// An element declaration: the plain data a feature gives for an element, the
796/// syntax it is written in (macro, environment or special character sequence),
797/// its arguments (each with a parser, a layout, a parsing mode and the scoped
798/// packages available inside it) and its body.
799///
800/// Besides the syntax ([`SyntaxDef`]), the declaration holds the feature that
801/// declares it, the names the element is written under, the element value its
802/// nodes carry, the parsing modes it is available in, and documentation. A
803/// feature passes it to
804/// [`FeatureBuilder::element`](crate::core::registry::FeatureBuilder::element),
805/// or places it in a [`ScopedPackageDef`].
806///
807/// A declaration is available in text mode unless it lists its parsing modes
808/// with [`ElementDef::modes`]: a feature that defines a command of mathematics
809/// lists `[Mode::Math]`, and one that defines a command for both modes lists
810/// both. Two declarations of one name whose modes do not overlap never clash,
811/// whether they come from one feature or from two: a text-mode `\textbf` and
812/// a mathematics-mode `\textbf` are two different commands. A declaration
813/// with no syntax ([`SyntaxDef::Synthesized`]) carries the field and ignores
814/// it.
815#[derive(Clone)]
816pub struct ElementDef {
817 /// The feature that declares the element. Error messages identify the
818 /// declaration by it, and the symbol table
819 /// ([`MintedProviders::symbols`](super::MintedProviders::symbols)) records
820 /// it. The feature builder sets it to the feature being built, so a
821 /// feature need not set it; a caller of
822 /// [`build_language`](crate::lang::build_language) that builds the
823 /// declarations by hand sets it here.
824 pub owner: FeatureName,
825 /// The names this element is written under, without the escape
826 /// character. Several names may share one element value: the headings
827 /// feature, for instance, declares all the commands of one heading kind
828 /// under one element value. Empty for a special
829 /// character sequence and for an element with no syntax
830 /// ([`SyntaxDef::Synthesized`]).
831 pub names: Vec<Name>,
832 /// How the element is written.
833 pub syntax: SyntaxDef,
834 /// The element value every node of this declaration carries.
835 pub element: Arc<ElementSpec>,
836 /// Documentation of the declaration. The library does not act on it; the
837 /// registry keeps it with the declaration
838 /// ([`FlmRegistry::declarations`](crate::core::registry::FlmRegistry::declarations))
839 /// for a program that describes what an author may write.
840 pub docs: String,
841 /// The parsing modes the declaration is available in: `[Mode::Text]`
842 /// unless the feature lists others with [`ElementDef::modes`]. Ignored for
843 /// [`SyntaxDef::Synthesized`], which no document writes.
844 pub modes: Vec<Mode>,
845}
846
847impl ElementDef {
848 /// Creates the declaration, by `owner`, that `element` is written as
849 /// `syntax` under `names`, with no documentation and available in text
850 /// mode only.
851 pub fn new(
852 owner: impl Into<FeatureName>,
853 names: impl IntoIterator<Item = impl Into<Name>>,
854 syntax: SyntaxDef,
855 element: Arc<ElementSpec>,
856 ) -> ElementDef {
857 ElementDef {
858 owner: owner.into(),
859 names: names.into_iter().map(Into::into).collect(),
860 syntax,
861 element,
862 docs: String::new(),
863 modes: vec![Mode::Text],
864 }
865 }
866
867 /// Builder: sets the declaration's documentation.
868 pub fn docs(mut self, docs: impl Into<String>) -> ElementDef {
869 self.docs = crate::kept_docs(docs);
870 self
871 }
872
873 /// Builder: sets the parsing modes the declaration is available in,
874 /// replacing the default, text mode. A feature that defines a command of
875 /// mathematics passes `[Mode::Math]`; one that defines a command for both
876 /// modes passes `[Mode::Text, Mode::Math]`.
877 pub fn modes(mut self, modes: impl IntoIterator<Item = Mode>) -> ElementDef {
878 self.modes = modes.into_iter().collect();
879 self
880 }
881}
882
883impl fmt::Debug for ElementDef {
884 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
885 f.debug_struct("ElementDef")
886 .field("owner", &self.owner)
887 .field("names", &self.names)
888 .field("syntax", &self.syntax)
889 .field("element", &self.element.name)
890 .field("modes", &self.modes)
891 .finish()
892 }
893}
894
895/// The callable kinds a fallback can be declared for: macros and
896/// environments.
897///
898/// There is no fallback for special character sequences: a sequence of
899/// characters that no declaration defines is not a special character
900/// sequence, and is read as ordinary text.
901#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
902pub enum FallbackKind {
903 /// Macros that no declaration defines.
904 Macro,
905 /// Environments that no declaration defines.
906 Environment,
907}
908
909impl FallbackKind {
910 /// Returns the callable kind ([`CallableKind`]) this fallback kind
911 /// applies to.
912 pub fn callable_kind(self) -> CallableKind {
913 match self {
914 FallbackKind::Macro => CallableKind::Macro,
915 FallbackKind::Environment => CallableKind::Environment,
916 }
917 }
918
919 /// Returns the callable type of the FLM language ([`FlmCallableType`])
920 /// this fallback kind applies to.
921 pub fn callable_type(self) -> FlmCallableType {
922 self.callable_kind().callable_type()
923 }
924}
925
926impl fmt::Display for FallbackKind {
927 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
928 f.write_str(match self {
929 FallbackKind::Macro => "macro",
930 FallbackKind::Environment => "environment",
931 })
932 }
933}
934
935/// A fallback: a feature's declaration of what a macro or an environment that
936/// no declaration defines means, in the parsing modes the fallback lists.
937///
938/// In those modes, such a command of the fallback's kind
939/// ([`kind`](Self::kind)) resolves to a specification that takes no argument
940/// and carries `element`, and the parse reports nothing. A mathematics feature
941/// uses a fallback to accept any command name inside `\(…\)` as content for
942/// the mathematics renderer, while text mode still reports an unknown command.
943///
944/// Only one fallback may apply to one kind in one parsing mode across a
945/// registry: a later fallback that overlaps an earlier one is reported as a
946/// [`MintError::Clash`](super::MintError::Clash) and not installed. The
947/// language has its own two fallbacks, consulted after every fallback a
948/// feature declares, which apply in every mode and report the unknown command;
949/// their nodes carry [`UNKNOWN_MACRO`](crate::lang::structural::UNKNOWN_MACRO) or
950/// [`UNKNOWN_ENVIRONMENT`](crate::lang::structural::UNKNOWN_ENVIRONMENT). A feature
951/// declares a fallback with
952/// [`FeatureBuilder::fallback`](crate::core::registry::FeatureBuilder::fallback);
953/// [`FlmFallbackProvider`](super::FlmFallbackProvider) applies them.
954#[derive(Clone)]
955pub struct FallbackDef {
956 /// The feature that declares the fallback; the feature builder sets it.
957 pub owner: FeatureName,
958 /// The parsing modes in which the fallback applies.
959 pub modes: Vec<Mode>,
960 /// The callable kind the fallback applies to.
961 pub kind: FallbackKind,
962 /// The element that the node of such a command carries.
963 pub element: Arc<ElementSpec>,
964}
965
966impl fmt::Debug for FallbackDef {
967 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
968 f.debug_struct("FallbackDef")
969 .field("owner", &self.owner)
970 .field("modes", &self.modes)
971 .field("kind", &self.kind)
972 .field("element", &self.element.name)
973 .finish()
974 }
975}
976
977/// A scoped package: a set of element declarations that can be written only
978/// inside the environment bodies and arguments whose declarations refer to the
979/// package by name, for instance `\item` inside a list's body or `\caption`
980/// inside a float's body.
981///
982/// A body refers to a scoped package with [`BodyDef::scoped`], an argument
983/// with [`ArgDef::scoped`]. While such a body or argument is parsed, the
984/// package's declarations are available there and shadow any other definition
985/// of the same names; outside, they do not exist.
986///
987/// Minting builds one techy package per scoped package. That package is not
988/// on the document's scope stack: it is added as the innermost techy package
989/// only while a body or an argument that refers to it is parsed. Minting never
990/// checks the declarations of a scoped package for clashes with those of
991/// another scoped package or of a feature; only two scoped packages of one
992/// name clash ([`ClashKind::ScopedPackage`](super::ClashKind::ScopedPackage)).
993///
994/// A feature declares a scoped package with
995/// [`FeatureBuilder::scoped_package`](crate::core::registry::FeatureBuilder::scoped_package).
996/// A body or an argument may refer to a scoped package that another feature
997/// declares. The referring feature then declares the name as a peer
998/// ([`FeatureBuilder::peer_scoped_package`](crate::core::registry::FeatureBuilder::peer_scoped_package)),
999/// so that a registry without the owning feature still builds: the referring
1000/// bodies and arguments then make no command available through the package.
1001/// See also [scoped packages](crate::guide::concepts_overview#scoped-packages).
1002#[derive(Clone)]
1003pub struct ScopedPackageDef {
1004 /// The feature that declares the package; the feature builder sets it,
1005 /// and sets it on each of the package's element declarations too.
1006 pub owner: FeatureName,
1007 /// The name by which a body or an argument refers to the package. It must
1008 /// be unique across the registry: minting reports a second package of the
1009 /// same name as a [`MintError::Clash`](super::MintError::Clash) and builds
1010 /// only the first.
1011 pub name: Name,
1012 /// The element declarations the package holds.
1013 pub elements: Vec<ElementDef>,
1014 /// Documentation of the package. The library does not act on it; the
1015 /// registry keeps it with the declaration
1016 /// ([`FlmRegistry::declarations`](crate::core::registry::FlmRegistry::declarations))
1017 /// for a program that describes what an author may write.
1018 pub docs: String,
1019}
1020
1021impl fmt::Debug for ScopedPackageDef {
1022 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1023 f.debug_struct("ScopedPackageDef")
1024 .field("owner", &self.owner)
1025 .field("name", &self.name)
1026 .field("elements", &self.elements)
1027 .finish()
1028 }
1029}
1030
1031/// An override: the statement, by the feature `owner`, that its definition of
1032/// `name` replaces the definitions other features give that name.
1033///
1034/// Registration order decides which of several definitions of one name
1035/// applies, because a later feature's techy package is innermost on the scope
1036/// stack. Two features that define one name in one parsing mode are reported
1037/// as a [`MintError::Clash`](super::MintError::Clash), unless the feature
1038/// order places the feature registered last explicitly after the others
1039/// ([`crate::core::registry::order`]), or that feature declares an override.
1040/// An override thus prevents that report in each mode where `owner` is the
1041/// feature registered last among those that define the name; elsewhere it is
1042/// not consulted and has no effect. A feature declares an override with
1043/// [`FeatureBuilder::override_callable`](crate::core::registry::FeatureBuilder::override_callable).
1044#[derive(Debug, Clone, PartialEq, Eq)]
1045pub struct OverrideDef {
1046 /// The feature whose definition replaces the others.
1047 pub owner: FeatureName,
1048 /// The callable kind of the redefined name.
1049 pub kind: CallableKind,
1050 /// The redefined name, without the escape character, or the trigger of a
1051 /// special character sequence.
1052 pub name: Name,
1053}