hedy icon indicating copy to clipboard operation
hedy copied to clipboard

Parsing in indenter instead of string hacking

Open Felienne opened this issue 3 years ago • 4 comments

I made a half-assed solution for checking whether a line needs indentation, of course this is not pretty:

https://github.com/Felienne/hedy/blob/30c35fd3f0e6fdd687a9868e748d2e36c7c93f98/hedy.py#L1501-L1510

This could be improved by actually parsing the line with a subset of the grammar that only allows for the first line of the repetition (potentially per level so that in level 9 we do not give an indentation error with a misused repeat because that would be confusing.

Felienne avatar Nov 09 '21 06:11 Felienne

In Lark there's a class called Indenter, that is used to parse space relevant languages. Could we use that for Hedy? I was looking into it and seems promising, but I don't know if there's a reason why we don't use it.

https://lark-parser.readthedocs.io/en/latest/examples/indented_tree.html

jpelay avatar Nov 09 '21 13:11 jpelay

The reason we don't use it is that when I was looking into it, it did not work with our Earley parser, but maybe by now it does? Feel free to look into it, you might know more that I do!

Felienne avatar Nov 09 '21 13:11 Felienne

Yes, you're right! It does work with Earley, but only using the standard lexer, and I think that is no help for us, which is a boomer.

jpelay avatar Nov 15 '21 00:11 jpelay

Closed by #2892

Felienne avatar Jun 14 '22 19:06 Felienne