Closed eremmel closed 1 month ago
Here some more comment issues. After the update of Hedy some code at level 10 did not run any more due to fact that whitespace before comment token '#' is not considered. At level 10 any way strings needs quotes! But comment token should be allowed in quoted strings.
At level 10 you do not need quotes for string assignments. That is only as of level 12.
But there are also issues at level 12:
And the code, for easy reference.
i = 4 # met comment
print '[' i ']'
if i = 4
j = 4 # met comment
print '[' j ']'
if j = 4
print 'comments ok on level 1'
else
print 'comments not ok on level 1'
else
print 'comments not ok on level 0'
This code runs on levels 10 and 11 (though with incorrect output) and, as shown above, does not run at level 12.
Looks like the definition and implementation of comment starts with '#' i.s.o. regexp: \s#.$ (this regexp does not consider # in quoted strings). So should the definition of COMMENT in level1.lark not become: COMMENT: _SPACE? _HASH /([^\n]+)/
This breaks the catch with '_error_invalidspace', but it prevents that trailing spaces are added to many commands.
Another solution might be to introduce something as a 'command-line' Logically each command line consists of indent-block* command? comment?. But I do not know (yet) how indenting is covered. command-line: command ( _SPACE COMMENT)? | COMMENT Maybe still to think about comment-sign in a string.
Hi, would I be able to be assigned to this issue ?
This issue deserves a summary. Here is a list of all issues mentioned so far plus a couple of new issues which are tightly coupled to the old ones:
Indented comments (which appear in the bodies of commands such as if
and repeat
) are not allowed in all levels. For example:
repeat 3 times
# comment
print ‘3’
Resolution: this is a bug and will be addressed
Comments cannot appear at the end of indented commands in all levels. For example:
repeat 3 times
print '3' # comment
Resolution: this is a bug and will be addressed
In levels 4-11 when a variable is assigned a quoted string containing #, its value is printed only until the # sign. For example in level 11 the following program:
a is 'this is a # test'
print a
outputs 'this is a
Resolution: this is not a bug but the expected behavior of Hedy. In levels 4-11 only the print
and ask
commands require quotes. The assign command does not, which means the single quotes do not take precedence over the comment. Therefore, the variable value is indeed 'this is a
.
An issue which has not been mentioned but is tightly coupled to issue 3. is that printing a quoted string containing a # is not supported in all levels. In level 4, due to grammar ambiguity, the program would sometimes work. However, in all consecutive levels, it yields an error:
print 'comments start with the # sign'
Resolution: This is a bug and will be addressed
# add trailing space to the end of line 2
naam is 'James'
if naam is 'trailing space’
print 'shaken'
Resolution: this is a bug and will be addressed
In levels 2-11 the assign command will inconsistently add to the value all trailing spaces. This this is an interesting problem that touches upon language design choices, I created a separate issue: #5684.
The equality command removes spaces in levels 8-11. For example:
i = this is # met comment
print '[' i ']'
if i = ‘this is’
print i
The above command will not print anything because right-hand-side of the if
statement is transpiled to this is
instead of this is
.
Resolution: this is a bug and will be addressed
Describe the bug When you want to use comments in indented code section it is not allowed. Compiler gives a weird message.
Paste the Hedy code & level Levels tested with this code: 8, 11 and 18
Add a screenshot (optional) Error reported is all cases is:
Expected behavior Indented comments are allowed and does not impact program.
What machine and browser you were using (optional) N/A Error is generated by backend server