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.3k stars 285 forks source link

[BUG] Incorrect error message when an unquoted backslash is found in a print statement #3444

Closed jeremydavis519 closed 1 month ago

jeremydavis519 commented 1 year ago

Describe the bug Trying to use a backslash as an operator is, of course, a syntax error, but Hedy seems to get confused about where exactly the error is. This situation can arise if a student, having recently been given access to division, forgets which way the slash should be slanted.

In the example code below, Hedy gives an error starting like this:

Be careful. If you ask or print something, the text should start and finish with a quotation mark.

That's fine so far, but the error becomes confusing in the next sentence:

You forgot that for the text divided.

The problem is that divided was part of the quoted text.

Paste the Hedy code & level I tried this on level 6.

print '5 divided by 5 is ' 5 \ 5

Add a screenshot (optional) image

Expected behavior I expected the error to say that the backslash needed to be quoted, or perhaps all of 5 \ 5.

Ideally, though, Hedy would suggest using a forward slash instead, since that's probably what the student meant. I've seen some references to the Confusables package in other issues, and that might help in this case. Not sure, as I haven't looked into what that package does specifically.

What machine and browser you were using (optional) If the issue concerns things in the website, let us know:

Felienne commented 1 year ago

Thanks for a good catch! There are a few approaches here, we could add \ to the parser or maybe just output slightly different Python? I am not even sure myself why the error is as it is, because both quotes should still be around the text? Maybe @jpelay can dive in?

jpelay commented 1 year ago

I am not even sure myself why the error is as it is, because both quotes should still be around the text? The cause of this is that the error returns as unquoted text the first child of the error_print_nq node:

https://github.com/hedyorg/hedy/blob/211948b660d9cada93317bc0fe89f39e9639293d/hedy.py#L997-L999

In the case of this code snippet it returns the second word of the first text 'divided', if we change that line, the error message changes accordingly.

Image

boryanagoncharenko commented 1 month ago

Nowadays the error indicates that there are missing quotes:

Screenshot 2024-08-06 at 14 43 00

However, it seems a bit off that the error points the whole text including the already quoted parts. It would be nicer to only mention the unquoted parts, e.g. 5 \ 5. Also, the double backslash should be addressed.