Skip to main content

Module rules

Module rules 

Source
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:

elementlowers torule
flm.paragraphflm.pres.parParagraphRule
flm.mathflm.pres.span of role flm.math, and an ErrorMathGroupRule
flm.verbatimflm.pres.verbatimVerbatimRule
flm.unknown.macroflm.pres.unknownUnknownMacroRule
flm.unknown.environmentflm.pres.unknownUnknownEnvironmentRule
flm.fieldnothing, and an ErrorFieldRule

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§

FieldRule
Lowers flm.field to nothing and reports FieldNotRead: a field that reaches a backend on its own is a fault of the construct that absorbed it.
MathGroupRule
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 a flm.pres.span of role flm.math (MATH) and kind inline or display (see the module documentation, A math group is an Error until a feature processes mathematics).
ParagraphRule
Lowers flm.paragraph to a flm.pres.par holding the paragraph’s lowered inline content, through lower_paragraph.
UnknownEnvironmentRule
Lowers flm.unknown.environment (an environment no feature declares) to a flm.pres.unknown holding its lowered body.
UnknownMacroRule
Lowers flm.unknown.macro (a macro no feature declares) to a childless flm.pres.unknown carrying its source text, \name.
VerbatimRule
Lowers flm.verbatim to flm.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 ParagraphRule requires: the table of trees the block-structure rewrite writes, declared by the blocks feature. 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 MathGroupRule stages for a displayed math group (\[…\], $$…$$), display.
MATH_INLINE_KIND
The kind of the span MathGroupRule stages 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 lowering feature registers them.
is_blank
Whether node is blank: a node that is whitespace, such as ~ and \ (its element carries the aspect Whitespace), 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_trimmed leaves blank nodes out at the edges of a run.
lower_arg_named_or_nothing
lower_arg_or_nothing for the argument named name instead of one at a position.
lower_arg_or_nothing
Lowers the content of the argument at index (in invocation order) of node, 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, with leading at the start of the first paragraph’s inline content and trailing at the end of the last one, and returns the blocks.
lower_paragraph
Stages one flm.pres.par holding leading, then the inline content of the paragraph node lowered through the rules, then trailing, 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_trimmed over several runs of siblings read as one run of content, the edges being those of the whole. The quote feature uses it for the lines of a quotation’s lines section, which are cut into runs at each \indent.