# grammar for a language that is indent-sensitive

**URL:** <https://discuss.codemirror.net/t/grammar-for-a-language-that-is-indent-sensitive/6469>\
**Category:** Lezer\
**Created:** [May 13, 2023, 2:06pm UTC](https://discuss.codemirror.net/t/grammar-for-a-language-that-is-indent-sensitive/6469 "2023-05-13T14:06:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![forgodtosave](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/forgodtosave/32/3308_2.png) [@forgodtosave](https://discuss.codemirror.net/u/forgodtosave)\
**Post date:** [May 13, 2023, 2:06pm UTC](https://discuss.codemirror.net/t/grammar-for-a-language-that-is-indent-sensitive/6469/1 "2023-05-13T14:06:28Z")

</div>

Hi,

I am trying to write a simple parser ([link to repo](https://github.com/forgodtosave/mainsail/tree/Grammar-Indentation-Tracking/src/plugins/languages/KlipperConfigLanguage)) for a language that is indent-sensitive like python. However, I fail at the indentation tracking.  
The grammar rules are specially modeled on the python rules. And the external tokenizer is also almost copy and pate but with a few cuts (if I use the custom tokenizer in python, the indentation tracking still works).

for the following example I get this syntax tree ([generated with](https://gist.github.com/msteen/e4828fbf25d6efef73576fc43ac479d2))

```auto
test0| val:20
test1| val:asdf
test2| 
  val:21
test3| val:22

```

 ![image](https://discuss.codemirror.net/uploads/default/original/2X/9/99d51d1e28772990e1e9ac7e0e43eb88f49f9ca9.png)

Any ideas what I’m doing wrong?

---

<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 15, 2023, 10:09am UTC](https://discuss.codemirror.net/t/grammar-for-a-language-that-is-indent-sensitive/6469/2 "2023-05-15T10:09:27Z")

</div>

Nothing jumps out. Try building with `--names` and setting the environment variable `LOG=parse` to see what, exactly, the parser is doing.

---

<div class="post-metadata">

**Author:** ![forgodtosave](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/forgodtosave/32/3308_2.png) [@forgodtosave](https://discuss.codemirror.net/u/forgodtosave)\
**Post date:** [May 16, 2023, 9:32pm UTC](https://discuss.codemirror.net/t/grammar-for-a-language-that-is-indent-sensitive/6469/3 "2023-05-16T21:32:15Z")

</div>

Thanks for the answer. `LOG=parse` does not provide any additional output although I used `npx` with `--names`. `LOG=lr` works unfortunately I don’t see how this could help me.

Am I doing something wrong? Is there any other way to find the error?

---

<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 17, 2023, 7:45am UTC](https://discuss.codemirror.net/t/grammar-for-a-language-that-is-indent-sensitive/6469/4 "2023-05-17T07:45:56Z")

</div>

`LOG=parse` should always produce output. But you must provide it when _parsing_, not when generating the parse tables.

---

<div class="post-metadata">

**Author:** ![forgodtosave](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/forgodtosave/32/3308_2.png) [@forgodtosave](https://discuss.codemirror.net/u/forgodtosave)\
**Post date:** [May 18, 2023, 10:21am UTC](https://discuss.codemirror.net/t/grammar-for-a-language-that-is-indent-sensitive/6469/5 "2023-05-18T10:21:25Z")

</div>

Oh ok thanks for the information. I just don’t understand how I should provide the system variable in this case. And how do I then display the logging result? I couldn’t find anything regarding this online.

---

<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 18, 2023, 1:52pm UTC](https://discuss.codemirror.net/t/grammar-for-a-language-that-is-indent-sensitive/6469/6 "2023-05-18T13:52:42Z")

</div>

Run your parse in node, and start it `LOG=parse node myscript.js`.

---

<div class="post-metadata">

**Author:** ![forgodtosave](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/forgodtosave/32/3308_2.png) [@forgodtosave](https://discuss.codemirror.net/u/forgodtosave)\
**Post date:** [May 19, 2023, 2:32pm UTC](https://discuss.codemirror.net/t/grammar-for-a-language-that-is-indent-sensitive/6469/7 "2023-05-19T14:32:11Z")

</div>

> [@marijn](#):
>
> Run your parse in node

I’m sorry I don’t really understand what you mean by that. Is there also a good possibility for vue cli projects?

---

<div class="post-metadata">

**Author:** ![forgodtosave](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/forgodtosave/32/3308_2.png) [@forgodtosave](https://discuss.codemirror.net/u/forgodtosave)\
**Post date:** [May 27, 2023, 1:30pm UTC](https://discuss.codemirror.net/t/grammar-for-a-language-that-is-indent-sensitive/6469/8 "2023-05-27T13:30:49Z")

</div>

I finally found the problem: the problem was the wrong order of “`@tokens, @context, @external tokens`”. It seems that the external tokens must be mentioned before the tokens.
