AstRewriter

class AstRewriter(context: MutableContext, errorHandler: PipelineErrorHandler = requireNotNull(context.errorHandler) { "AstRewriter requires a pipeline error handler" }) : AstIterator<AstRoot>

An AstIterator that walks the AST and replaces every PrimitiveFunctionBackedNode whose backing function has been wrapped via .extend with an equivalent FunctionCallNode. It queues the synthesized calls on the context, and finally expands them in one pass so the rewritten tree is ready for rendering.

The traversal recurses into the children of FunctionCallNodes whose backing function is not extended (for example, the .tableofcontents call output contains a "Table of Contents" heading that should also pick up .extend {heading}). FunctionCallNodes whose backing function is extended are treated as opaque: their children are the wrapper's chosen output and must not be re-rewritten — otherwise the .super heading inside an .extend {heading} wrapper would be wrapped over and over.

Parameters

context

context to resolve extensions against and to register synthesized calls in

errorHandler

strategy used by the expander to handle errors raised by wrappers. Defaults to the error handler of the pipeline currently attached to context; fails fast if neither is available

See also

Constructors

Link copied to clipboard
constructor(context: MutableContext, errorHandler: PipelineErrorHandler = requireNotNull(context.errorHandler) { "AstRewriter requires a pipeline error handler" })

Functions

Link copied to clipboard
open override fun traverse(root: AstRoot): AstRoot

Runs the iterator from the given root node, traversing the node tree and visiting each node.