Skip to content

ParseTree to AST transformation with alternative rules #169

Answered by mar9000
mar9000 asked this question in Q&A
Discussion options

You must be logged in to vote

I've found it... indeed was pretty simple: override transform() to just skip the pure alternative rules plus altrnative labels:

abstractRuleA:
    abstractRuleB  #abstractRuleBAlias
    | ruleC #ruleCAlias
    ;
abstractRuleB: 
    abstractRuleD #abstractRuleDAlias
    | ruleE #ruleEAlias
    ;
override fun transform(source: Any?, parent: Node?): Node? {
        return when (source) {
            is AbstractRuleBAliasContext -> transform(source.abstractRuleB(), parent)
            // other rules...
            else -> super.transform(source, parent)
        }
}```

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by mar9000
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@mar9000
Comment options

@alessiostalla
Comment options

@mar9000
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants