Say why an expression could not be evaluated#79
Merged
Conversation
The evaluator threw an empty ParseError from fourteen places, so every
failure reached the caller as an undifferentiated "not evaluable" and the
reader was left to find the bad symbol themselves -- hardest to do on the
long expressions a translator emits:
controller 'oo' variable 'vv': could not evaluate
'-1.00000000000000000E+000 / C_LIGHT'
ParseError now carries a reason and every throw site fills it in: unknown
constant/variable, unknown function, unknown species, a mass number missing
its '#', wrong argument count (named against the function rather than
reported as an unknown name), missing ')', trailing text, and a non-finite
result. EvalOutcome carries it to the caller, and the four sites that report
an expression failure append it.
A miscased name gets a suggestion without a second table to drift: every
built-in constant is lower case, so the lowered name is retried against the
constants and the user symbol table, which also catches a user constant
written MY_CONST but defined my_const. Function names live only in apply's
dispatch chain, so the lowered spelling is probed there and the result
discarded -- a miscased name is still an error, not a silent correction.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A failed expression reported only that it failed:
leaving the reader to find the bad symbol themselves — hardest to do on the long expressions a translator emits. It now says which symbol and how to spell it:
What changed
ParseErrorwas an empty struct thrown from fourteen places in the evaluator, so every failure arrived at the caller as an undifferentiated "not evaluable". It now carries awhy, and each throw site fills it in: unknown constant/variable, unknown function, unknown species, a mass number missing its#, wrong argument count (named against the function rather than reported as an unknown name), missing), trailing text, and a non-finite result.EvalOutcomegained anerrorfield to carry it out.pals_expand.cppappends the reason after--at the four sites that report an expression failure: element values (substitute_values), controller initial values, controller control expressions, andsetcommand values. Controller variables needed a field onCtrlVar, since the report happens in a later pass than the evaluation.Suggestions without a second table
Every built-in constant is lower case, so
case_hintlowers the name and retriesbuiltin_constantand the user symbol table — no list to drift out of step, and it also catches a user constant writtenMY_CONSTbut definedmy_const. Function names live only inapply's dispatch chain, so the lowered spelling is probed there and the result discarded: a miscased function is still an error, not a silent correction, and the recursion terminates because a lowered name lowers to itself.Tests
Two cases in
test_expressions.cpp: the element path (miscased constant with suggestion, an unknown name that gets no invented suggestion, miscased function, arity, unknown species, missing#, unbalanced parens) and the controller path. Full suite: 1181 assertions in 227 cases.Not in this PR
unknown constant or variable 'vv') though it is declared and merely valueless. Fixing that means the controller pass telling the evaluator "declared but unevaluated"; the shortcut of defaulting a failed variable to zero would turn a loud error into a silently wrong number.evaluate_pals_expression(expr, ok)still reports only a boolean, so PALSJulia raises with the text alone. Widening it is an ABI change.🤖 Generated with Claude Code