antlr-kotlin icon indicating copy to clipboard operation
antlr-kotlin copied to clipboard

How do you plan to keep this codebase to be in sync with the antlr core?

Open NorbertSandor opened this issue 6 years ago • 17 comments
trafficstars

Maybe it is easier than it seems at first sight? :)

NorbertSandor avatar May 08 '19 08:05 NorbertSandor

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

ftomassetti avatar May 08 '19 15:05 ftomassetti

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:

  1. 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.
  2. 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

tim-patterson avatar May 11 '19 11:05 tim-patterson

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

ftomassetti avatar May 11 '19 16:05 ftomassetti

Additionally, the current solution would probably work with Kotlin Native as well...

NorbertSandor avatar May 11 '19 17:05 NorbertSandor

exactly @NorbertSandor , good point that I forgot about

ftomassetti avatar May 12 '19 08:05 ftomassetti

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

ftomassetti avatar May 12 '19 08:05 ftomassetti

BTW @tim-patterson it would be interesting to get some of your fixes merged back into this project

ftomassetti avatar May 12 '19 08:05 ftomassetti

@tim-patterson I started looking into that but I could use some help https://github.com/Strumenta/antlr-kotlin/pull/16

ftomassetti avatar May 12 '19 08:05 ftomassetti

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.

KvanTTT avatar Jan 09 '22 16:01 KvanTTT

Perfect, that would be great. Thank you for the offer

ftomassetti avatar Jan 10 '22 12:01 ftomassetti

@KvanTTT fancy porting some useful grammars/runtime tests on this repo now that it's been upgraded? Would be cool 🔝

lppedd avatar Dec 19 '23 00:12 lppedd

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.

KvanTTT avatar Dec 19 '23 17:12 KvanTTT

Sounds good @KvanTTT.
Do you already have a time frame for the next version? e.g., 2025 (even if it's your guess).

lppedd avatar Dec 19 '23 17:12 lppedd

Not yet, we are at the very beginning stage.

KvanTTT avatar Dec 19 '23 18:12 KvanTTT

@KvanTTT reasonable. Is it possible to follow the discussion at some point?

lppedd avatar Dec 19 '23 18:12 lppedd

Not yet. But I'll contact the owner since I think public discussion could be more useful.

KvanTTT avatar Dec 19 '23 18:12 KvanTTT

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!

ftomassetti avatar Dec 20 '23 07:12 ftomassetti