How do you iterate on your grammars efficiently?

Hey, I have a small DSL. I’d like to syntax highlight it in codemirror.

I had prototyped a tree-sitter grammar for it. That seemed to work. It took me many tries to get it right though!

I found https://lezer-sandbox.vercel.app/ through here, or I think somewhere in the official docs, but it doesn’t seem to be fully working currently. It says “Highlight is null”

I’ve read through the system guide. It looks like I need to build with lezer-generator, then write my own program to call “parse” (There’s no official parse cli?) and see how the tree looks?

How do I quickly check how highlighting looks?

Don’t want to sound like I’m criticizing the docs at all. Just want to make sure I’m aware of all the tooling.

The way I work on grammars is to set up a test suite with the syntax trees I want to see (see the test/ directories in the various parser repositories), since that provides a less lossy and more direct feedback on the way the grammar is working. Then I just hack on the grammar until it compiles and those tests pass. Adding highlighting after that tends to be straightforward.

1 Like

LOL it’s working.
Thanks!

If you like seeing the parse tree, I can recommend searching in this forum for a way to print the parse result. Makes it much easier to know what your parser did “wrong” and how to fix it.

1 Like

Also checkout this What's the best to test and debug grammars? - #5 by grayen

1 Like