Possible for generated supergrammars to generate actual hierarchies #4647
Replies: 2 comments
-
Can say that at least, yes, as alluded to in the various documentation formats, rules are inherited, albeit in name only. However, from a generated code cohesion perspective, I would say it is anything but cohesive in terms of class hierarchy. So if that is the goal, does require at least some sort of author, or grammar subscriber, at any rate, interface intervention to achieve that level of cohesion. |
Beta Was this translation helpful? Give feedback.
-
This is one thing I was able to consider. Which allows for a kind of base class comprehension of common contextual concerns, protected virtual void BeforeEnterLocation<C>(C context) where C : ParserRuleContext { ... }
protected virtual void AfterEnterLocation<C>(C context) where C : ParserRuleContext { ... }
protected virtual void BeforeExitLocation<C>(C context) where C : ParserRuleContext { ... }
protected virtual void AfterExitLocation<C>(C context) where C : ParserRuleContext { ... } When their timing happening at the indicated ways, before/after at either of the enter/exit generated methods. |
Beta Was this translation helpful? Give feedback.
-
I'm sure I'm not the first to have had this thought.
I have a grammar B which really wants to be a superset of grammar A. I know I can kinda sorta get there by importing grammar A. Although I am not 💯 percent certain what gets generated, yet. They should really share the same rules together, and of course B utilizes many in fact all the same lexicon as A.
At least in the CSharp generated code, I do not see an actual class hierarchy going on, i.e.
But, probably more importantly, also in terms of the listener code generation, because this is really where we want the DSL synthesis to occur, IMO.
Perhaps kinda sorta we could pin such a listener interface sharing underneath the base class, maybe. But that just feels a bit of a kludge, not really what we're after if the rules are not derived, overridden, things of this nature.
Could maybe gen up a separate class structure that emulates this, and proxy into the parser features. But just feels like extra work, when perhaps Antlr could be doing more of that heavy lifting smarter.
Thoughts? 🧠 💡
Beta Was this translation helpful? Give feedback.
All reactions