lezer / v6 overlay parser extension

Hi

These days I’m playing with CodeMirror v6.

My goal is to provide JS-like syntax highlighting/autocompletion inside mustache html templates inside curly braces.

Initial idea was to adjust lezer-html to make it treat content inside curly braces by nested js parser as if it was javascript (mustache is less powerful than generic javascript, but this would still work for me).
So I added
mustache { "{{" nest.jsParser "}}" } into lezer-html grammar entities just to realize that my mustache extension should work over html grammar and have higher priority. E.g. it should blend into text, it could blend across html elements / attributes whatever.
After playing a while with lezer-html parser grammar I concluded that I don’t quite get the way to accomplish my goal.

Found some brief pre-v6 example with overlay parsers CodeMirror: Overlay Parser Demo — maybe you have some extension points in mind to share that I don’t see yet or give some advice how would you start with that.

Thanks!

This doesn’t exist yet. I’m working on adding something like this to Lezer but it’s turning out to be tricky, and may take a while.

So as I understand overlay parser would be a way to go for this goal.
But are there other ways to implement it?

Like wrapping html lezer parser by mustache-aware syntax parser?
Could you give some insights how overlay parser is planned to work internally?

My current intention (but this may not work out) is to allow Lezer parsers to be extended with ‘injected parsers’, which on specific patterns in the input stop the outer parser and switch to a nested parser.

Ok let me know if there’s any beta build to try :slight_smile: