# How do you iterate on your grammars efficiently?

**URL:** <https://discuss.codemirror.net/t/how-do-you-iterate-on-your-grammars-efficiently/4349>\
**Category:** Lezer\
**Created:** [May 4, 2022, 9:55pm UTC](https://discuss.codemirror.net/t/how-do-you-iterate-on-your-grammars-efficiently/4349 "2022-05-04T21:55:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaledu](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/kaledu/32/2041_2.png) [@kaledu](https://discuss.codemirror.net/u/kaledu)\
**Post date:** [May 4, 2022, 9:55pm UTC](https://discuss.codemirror.net/t/how-do-you-iterate-on-your-grammars-efficiently/4349/1 "2022-05-04T21:55:18Z")

</div>

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/](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.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [May 5, 2022, 6:40am UTC](https://discuss.codemirror.net/t/how-do-you-iterate-on-your-grammars-efficiently/4349/2 "2022-05-05T06:40:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kaledu](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/kaledu/32/2041_2.png) [@kaledu](https://discuss.codemirror.net/u/kaledu)\
**Post date:** [May 5, 2022, 11:46pm UTC](https://discuss.codemirror.net/t/how-do-you-iterate-on-your-grammars-efficiently/4349/3 "2022-05-05T23:46:31Z")

</div>

LOL it’s working.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Tdsone](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/tdsone/32/2052_2.png) [@Tdsone](https://discuss.codemirror.net/u/Tdsone)\
**Post date:** [May 7, 2022, 7:41am UTC](https://discuss.codemirror.net/t/how-do-you-iterate-on-your-grammars-efficiently/4349/4 "2022-05-07T07:41:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tdsone](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/tdsone/32/2052_2.png) [@Tdsone](https://discuss.codemirror.net/u/Tdsone)\
**Post date:** [May 7, 2022, 7:43am UTC](https://discuss.codemirror.net/t/how-do-you-iterate-on-your-grammars-efficiently/4349/5 "2022-05-07T07:43:04Z")

</div>

Also checkout this [What's the best to test and debug grammars? - #5 by grayen](https://discuss.codemirror.net/t/whats-the-best-to-test-and-debug-grammars/2542/5)
