hedyorg / hedy

Hedy is a gradual programming language to teach children programming. Gradual languages use different language levels, where each level adds new concepts and syntactic complexity. At the end of the Hedy level sequence, kids master a subset of syntactically valid Python.
https://www.hedy.org
European Union Public License 1.2
1.27k stars 282 forks source link

Parsing in indenter instead of string hacking #1213

Open Felienne opened 2 years ago

Felienne commented 2 years ago

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.

jpelay commented 2 years ago

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

Felienne commented 2 years ago

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!

jpelay commented 2 years ago

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.

Felienne commented 2 years ago

Closed by #2892