This works great except that the closing brace inside the inner string closes the directive. How should I approach making quotes inside the DirectiveContent hide the closing brace?
This isn’t something that Lezer can do, really. You could include a limited JavaScript tokenizer in your outer language, but there’s no way to defer to another parser and then pick up the parsing again after that has finished an expression (the outer parser runs to completion before the inner parser gets involved).
Thanks for the clarification. It explains why I haven’t seen any non-trivial examples of mixed language parsing without an external tokenizer. I’ll look closer at what lezer-parser/html does for scriptTokens and work from there.
Although the original idea of using an external tokenizer is probably still the right approach for most people, I found that my language is simple enough I can include a minimal tokenizer in the outer language by expanding on the example in SrivishnuR’s question. It won’t fully support something like JavaScript (backticks don’t work right, for example), but I hope it will help others who are learning to use Lezer.