ParseTreeToASTTransformer

open class ParseTreeToASTTransformer(issues: MutableList<Issue> = mutableListOf(), allowGenericNode: Boolean = true, val source: Source? = null) : ASTTransformer

Implements a transformation from an ANTLR parse tree (the output of the parser) to an AST (a higher-level representation of the source code).

Constructors

Link copied to clipboard
constructor(issues: MutableList<Issue> = mutableListOf(), allowGenericNode: Boolean = true, source: Source? = null)

Functions

Link copied to clipboard
fun addIssue(message: String, severity: IssueSeverity, range: Range?): Issue
Link copied to clipboard
inline fun <P : ParserRuleContext> registerNodeFactoryUnwrappingChild(): NodeTransformer<P, Node>

Alternative to registerNodeFactoryUnwrappingChild(KClass) which is slightly more concise.

Link copied to clipboard
inline fun <S : Any, T : Node> registerNodeTransformer(crossinline transformer: S.(ASTTransformer) -> T?): NodeTransformer<S, T>
fun <S : Any, T : Node> registerNodeTransformer(kclass: KClass<S>, transformer: (S) -> T?): NodeTransformer<S, T>
fun <S : Any, T : Node> registerNodeTransformer(kclass: KClass<S>, transformer: (S, ASTTransformer) -> T?): NodeTransformer<S, T>
fun <S : Any, T : Node> registerNodeTransformer(kclass: KClass<S>, transformer: (S, ASTTransformer, NodeTransformer<S, T>) -> T?): NodeTransformer<S, T>
fun <S : Any, T : Node> registerNodeTransformer(source: KClass<S>, target: KClass<T>, parameterConverters: List<ParameterConverter>): NodeTransformer<S, T>
Link copied to clipboard
fun <P : ParserRuleContext> registerNodeTransformerUnwrappingChild(kclass: KClass<P>): NodeTransformer<P, Node>

Often in ANTLR grammar we have rules which wraps other rules and act as wrapper. When there is only a ParserRuleContext child we can transform that child and return that result.

Link copied to clipboard
inline fun <S : RuleContext, T : Node> ParseTreeToASTTransformer.registerTrivialPTtoASTConversion(vararg nameConversions: Pair<KCallable<*>, KCallable<*>>)
inline fun <S : RuleContext, T : Node> ASTTransformer.registerTrivialPTtoASTConversion(vararg nameConversions: Pair<String, String>)
Link copied to clipboard
open override fun transform(source: Any?, parent: Node?): Node?

Performs the transformation of a node and, recursively, its descendants. In addition to the overridden method, it also assigns the parseTreeNode to the AST node so that it can keep track of its range. However, a node transformer can override the parseTreeNode of the nodes it creates (but not the parent).

Link copied to clipboard
fun <T> ParseTreeToASTTransformer.translateCasted(original: ParserRuleContext): T

Translate the given node and ensure a certain type will be obtained.

Link copied to clipboard
fun <T> ParseTreeToASTTransformer.translateList(original: Collection<out ParserRuleContext>?): ObservableList<T>

Translate a whole collection into a mutable list, translating each element and ensuring the list has the expected type.

Link copied to clipboard
fun <T> ParseTreeToASTTransformer.translateOnlyChild(parent: ParserRuleContext): T

Translate the only child (of type ParseRuleContext) and ensure the resulting value as the expected type.

Link copied to clipboard
fun <T> ParseTreeToASTTransformer.translateOptional(original: ParserRuleContext?): T?

Translate the given node and ensure a certain type will be obtained, if the value is not null. If the value is null, null is returned.

Link copied to clipboard
inline fun <S : RuleContext, T : Node> ParseTreeToASTTransformer.unwrap(wrappingMember: KCallable<*>)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val source: Source? = null