Skip to main content

Module lowering

Module lowering 

Source
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, a Compute stage of PerTree scope named flm.<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 holds flm.pres.par; where it holds a heading, flm.pres.block-heading; where it holds a reference, a flm.pres.link around the reference’s displayed content.
  • A decoration is a node whose element carries the Decoration aspect. 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_value lowers 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 is rank.
  • 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 the Lowerer (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_verbatim and copy_run_verbatim for opaque content; read_verbatim_content and stage_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; and lower_region_content, the plain shape of a node region lowered through Lowerer::lower_region.
  • table — LoweredTrees, the flm.lowered.<backend> table, and LoweredAddr, 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, and lower_content_pointer, the lowering every such node’s rule calls, with a check supplied by the rule’s own feature.
  • error — the flm.lowering.* conditions and flm.verbatim.content-not-characters, and the recovery after each.
  • feature — the lowering feature, 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_tree and lower_value, which turn one tree into one lowered tree, and the implementation of the Lowerer every 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) and MathUnprocessed (flm.math.unprocessed).
feature
The lowering feature: 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.