Expand description
The input feature: \input{file}, which brings the content of another file into
the document where the command is written.
§What an author writes, and what it produces
An author writes \input{chapter.flm} to include the file chapter.flm. The
argument is the reference to the file, as plain characters; the embedding
program’s input resolver (InputResolver) finds and
reads the file it refers to (the flm program reads it relative to the folder of
the file that holds the command). The guide to the language describes the command
for authors (including files).
An included file is one of two kinds, as its front matter declares (see content inputs and heading inputs):
- A content input continues the text around the command: its content is parsed where the command is written, and every output shows it as if it had been written there. A paragraph begun before the command continues into the included content.
- A heading input opens with a heading and becomes a tree of its own in the
document (
crate::model::assemble). The command stays in the tree as a block, and every output writes the included tree where the command is.
When the file could not be brought in (its reference is not plain characters, no
file is found, the file includes itself, …), the parse reports the problem at the
command, and every output shows a mark where the content is missing (the dropped
mark flm.pres.dropped,
lowering::error, which gives the
reference).
§How a parse handles the command
The feature declares the command as an inclusion macro of the language
(SyntaxDef::Inclusion), whose one argument is the reference. What happens while
the document is parsed (the embedding program asked for the file, the content of a
content input parsed where the command is written) is done by the language layer
(crate::lang::input).
§The splicing rewrite
A rewrite stage runs before the document’s trees are frozen and turns one tree into
another (RewriteStage). The feature’s rewrite stage SPLICE
(flm.input.splice) replaces every command whose file was brought in by the file’s
content, in place of the command among its sibling nodes
(crate::lang::rewrites::input), and publishes the trees as SPLICED
(flm.input.spliced). It runs before the rewrites of the user definitions and of
the block structure, so that they, and every later stage, see one text: a paragraph
begun before the command continues into the included content, a list written there
nests in the list around the command, and a user definition used there is
expanded. The capability flm.input.spliced is a member of the collection
flm.validated, which every standard workflow
demands, so the rewrite runs in every plan of a standard workflow.
§The lowering rule
Only two kinds of \input command remain in the trees after the splicing rewrite,
and the rule RULE (flm.input.lower.default, InputRule), the default on
every backend, lowers both:
- The command of a heading input. The command places the included file’s tree.
For each such command in the rewritten trees, the run records the tree the command
places, and the document order enters that tree at the command
(
crate::core::run::order). The rule asks which tree the command places (Lowerer::placement) and lowers the command to aflm.pres.subtreenode that gives that tree, which every output writes where the command is. - A command whose file was not brought in. The parse reported the problem, and
the rule lowers the command to a
flm.pres.droppedmark that gives the reference (\input{chapter.flm}), on every output, so that a reader sees where content is missing.
A command of a heading input that a rewrite copied (a user definition whose
template writes twice the argument that holds the command) places its file at its
first copy only, because a file is placed at one place of the document. The run
reports each other copy (flm.run.placed-twice), and the rule lowers it to the same
dropped mark.
§Items
- The feature:
Input,feature,FEATURE. - The element:
ELEMENT(flm.input), and the argument rolePATH_ARG_ROLE(flm.input.path), which states that an argument holds a reference to another file whose content is read in (ArgDef::role). - The rewrite stage:
SPLICE,SPLICED. - The lowering rule:
RULE,InputRule,rule.
Structs§
- Input
- The
inputfeature: it registers the command\input, the splicing rewrite stageSPLICEand its membership in the collectionflm.validated, and the lowering ruleRULE. See the module documentation. - Input
Rule - The implementation of the lowering rule
RULE: it lowers the command of a heading input to aflm.pres.subtreenode that gives the tree the command places, and a command whose file was not brought in to aflm.pres.droppedmark that gives the reference. The command of a content input never reaches the rule, because the splicing rewrite replaced it. See the module documentation.
Constants§
- ELEMENT
- The name of the element of the command
\input,flm.input. - FEATURE
- The feature’s registered name,
input. - PATH_
ARG_ ROLE - The argument role of a reference to another file whose content is read
in,
flm.input.path: the role of the reference argument (REFERENCE_ARGUMENT) of\input. - RULE
- The name of the lowering rule of the command of a heading input and of a
command whose file was not brought in,
flm.input.lower.default(InputRule). - SPLICE
- The name of the splicing rewrite stage,
flm.input.splice, which replaces every command whose file was brought in by the file’s content. - SPLICED
- The table of trees that the splicing rewrite publishes, which is also the
capability it provides,
flm.input.spliced: the content of every included file is in place of its command, among the command’s sibling nodes.