Repository navigation
fix(format): keep the parentheses an expression's reading depends on; release 0.1.1 - #1
Merged
Merged
Conversation
exprToString parenthesised an operand only when it bound more loosely than its parent, so a right operand at the same level as `-` or `/` lost its parentheses: `thrust / (totalMass * 9.81) >= 2` rendered as `thrust / totalMass * 9.81 ≥ 2`, which denotes another expression than the one evaluated. The same held for `a - (b - c)`, comparisons nested in comparisons, and a unary minus over a compound or negated operand (`-(a + b)` rendered as `-a + b`). Operands are now parenthesised by side and operator; parentheses that change nothing are still left out. First tests for format.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-up on the parentheses fix: - a negation right of an operator is grouped only under `-` (`t ≥ -10`, not `t ≥ (-10)`); a negative literal there too (`a - (-5)`); - a negative under a unary minus is grouped (`-(-5)`, formerly `--5`); - a quantity right of `*` or `/` is grouped, since mathjs reads `5 / 2 kg` as `(5 / 2) kg`; - an operator outside the precedence table groups its compound operands. A 4.77M-tree round-trip fuzz finds no rendering that reads as another expression. Version 0.1.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 tasks done
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.
Summary
exprToStringonly parenthesised an operand that binds more loosely than its parent.-or/lost its parentheses:thrust / (totalMass * 9.81) ≥ 2was shown asthrust / totalMass * 9.81 ≥ 2.-or/at the same level:a - (b - c),a / (b * c);a - (-b);-(a + b),-(-a).a - b - c,a * b * c,a + b - c,(a + b) * 2,t ≥ -10 and t ≤ 80.Test plan
tests/format_test.ts(the first tests forformat.ts). Three of its four tests failed before the fix. The fourth pins the cases that must stay free of parentheses.deno task test(35 passed, z3 included),deno task check,deno lint, anddeno fmt --checkon the changed files.mainare already unformatted; this PR leaves them alone.Not done here
deno.jsonmoves offjsr:@casys/constraint-solver@0.1.0.🤖 Generated with Claude Code