antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

JavaScript-Runtime makes it hard to work with the ATN

Open matthiasharzer opened this issue 9 months ago • 1 comments

I'm trying to build a suggestion system for my ANTLR4 grammer in a TypeScript project, based on this guide by Daniel Bazaco. It makes use of the ATN generated by ANTLR and distignuishes between the ATN-transitions using instanceof checks. However since the npm-bundle does neither export the ATN-transition, nor its types, it's virtualy impossible to distinguish between the different transition-types like AtomTransition, RuleTransition, etc.

Exporting the ATN transitions and adding its types wouldn't impact the functionality of the remaining runtime at all, there for I'd really like to see them added soon. It would make working with the ATN a lot easier.

I have already setup a PR #4805 which addresses this issue,

matthiasharzer avatar Apr 01 '25 10:04 matthiasharzer

I think people keep asking for the ATN types and objects to be exposed in all sorts of development environments. But the way I see it, I don't think they will ever do so (as hinted by https://github.com/antlr/antlr4/pull/4805#issuecomment-2776744816).

I'd suggest you simply apply your own patches to the source code! (Possibly using .diff files after fetching the runtime's codebase) Seeing as releases are not very frequent, it wouldn't be terribly hard to maintain in the long run on your own.

Edit: you could use patch-package..

0xENDER avatar Apr 05 '25 00:04 0xENDER

Resolved in https://github.com/antlr/antlr4/pull/4805#issuecomment-2799542156

matthiasharzer avatar Jun 27 '25 20:06 matthiasharzer