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

[UI] Syntax highlighting variables #4599

Open Felienne opened 9 months ago

Felienne commented 9 months ago

Discussed in https://github.com/hedyorg/hedy/discussions/3929

Originally posted by **stevecopley** January 12, 2023 Can't find any prior mention of this in the discussions, so... To aid understanding the concept of user-created variables, it would be helpful to subtly highlight variables within print statements, so that they are visually different to the surrounding text. Students could then see that their variables are placed within the text.
Felienne commented 9 months ago

We had a PR open for this (#3988) which could be useful if we try this in the new CodeMirror system, esp since CodeMirror has a more powerful syntax highlighting system!

jpelay commented 9 months ago

Yes, CodeMirror can parse the input using the Lezer parser generator. Hedy's syntax has some ambiguities: variables and text being one of them. However, Lezer also let's you build an external tokenizer if the Lezer built in one won't suffice. I think this feature can be used to built a data structure where we store the variables, but I'm not 100% sure of this.

Felienne commented 9 months ago

It is not a high priority (since the don't have it now either) but it would be cool!! We could even highlight (with an error underline) undefined variables too!