Repository navigation
Simulator: string comparisons, parentheses, ! and stop on error - #9
Merged
Merged
Conversation
Conditions are now split only outside brackets and string literals, so '(a || b) && c', '!(a > 3)' and '"a && b"' evaluate as in Java. Comparisons with a string literal or string variable compare text, and 'x.equals(y)' is accepted. 'if (a) && (b)' no longer has its first and last parenthesis stripped. After an error the engine sets state.isHalted and stays on the failing step instead of advancing past it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cp4EQgFQyGbM8MVLiWbJKQ
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.
Requested by Holger · project thread
Before: in the simulator,
name == "Anna"failed with "Invalid expression",(a < 3 || a > 10) && band!(a > 3)were evaluated wrong or failed, an&&inside a string literal split the condition, andif (a > 3) && (a < 10)lost its first and last parenthesis. After any error the simulation skipped the failing block and kept running.After: conditions behave like Java:
||binds weaker than&&, which binds weaker than!; parentheses group; comparisons with a string literal or string variable compare text (==,!=,<, …), andname.equals("Anna")works. Comparing a string with a number is reported as an error. After an error the simulation stops on the failing block (it stays highlighted, Play/Step are disabled) until Reset.How:
evaluateBoolExpressionnow splits only outside brackets and string literals (topLevelMask), strips a pair of outer parentheses only when they actually match, and routes comparisons throughevaluateComparison, which picks text or numeric comparison.VisuStructSimulationStategainsisHalted(defaults tofalse), andcanSteprespects it. The app needs no changes: it already disables the controls viacanStepand showsstate.message.Stacked on #8 (tests + CI); GitHub retargets this PR to
mainonce #8 is merged. New tests are inSimulationConditionTests.swift; CHANGELOG has an Unreleased entry.Generated by Claude Code