> My use case is parsing Typescript type definitions.
> Edit: unfortunately, this seems to be a JNI bridge to the Rust code in SWC, I was hoping for a JVM-native solution.
Maybe tree-sitter[0] TypeScript support[1] could do the trick?
Tree-sitter is a parser generator tool and an incremental
parsing library. It can build a concrete syntax tree for a
source file and efficiently update the syntax tree as the
source file is edited.
I get the sense that treesitter is more for syntax highlighting than for real parsing, since I raised this issue[0] a while ago and I don't think anyone's really interested in it (not really interested enough myself in tree-sitter to see if it can be fundamentally solved; solving it involves making almost all production rules in the grammar parametric over two booleans).
Admittedly I haven't tested the TypeScript treesitter grammar, but I'd be surprised if the issue is fixed there. I've put together a sample file[1] that demonstrates various cases of these context dependencies. If I remember correctly, Sublime's highlighter was the best at handling these cases out of various editors I tried, though it still failed at some of the ones at the bottom involving multi-line function expressions within object literal keys. GitHub/gist uses treesitter, so you'll notice that sometimes the "REGEX" and "DIVISION" blocks are inconsistently coloured, but a correct parser should associate a colour consistently to them. Not demonstrated here, but inserting a multi-line comment in a file that is parsed incorrectly will throw the entire thing off.
If the tree-sitter runtime requirements are prohibitive and a pure JVM solution (IOW, no JNI) mandatory, then I'd recommend using antlr[0] with its representative grammar[1] as a starting point. See here[2] for more details.
I agree that the Antlr Typescript grammar is underwhelming, and I also agree with the difficulty of not having a well defined owner of the project to interact with. My main use case is parsing TS type definitions, and the grammar from the grammars-v4 repo doesn't parse anything starting with 'declare', which is pretty fundamental.
> Edit: unfortunately, this seems to be a JNI bridge to the Rust code in SWC, I was hoping for a JVM-native solution.
Maybe tree-sitter[0] TypeScript support[1] could do the trick?
HTH0 - https://tree-sitter.github.io/tree-sitter/
1 - https://github.com/tree-sitter/tree-sitter-typescript