Anouncement: ANTLR4 for Typescript

887 views
Skip to first unread message

Mike Lischke

unread,
Jun 12, 2022, 9:32:46 AM6/12/22
to 'ANTLR announcements
Hi,

Some of you already know my plans to port ANTLR4 to Typescript, thereby creating a new ANTLR4 TS runtime (as an alternative to antlr4ts). I'd like to take the next step now, for your information and to get potential fellows to hack with me on that code.

There are actually 2 top level projects here:

1. A tool to convert Java to Typescript https://github.com/mike-lischke/java2typescript.
2. The TS port of ANTLR4 https://github.com/mike-lischke/a4tstool.

Both of which are still work in progress and released under the MIT license. The TS runtime is just a part of the ANTLR4 tool and will later be merged to the main ANTLR4 (Java) repository as yet another target language. The java2typescript project is of course using ANTLR4 (based on the antlr4ts runtime, which will ultimately be replaced with the new TS runtime) and on it's own an interesting parsing project for those of you who are looking for a cool project that uses ANTLR4.

The converter is already pretty matured and can convert Java code with only very few syntax problems, handling even complicated Java expressions like overloaded (generic) methods + constructors, explicit constructor invocation, nested static and non-static classes and so on (<= Java 11). There are Java SDK polyfills for classes needed by the generated TS code (like java.lang.StringBuilder), which are easy to extend with more classes, as the need arises. There's a readme in the lib/java folder explaining how the polyfills are organised and how to extend them.

The runtime (while completely converted) does not fully compile yet, because some manual fixes are still required.

Thanks,

Terence Parr

unread,
Jun 12, 2022, 1:02:27 PM6/12/22
to antlr-di...@googlegroups.com
Hi Mike, looks like some amazing work. I just tried implementing a webpage that would operate like the antlr plugin for intellij/jetbrains.  Added notes to 


If there is ever a complete TS/JS solution, then I think building single page app would be a lot easier. At the moment I need a server that runs the java tool and sends generated parsers back.

Ter

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/antlr-discussion/F124CBC7-334A-49FE-8E9A-63CB3CD7474E%40googlemail.com.

Mike Lischke

unread,
Jun 13, 2022, 4:23:08 AM6/13/22
to 'ANTLR announcements

If there is ever a complete TS/JS solution, then I think building single page app would be a lot easier. At the moment I need a server that runs the java tool and sends generated parsers back.

I added my thoughts there. For just running test input against an own grammar it is enough to generate interpreter data.





ivan.ko...@gmail.com

unread,
Jun 21, 2022, 5:29:00 PM6/21/22
to antlr-discussion
Hi. It looks like github discussions now is official place for disscusions like this :) https://www.antlr.org/support.html I missed the topic because I rarely visit this site.

понедельник, 13 июня 2022 г. в 11:23:08 UTC+3, mike.l...@googlemail.com:

ivan.ko...@gmail.com

unread,
Jun 21, 2022, 8:06:43 PM6/21/22
to antlr-discussion
Does it makes sense to replace JS runtime with TS one? TS can be compiled to JS. Moreover maybe it makes sense to use only Java code and compile it to TS with your converter? Runtime maintaining and making them in sync is very laborious.

среда, 22 июня 2022 г. в 00:29:00 UTC+3, ivan.ko...@gmail.com:

Mike Lischke

unread,
Jun 22, 2022, 3:50:27 AM6/22/22
to 'ANTLR announcements
Hi Ivan,


Does it makes sense to replace JS runtime with TS one? TS can be compiled to JS. Moreover maybe it makes sense to use only Java code and compile it to TS with your converter? Runtime maintaining and making them in sync is very laborious.

Currently there are no plans to remove the JS runtime. At a later point in time we can generate it, however, from the TS runtime. But still: the JS runtime needs to be provided separately, to avoid forcing users to install something they don't want (the transpiler). But since the JS runtime is usually used in a web environment (browser), it would pay off to use a bundler (e.g. webpack) to generate a minified JS bundle from the TS runtime. Just a thought for the future.

The current approach is indeed to take the Java code, run it through the converter to get TS code and then fix the machine translated output to work correctly. The conversion process is so quick that it is possible to run it iteratively. It's possible to protect already finished files to avoid losing their corrected content. With the same approach you can easily re-generate individual files whenever a new version of ANTLR4 comes out.


Reply all
Reply to author
Forward
0 new messages