Open iacore opened 1 year ago
Not exactly what is happening. It is confusing, but here is what is going on:
"
- and starts a string."
in the input buffer is interpreted as a new string.Now this is confusing but consistent with how other parser errors are handled.
Shouldn't REPL stop parsing on first parse error? like (parse "\"a\\b\"")
Shouldn't REPL stop parsing on first parse error? like
(parse "\"a\\b\"")
No, since a user at a repl would want to continue after any errors to enter more data. More generally, with some (bad) code snippet like:
(def a 123) ) (+ 1 2 3)
(Note the extra close parentheses) - the repl will print both 123
and 6
with an error in between them.
Shouldn't REPL stop parsing on first parse error? like
(parse "\"a\\b\"")
No, since a user at a repl would want to continue after any errors to enter more data. More generally, with some (bad) code snippet like:
(def a 123) ) (+ 1 2 3)
(Note the extra close parentheses) - the repl will print both
123
and6
with an error in between them.
I mean, the REPL can print the error, and don't do anything until the user fixed the syntax error. For example, Python
> python
Python 3.11.3 (main, Apr 7 2023, 00:46:44) [GCC 12.2.1 20230201] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print(1); printa)
File "<stdin>", line 1
print(1); printa)
^
SyntaxError: unmatched ')'
>>>
Lisp is in general different from Python - Python will read a whole line, parse it, and then evaluate it. If the line is part of a block (ends with some sort of continuation like a :
), then it will keep reading lines until the block is completed and only then do more parsing, and evaluate the whole block.
Janet is not line based, and does not process your programs in chunks of lines; the parser (reader) goes character by character. When a form is produced, it is compiled and then evaluated. The subsequent forms are not touched.
I mean, the REPL can print the error, and don't do anything until the user fixed the syntax error. For example, Python
Perhaps, but also keep in mind the the repl is the same environment as running from a file. The reason the behavior is like this, were there a syntax error, the execution will keep going is to get as much diagnostics information as possible. For example, if there is an error at the beginning of a source file, you would also like to get as many subsequent errors in the output as possible rather than needing to rerun the program one time per error.
You can use Ctrl-Q at the repl to cancel the current form though.
So the confusing part of this is the the error is thrown before the string is completely read, which causes confusing parser state. On a bad string escape, I think more consistent behavior would be to wait until the closing quote is found before raising a parsing error.
You can use Ctrl-Q at the repl to cancel the current form though.
Thanks! this helps
On parse error, the REPL state is not reset.
terminal trace:
Note the
repl:2:">
. It should berepl:2:>
, without the"
.