Skip to content

Get: go on reading the file after a syntax error, as in WMA - #1999

Merged
rocky merged 2 commits into
Mathics3:masterfrom
tombouctou:fix-get-continue-after-syntax-error
Oct 16, 2026
Merged

rocky merged 2 commits into
Mathics3:masterfrom
tombouctou:fix-get-continue-after-syntax-error

Conversation

@tombouctou

Copy link
Copy Markdown
Collaborator

When Get hits a syntax error, Mathics3 currently prints the message and then stops reading the file. Everything after the error is silently dropped. WMA does not do this. Its reference page says:

Get continues attempting to read a file even after a syntax error has been detected.

A minimal example (test/data/syntax-error-bug.m):

getSyntaxA = 1;
getSyntaxB = \[NoSuchCharacterName];
getSyntaxC = 3;
{getSyntaxA, getSyntaxB, getSyntaxC}

Get on this file currently reports the bad character name and returns Null, so getSyntaxC is never set. With this PR it reports the error, goes on reading, and returns {1, getSyntaxB, 3}.

In older packages, one bad line near the top therefore lost most of the file. For example, a single mistyped \[...] name lost hundreds of definitions that came after it.

The change is in eval_Get. After a SyntaxError, the loop continues with the next statement. As a guard against looping forever, it still returns Null if the parser consumed no input, i.e. the feeder's line number did not advance.

The new test test_get_continues_after_syntax_error fails on master and passes here. It deliberately does not check the text of the syntax message, because that text comes from Mathics3-scanner.

🤖 Generated with Claude Code

eval_Get returned at the first syntax error, so everything after it in
the file was silently skipped. WMA documents: "Get continues attempting
to read a file even after a syntax error has been detected." Report the
error and continue with the next expression; stop only if the parser
made no progress.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread test/builtin/files_io/test_files.py Outdated
# 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.m")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd appreciate it if we could change the extension here to end in .wl. The problem with .m extensions is that Objective-C headers also have an .m extension. Using .wl at the end, though, is unambiguously Wolfram Alpha as far as I can tell.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1f544ac: the file is now test/data/syntax-error-bug.wl; nothing else changes. Most of the other files in test/data/ (script.m, input-bug.m, star-bug.m, …) are still .m. If you'd like, I can rename those in a separate PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks! Yes, I'd be grateful if you'd rename the others in a separate PR.

.m is also the extension of Objective-C sources; .wl is unambiguous.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rocky

rocky commented Oct 16, 2026

Copy link
Copy Markdown
Member

LGTM

@rocky
rocky merged commit 0c72526 into Mathics3:master Oct 16, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants