antlr-kotlin
antlr-kotlin copied to clipboard
How do you plan to keep this codebase to be in sync with the antlr core?
Maybe it is easier than it seems at first sight? :)
Well, I do not think there is so much work going on on ANTLR core so I do not expect this to be hard. Eventually I would like to get this merged into the main repository but before that is possible we need to improve the testing of this project
Hi @ftomassetti I actually forked this from you last year some time. It took a few tweaks for me to actually get it parsing and running my grammar correctly(https://github.com/ftomassetti/antlr-kotlin/compare/master...tim-patterson:master). And here's the grammar and tests I used with it - (https://github.com/tim-patterson/sql-parser) - reasonably complete sql parser.
While I think its a great idea having a kotlin runtime what I found is:
- The performance in javascript land wasn't great, the code was spending a huge amount of time in the kotlin js runtime doing "instanceof" checks.
- The current kotlin antlr code is based on an incomplete port of the java code with large parts still commented out - some of these turned out to be quite important and in some cases the converted code didn't quite follow the same semantics as the java code (esp around switch statements), both of these caused some quite hard to track down bugs....(not necessarily crashes just incorrect parsing)
While I'm very impressed that you managed to get this running I can't help but think that maybe the better approach here is to simply use the kotlin multiplatform expect/actual to build a common abstraction over the existing js and java runtimes thereby being able to take advantage of the existing runtimes that have been tuned and tweaked for their target platforms with the upshot that the maintenance burden would be much less.
I know you might be quite invested in your current approach and so this may not seem that constructive, for that I apologize.
Tim
Hi Tim, sure more work is needed on this (I did not invest a huge time on this). However people are already using it and to some extent this works.
I have nothing against your approach, the only issue is: who has the time to implement this? Would you be willing to work on that?
I think we need for sure to generate Kotlin multi-platform code, so the wrapper would be just around the runtime. The generated code should be able to work with the multi-platform wrapper of the two runtimes. How hard would it be to generate code that works with that wrapper? I am not sure.
The current runtime is derived from the Java one, so I am not surprised it performs better on the JVM than on JavaScript
Additionally, the current solution would probably work with Kotlin Native as well...
exactly @NorbertSandor , good point that I forgot about
By the way the key of having a multi-platform project for parsers is for me the possibility of building full multi-platform tools like compilers, interpreters, maybe even editors
BTW @tim-patterson it would be interesting to get some of your fixes merged back into this project
@tim-patterson I started looking into that but I could use some help https://github.com/Strumenta/antlr-kotlin/pull/16
Actually, I'm very interested in supporting it as an official ANTLR target since I'm working both on ANTLR and Kotlin 😃
Eventually I would like to get this merged into the main repository but before that is possible we need to improve the testing of this project
I think it makes sense to use official runtime tests that are used for all runtimes. I can help with porting a bit later when runtime infrastructure will be refactored.
Perfect, that would be great. Thank you for the offer
@KvanTTT fancy porting some useful grammars/runtime tests on this repo now that it's been upgraded? Would be cool 🔝
Hi! Currently we've started discussion on developing of the next version of ANTLR, specifically the language we are going to use. I suggest Kotlin since it has a lot of benefits. That's why I will not invest effort for supporting Kotlin runtime for the ANTLR 4.
Sounds good @KvanTTT.
Do you already have a time frame for the next version? e.g., 2025 (even if it's your guess).
Not yet, we are at the very beginning stage.
@KvanTTT reasonable. Is it possible to follow the discussion at some point?
Not yet. But I'll contact the owner since I think public discussion could be more useful.
Not yet. But I'll contact the owner since I think public discussion could be more useful.
That is amazing! We love ANTLR and Kotlin, and we built some abstractions over ANTLR that we use in building our parsers. By the way, in the version under development we also take advantage of some interesting features of the K2 compiler :D If at some point I can help providing feedback, or promoting what you are going to build, just let me know. It would be an honor to help in some way. Thank you for your amazing work!