-
In a test grammar I have a rule composed of only alternatives and one of this alternative is also composed of only alternatives. Like
You can also look at the Python parsing example, see the stmt and simple_stmt rules. But I was not able to figure it out when we have 2 or more levels. The tutorial/example on how to parse Python in fact as the same problem (see the stmt and simple_stmt rules) but it does not uses |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
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)
}
}``` |
Beta Was this translation helpful? Give feedback.
-
Thank you Marco for sharing this. I think this can be interesting also for @alessiostalla |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm not sure I understand. Where's the Python example you're talking about? Anyway, sure you can override |
Beta Was this translation helpful? Give feedback.
I've found it... indeed was pretty simple: override transform() to just skip the pure alternative rules plus altrnative labels: