/

On this page

Pipeline - Tree rewrite

Main packages: core.ast.iterator, core.pipeline.stages

Once the queued function calls have been expanded, the AST is rewritten in place to apply any show-rules via user-defined extensions.

Several built-in nodes, such as headings, are primitive function-backed: the stdlib exposes functions whose parameters mirror the node’s properties. Whenever an .extend wrapper is registered for that name, every occurrence of the primitive must be routed through the wrapper.

The tree rewrite stage walks the AST depth-first and, for each primitive whose backing function has been extended, replaces the node with an equivalent function call.

As an optimization, the whole stage is skipped when no extension is registered in the document, which is the common case.