Expand description
Lowering: the stage that rewrites each frozen tree into the presentation tree one backend emits, the driver that runs it, and the rules and helpers every backend shares.
Lowering rewrites each frozen tree into a presentation tree for one
backend, by applying the lowering rule selected for each element, in
rounds, until only elements the backend writes natively remain; the result
is computed data in the table flm.lowered.<backend> (see backends,
lowering, and
outputs).
The frozen trees themselves never change (see frozen trees and computed
data).
After lowering, the backend’s emitter writes the output from the lowered
trees (for the text backend, super::text::emit).
The terms this module relies on:
- A backend is the registration bundle for one output format
(
BackendDef). Every backend registers exactly one lowering stage,LoweringStage, aComputestage ofPerTreescope namedflm.<backend>.lower. - A lowering rule is a named registry entity written for one element:
it declares what it requires, reads and produces, and implements
Lower, which stages (builds into the lowered tree) the element’s presentation for one backend (LoweringRule). The plan selects one rule per element and backend. - A presentation node is a node of a presentation element, an element
that never occurs in a source document (
super::pres). A lowered tree is built from presentation nodes and from nodes of the elements the backend writes natively: where the frozen tree holds a paragraph, the lowered tree holdsflm.pres.par; where it holds a heading,flm.pres.block-heading; where it holds a reference, aflm.pres.linkaround the reference’s displayed content. - A decoration is a node whose element carries the
Decorationaspect. When a rule stages a presentation node, the driver moves every decoration out of the node’s content slots into an attached slot of that node (see decorations, roles and kinds). - A piece is a document-level synthesized value that a backend places
before or after the document’s content
(
Piece);lower_valuelowers one, for the pieces stage (super::pieces). - A node region is one of a node’s arguments or one of its slots
(
NodeRegion). A rule may lower a node region of another node where its own node is placed, which is how a content pointer shows content written elsewhere.
Every rule works through the Lowerer, the only interface a lowering
rule has to the run, which the driver implements: through it the rule
lowers parts of its node, stages presentation nodes, splices a synthesized
value and lowers a node region of another node.
§Module map
stage—LoweringStage, the per-backend stage. The needs it declares when the plan is built are the union of the selected rules’ declarations (rules_needs, shared with every stage that lowers for a backend), and the number of rounds it allows isrank.driver—lower_tree, which runs the rounds over one tree;lower_value, which runs them over a synthesized value, such as a piece, after bringing it up to date; the implementation of theLowerer(lowering of a node’s parts, staging of presentation nodes with their provenance, decorations moved into attached slots, splicing a synthesized value, and the checks that a rule reads only what it declared). Also the helpers a rule calls:copy_subtree_verbatimandcopy_run_verbatimfor opaque content;read_verbatim_contentandstage_verbatim_content, through which every rule that stages verbatim content reads it as characters, reporting content that is not characters (ContentNotCharacters);lower_run, which hands a run of sibling nodes back to the ordinary rules; andlower_region_content, the plain shape of a node region lowered throughLowerer::lower_region.table—LoweredTrees, theflm.lowered.<backend>table, andLoweredAddr, the address of a node inside a lowered tree.rules— the default lowering rules of the structural elements, and the helpers that stage paragraphs and trimmed inline content for other rules.pointer—ContentPointer, the payload of a synthesized node that shows content written elsewhere without copying it, andlower_content_pointer, the lowering every such node’s rule calls, with a check supplied by the rule’s own feature.error— theflm.lowering.*conditions andflm.verbatim.content-not-characters, and the recovery after each.feature— theloweringfeature, which registers the presentation vocabulary, the default rules, the two native-set implications the driver relies on (native_implications) and two service slots.
Re-exports§
pub use driver::LoweringInputs;pub use driver::LoweringOutcome;pub use driver::VerbatimContent;pub use driver::copy_run_verbatim;pub use driver::copy_subtree_verbatim;pub use driver::lower_region_content;pub use driver::lower_run;pub use driver::lower_tree;pub use driver::lower_value;pub use driver::non_native;pub use driver::read_verbatim_content;pub use driver::stage_verbatim_content;pub use error::ContentNotCharacters;pub use error::FieldNotRead;pub use error::LoweringFailed;pub use error::MathUnprocessed;pub use error::NestingTooDeep;pub use error::NoRule;pub use error::RegionNotFound;pub use error::RoundsExceeded;pub use error::RuleFailed;pub use error::UnsupportedElement;pub use feature::FEATURE_NAME;pub use feature::LoweringFeature;pub use feature::NAMER_SLOT;pub use feature::REGIONS_SLOT;pub use feature::feature;pub use feature::native_implications;pub use pointer::ContentPointer;pub use pointer::PointerCheck;pub use pointer::lower_content_pointer;pub use rules::BLOCKS_STRUCTURED;pub use rules::FIELD_RULE;pub use rules::FieldRule;pub use rules::MATH_RULE;pub use rules::MathGroupRule;pub use rules::PARAGRAPH_RULE;pub use rules::ParagraphRule;pub use rules::UNKNOWN_ENVIRONMENT_RULE;pub use rules::UNKNOWN_MACRO_RULE;pub use rules::UnknownEnvironmentRule;pub use rules::UnknownMacroRule;pub use rules::VERBATIM_RULE;pub use rules::VerbatimRule;pub use rules::default_rules;pub use rules::is_blank;pub use rules::lower_arg_named_or_nothing;pub use rules::lower_arg_or_nothing;pub use rules::lower_blocks_with_edges;pub use rules::lower_paragraph;pub use rules::stage_trimmed;pub use rules::stage_trimmed_runs;pub use stage::LoweringStage;pub use stage::rank;pub use stage::rules_needs;pub use stage::selection_requires;pub use table::LoweredAddr;pub use table::LoweredTree;pub use table::LoweredTrees;pub use table::lowered_table;pub use table::lowered_table_name;
Modules§
- driver
- The lowering driver:
lower_treeandlower_value, which turn one tree into one lowered tree, and the implementation of theLowererevery lowering rule works through. - error
- This module defines the diagnostic conditions that are reported while a
document is lowered for a backend (see 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) andMathUnprocessed(flm.math.unprocessed). - feature
- The
loweringfeature: the registrations every backend relies on. - pointer
- Content pointers: synthesized nodes that show content written elsewhere in the tree, without copying it.
- rules
- The default lowering rules of the structural elements, and the helpers other rules use to stage paragraphs and trimmed inline content.
- stage
- The lowering stage of a backend,
LoweringStage, and the computations that plan construction gives it. - table
- The lowered-trees table, into which a backend’s lowering stage writes its result, and the address of a node inside a lowered tree.