NodeTransformer

class NodeTransformer<Source, Output : Node>(val constructor: (Source, ASTTransformer, NodeTransformer<Source, Output>) -> Output?, val children: MutableMap<String, ChildNodeTransformer<Source, *, *>?> = mutableMapOf(), var finalizer: (Output) -> Unit = {}, var skipChildren: Boolean = false, var childrenSetAtConstruction: Boolean = false)

Transformer that, given a tree node, will instantiate the corresponding transformed node.

Constructors

Link copied to clipboard
constructor(constructor: (Source, ASTTransformer, NodeTransformer<Source, Output>) -> Output?, children: MutableMap<String, ChildNodeTransformer<Source, *, *>?> = mutableMapOf(), finalizer: (Output) -> Unit = {}, skipChildren: Boolean = false, childrenSetAtConstruction: Boolean = false)

Functions

Link copied to clipboard
fun getter(path: String): (Source) -> Any?
Link copied to clipboard

Tells the ASTTransformer whether this NodeTransformer already takes care of the node's children and no further computation is desired on that subtree. E.g., when we're mapping an ANTLR parse tree, and we have a context that is only a wrapper over several alternatives, and for some reason those are not labeled alternatives in ANTLR (subclasses), we may configure the transformer as follows:

Link copied to clipboard
fun withChild(targetProperty: KMutableProperty1<*, *>, sourceAccessor: Source.() -> Any?): NodeTransformer<Source, Output>
fun withChild(targetProperty: KMutableProperty1<*, *>, sourceAccessor: Source.() -> Any?, scopedToType: KClass<*>): NodeTransformer<Source, Output>
fun <Target : Any, Child : Any> withChild(get: (Source) -> Any?, set: (Target, Child?) -> Unit?, name: String, scopedToType: KClass<*>? = null): NodeTransformer<Source, Output>

Specify how to convert a child. The value obtained from the conversion could either be used as a constructor parameter when instantiating the parent, or be used to set the value after the parent has been instantiated.

fun withChild(targetProperty: KProperty1<*, *>, sourceAccessor: Source.() -> Any?): NodeTransformer<Source, Output>
fun withChild(targetProperty: KProperty1<*, *>, sourceAccessor: Source.() -> Any?, scopedToType: KClass<*>): NodeTransformer<Source, Output>

Specify how to convert a child. The value obtained from the conversion can only be used as a constructor parameter when instantiating the parent. It cannot be used to set the value after the parent has been instantiated, because the property is not mutable.

Link copied to clipboard

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard