Grammar-Kit to LSP

Just sharing a neat idea I’ve been playing with lately.

In building out Mermaid Studio, I built out 22 separate Grammar-Kit parsers and JFlex lexers and I’ve been wondering how I might be able to get a bit more value out of them.

The result is a pipeline for converting Grammar-Kit/JFlex to Kotlin and using Kotlin/Wasm to back a TypeScript language server with minimal manual work, so it can be used in a browser.

Here’s an early preview which implements semantic highlighting and error reporting using the AST generated by Grammar-Kit. It features Grammar-Kit based Mermaid Flowchart language support in VS Code.

All the highlights are semantic tokens derived from the Grammar-Kit parser’s element types. No TextMate highlighting at all.

The pipeline generates “Portable Psi,” so I can eventually write Kotlin annotators and inspections to these portable interfaces and then adapt them to separate lightweight IntelliJ and LSP capability wrappers.

Happy Friday!