Fix binary operator reduction & associativity handling in parser; add operator precedence tests#1
Conversation
Coverage Report for CI Build 25848258237Warning No base build found for commit Coverage: 95.048%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats💛 - Coveralls |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8a217cc24c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| private utils: Utils; | ||
| private binaryOperatorsPrecedence: string[][]; | ||
| private static readonly BINARY_OPERATOR_GROUPS: ReadonlyArray<BinaryOperatorGroup> = [ | ||
| { opSet: new Set(['^']), associativity: 'right' }, |
There was a problem hiding this comment.
Keep exponentiation left-associative for Excel formulas
For Excel-compatible formulas, chained operators at the same precedence are evaluated left-to-right; Microsoft’s Excel precedence docs state this for same-precedence operators, so 2^3^2 should be reduced as (2^3)^2 (64), not 2^(3^2) (512). Marking ^ as right-associative changes results for any chained exponent formula and diverges from Excel behavior.
Useful? React with 👍 / 👎.
Motivation
Description
BINARY_OPERATOR_GROUPSthat pairs operator sets with anassociativityflag and implementreduceBinaryOperatorsandapplyInfixAtto correctly reduce operators by associativity.OPTIONtoMANYso multiple%tokens are applied in sequence.@types/nodetodevDependenciesand update the pnpm lockfile accordingly.test/operators/testcase.tswith many operator-precedence and associativity cases (exponentiation chaining, unary minus vs exponent, chained comparisons, percent combinations, concatenation order, and others).Testing
npm run test, which includes the operator tests intest/operators/testcase.ts, and the tests passed.Codex Task