Skip to content

Commit ece4e78

Browse files
committed
Add = for equality and <> for inequality
This will help with people coming from Excel, as well as LLMs generating formulas based on training data from Excel
1 parent 11f47ee commit ece4e78

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
- Namespaced formula functions
8585
- Make parsing faster
8686
- Hand-written recursive descent
87-
- Add <> as alternative for !=
8887
- Local storage
8988
- Save sheets
9089
- Load sheets

src/formula.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class BinaryOperation extends Expression {
9090
"<": (x, y) => x < y,
9191
"&&": (x, y) => x && y,
9292
"||": (x, y) => x || y,
93+
"<>": (x, y) => x !== y,
94+
"=": (x, y) => x === y,
9395

9496
// Bitwise
9597
"&": (x, y) => (x >>> 0) & (y >>> 0),
@@ -458,6 +460,8 @@ const relational = leftAssociativeBinOp(shift, BinaryOperation, [
458460
const equality = leftAssociativeBinOp(relational, BinaryOperation, [
459461
"==",
460462
"!=",
463+
"=",
464+
"<>",
461465
]);
462466

463467
const bitwiseAnd = leftAssociativeBinOp(equality, BinaryOperation, ["&"]);

test/sheet-and-formula.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ test("Complex logical expressions in formulas", async () => {
178178
"=~0 >>> 0 << 12",
179179
"=!(~0 >>> 0 & 0x1 | 0xff) || false",
180180
"=if(5 < 3 || 2 > 1 && 1 == 1 || 2 != 1 && 3 <= 0x5, 2 >= 1, 10)",
181+
"=if(5 < 3 || 2 > 1 && 1 = 1 || 2 <> 1 && 3 <= 0x5, 2 >= 1, 10)",
181182
],
182183
]);
183184
await expectSheet(state.currentSheet, [
@@ -187,6 +188,7 @@ test("Complex logical expressions in formulas", async () => {
187188
(~0 >>> 0) << 12,
188189
!(((~0 >>> 0) & 0x1) | 0xff) || false,
189190
5 < 3 || (2 > 1 && 1 == 1) || (2 != 1 && 3 <= 0x5) ? 2 >= 1 : 10,
191+
5 < 3 || (2 > 1 && 1 == 1) || (2 != 1 && 3 <= 0x5) ? 2 >= 1 : 10,
190192
],
191193
]);
192194
});

0 commit comments

Comments
 (0)