congo-cc / congo-parser-generator

The CongoCC Parser Generator, the Next Generation of JavaCC 21, which in turn was the next generation of JavaCC
https://discuss.congocc.org/
Other
36 stars 11 forks source link

Injection into Node.Visitor seems to be not possible #45

Closed adMartem closed 5 months ago

adMartem commented 1 year ago

INJECT Node.Visitor results in a syntax error, and INJECT Visitor is simply ignored. I'll look at this in more detail unless someone else [Jon] wants to deal with it. For now I'll just add my injection to the concrete instance(s).

revusky commented 1 year ago

Yeah, I guess it's true that you can't inject code into an inner class. I hadn't really given that much thought. I don't think I was consciously creating any such impedance when I made Node.Visitor an inner class. I think it was mostly just organizational. The same applies to Node.TerminalNode, which I created as a base API for polyglot projects. Along with Node.NodeType.

But what is the use case for injecting code into Node.Visitor? (I'm not saying that there absolutely is no use case. Probably there is if you want to do that, but it isn't clear to me.)

I suppose you've noticed that I get pretty good use internally out of Node.Visitor. The Reaper is a Node.Visitor, for example. So is the JavaFormatter. Just today and yesterday, I wrote a CSharpFormatter. that is pretty imperfect, but it actually formats most Csharp code you throw at it more or less okay. These things don't really even have to be perfect since the code compiles the same anyway. The Reaper is also pretty imperfect. But really, t just doesn't seem to warrant the effort to make it any better. I guess I'll writea Reaper for CSharp pretty soon.

But anyway, I guess it is a flaw that you can't inject into an inner class, but offhand, I don't think this is very high up on my TODO list, so if you want to figure out how to allow that you can, of cource. It looks pretty margiinal to me, thought it would of course have value in terms of familiarizing yourself with the code.

adMartem commented 11 months ago

I honestly can't remember why I was trying to do this. If I recall it, I'll add the narrative here, but it must not have been very important. I probably tried to do it, noticed it didn't work, and recorded it here and moved on.

adMartem commented 5 months ago

Is this something that should be done when it's convenient, or just not supported? Or just one of the polyglot issues that might be solved by other changes in that area?