Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion mathics/eval/files_io/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,17 @@ def eval_Get(
with Mathics3Open(resolved_path, "r", encoding=encoding) as f:
feeder = MathicsFileLineFeeder(f, trace_fn)
while not feeder.empty():
lineno = feeder.lineno
try:
# Note: we use mathics.core.parser.parse
# so that tracing/debugging can intercept parse()
query = mathics.core.parser.parse(definitions, feeder)
except SyntaxError:
return SymbolNull
# As in WMA, report the error and go on reading the
# rest of the file, unless no input was consumed.
if feeder.lineno == lineno:
return SymbolNull
continue
finally:
feeder.send_messages(evaluation)
if query is None: # blank line / comment
Expand Down
12 changes: 12 additions & 0 deletions test/builtin/files_io/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ def test_get_evaluates_queries_after_error():
check_evaluation(f'Get["{script_path}"]', "OK!", hold_expected=True)


def test_get_continues_after_syntax_error():
# As in WMA, Get reports a syntax error and goes on reading the file.
script_path = canonic_filename(
osp.normpath(
osp.join(osp.dirname(__file__), "..", "..", "data", "syntax-error-bug.wl")
)
)
# The syntax message itself is not checked here: its text comes from
# Mathics3-scanner.
check_evaluation(f'Get["{script_path}"]', "{1, getSyntaxB, 3}")


@pytest.mark.skipif(
sys.platform in ("win32",), reason="$Path does not work on Windows?"
)
Expand Down
5 changes: 5 additions & 0 deletions test/data/syntax-error-bug.wl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(* Get must go on reading the file after a syntax error, as in WMA. *)
getSyntaxA = 1;
getSyntaxB = \[NoSuchCharacterName];
getSyntaxC = 3;
{getSyntaxA, getSyntaxB, getSyntaxC}
Loading