Expand description
The default lowering rules of the structural elements, and the helpers other rules use to stage paragraphs and trimmed inline content.
The structural elements are the elements of the node shapes no
feature declares: text, comments, containers, groups of each class,
paragraphs, paragraph breaks, template placeholders, fields, and the macros and
environments a parse could not attribute to any feature
(StructuralElements; see
structural elements).
Most structural elements need no rule: flm.text, flm.group,
flm.opaque-wrapper, flm.comment, flm.container and flm.parbreak are
elements a backend writes natively, so nothing lowers them; the text
backend of this crate writes all six natively
(FLOW_THROUGH). An
opaque wrapper has no delimiters, so a backend writes it through its
children, and its text comes out as typed. The
paragraph-break element is among them because it remains after block
structuring inside opaque math content. The six rules of this module cover
the elements that do need a rule, and default_rules is the list the
lowering feature registers:
| element | lowers to | rule |
|---|---|---|
flm.paragraph | flm.pres.par | ParagraphRule |
flm.math | flm.pres.span of role flm.math, and an Error | MathGroupRule |
flm.verbatim | flm.pres.verbatim | VerbatimRule |
flm.unknown.macro | flm.pres.unknown | UnknownMacroRule |
flm.unknown.environment | flm.pres.unknown | UnknownEnvironmentRule |
flm.field | nothing, and an Error | FieldRule |
Each is registered as the default rule for its element on every backend
(DefaultMark::Everywhere), except the rule of flm.math, which is never
a default (DefaultMark::Never): it is chosen only where no feature that
processes mathematics has a rule for flm.math on the backend at hand. A backend uses it unless the plan request
prefers another rule by name, the backend writes the element natively, or
another rule is marked as the default on that backend
(DefaultMark::OnBackends); see the rule selection order at
SelectedRules.
§What the default rules do and require
The paragraph rule requires the capability flm.blocks.structured
(BLOCKS_STRUCTURED). A paragraph group exists only in a tree the
block-structure rewrite has processed, and a rule states what must have
happened before it runs by requiring a capability. Since this rule is
selected for every backend that does not write flm.paragraph natively,
every such plan structures its trees.
Verbatim content is copied unchanged. It is an opaque
region: nothing inside it
is lowered, and the nodes are copied unchanged into the presentation
node’s body (super::copy_run_verbatim). Verbatim content is first read
as characters, as every rule that stages verbatim content reads it
(super::stage_verbatim_content): content that a template substituted
there and that is not characters is reported as
ContentNotCharacters at the command or
environment owning the group, and shown as its source text.
A math group is an Error until a feature processes mathematics. The
math groups and the display-math environments are lowered by the rules of
the feature that processes mathematics (for example the feature of the
package math_passthrough). Where no
such feature has a rule for flm.math on the backend at hand, the rule of
last resort MathGroupRule reports
MathUnprocessed (flm.math.unprocessed) at the
group and lowers the group’s content through the rules as ordinary content,
inside a flm.pres.span of role flm.math and kind inline or display.
The math feature’s own rule of last resort does the same for a
display-math environment
(unprocessed).
A verbatim group’s display and kind are inferred. Its display is
Block when the group is the body of a block-role element declared with a
verbatim body and Inline otherwise; its verbatim kind is text, the kind
that applies no formatting of its own, because a bare group states no
kind. An element that needs another kind, another display or a language
tag builds the payload in its own rule from the group’s children, as the
two rules of the verbatim feature do.
An unattributed macro or environment is lowered as content, not as an
error mark. flm.unknown.macro and flm.unknown.environment are the
elements the parse gives a macro or an environment no feature declares.
They lower to flm.pres.unknown carrying the kind, the name and the
source text of the invocation, so a backend writes what the author wrote.
The run’s diagnostics report the mistake; the output itself says nothing
about it.
A field reaching a backend is an error. A field is a macro that a
construct absorbs as data rather than as content, such as the \label
written after a heading or the \tag on an equation line (see fields:
data a construct
reads),
and every field node carries the element FIELD. The construct that
declared a field reads it, and nothing is written for the field itself,
so a field node that reaches the lowering means that construct did not
read its data. FieldRule writes nothing for it and reports
FieldNotRead at the node, on every backend. The rule also makes every
plan complete for the element: a document may contain a field, so every
backend needs a lowering for it.
A mandatory argument that the parse left absent after a parse error is
not a second mistake. The node lowers to the content that does exist (an
empty span, a heading with an empty title), and the parse’s own diagnostic
remains the only report: no flm.lowering.rule-failed, no
flm.pres.unsupported stand-in. lower_arg_or_nothing and
lower_arg_named_or_nothing behave this way, and a rule lowering a
mandatory argument should call them rather than the strict
Lowerer::lower_arg and Lowerer::lower_arg_named, which fail on an
absent argument. None of the rules of this module lowers an argument.
Structs§
- Field
Rule - Lowers
flm.fieldto nothing and reportsFieldNotRead: a field that reaches a backend on its own is a fault of the construct that absorbed it. - Math
Group Rule - The rule of last resort of the math groups: it reports
MathUnprocessed(flm.math.unprocessed, an Error) at the group’s span, and lowers the group’s content through the rules as ordinary content, inside aflm.pres.spanof roleflm.math(MATH) and kindinlineordisplay(see the module documentation, A math group is an Error until a feature processes mathematics). - Paragraph
Rule - Lowers
flm.paragraphto aflm.pres.parholding the paragraph’s lowered inline content, throughlower_paragraph. - Unknown
Environment Rule - Lowers
flm.unknown.environment(an environment no feature declares) to aflm.pres.unknownholding its lowered body. - Unknown
Macro Rule - Lowers
flm.unknown.macro(a macro no feature declares) to a childlessflm.pres.unknowncarrying its source text,\name. - Verbatim
Rule - Lowers
flm.verbatimtoflm.pres.verbatim, copying the group’s content unchanged once it is read as characters (stage_verbatim_content; content that is not characters is reported at the command or environment owning the group, and shown as its source text).
Constants§
- BLOCKS_
STRUCTURED - The capability
ParagraphRulerequires: the table of trees the block-structure rewrite writes, declared by theblocksfeature. Because the rule requires it, every plan whose backend lowers paragraphs includes that rewrite. - FIELD_
RULE - The registered name of the field rule,
FieldRule. - MATH_
DISPLAY_ KIND - The kind of the span
MathGroupRulestages for a displayed math group (\[…\],$$…$$),display. - MATH_
INLINE_ KIND - The kind of the span
MathGroupRulestages for an inline math group (\(…\),$…$),inline. - MATH_
RULE - The registered name of the rule of last resort of the math groups,
flm.math.lower.default(MathGroupRule). - PARAGRAPH_
RULE - The registered name of the paragraph rule,
ParagraphRule. - UNKNOWN_
ENVIRONMENT_ RULE - The registered name of the unattributed-environment rule,
UnknownEnvironmentRule. - UNKNOWN_
MACRO_ RULE - The registered name of the unattributed-macro rule,
UnknownMacroRule. - VERBATIM_
RULE - The registered name of the verbatim rule,
VerbatimRule.
Functions§
- default_
rules - The six default rules of this module, one per structural element that
needs a rule, as values a feature can register; the
loweringfeature registers them. - is_
blank - Whether
nodeis blank: a node that is whitespace, such as~and\(its element carries the aspectWhitespace), or text made of whitespace alone: the space, the tab, the carriage return and the line feed. Text holding the character U+00A0 is not blank.stage_trimmedleaves blank nodes out at the edges of a run. - lower_
arg_ named_ or_ nothing lower_arg_or_nothingfor the argument namednameinstead of one at a position.- lower_
arg_ or_ nothing - Lowers the content of the argument at
index(in invocation order) ofnode, or produces nothing when the parse left that argument absent after a parse error. - lower_
blocks_ with_ edges - Lowers
content(a run of sibling nodes holding paragraphs and blocks, or inline content) as blocks, withleadingat the start of the first paragraph’s inline content andtrailingat the end of the last one, and returns the blocks. - lower_
paragraph - Stages one
flm.pres.parholdingleading, then the inline content of the paragraphnodelowered through the rules, thentrailing, and returns it. - stage_
trimmed - Stages
content, a run of inline content, with the whitespace at both of its ends trimmed, and returns the staged nodes. The whitespace and the comments before its first content and after its last are left out, and the text at either edge is staged without its leading or its trailing whitespace. Everything between the two edges is lowered through the rules unchanged. Content holding only whitespace and comments stages nothing. - stage_
trimmed_ runs stage_trimmedover several runs of siblings read as one run of content, the edges being those of the whole. Thequotefeature uses it for the lines of a quotation’s lines section, which are cut into runs at each\indent.