Skip to content

Commit 8ebb37d

Browse files
committed
Add support for single-quoted strings
1 parent 2050509 commit 8ebb37d

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/formula.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,16 +399,25 @@ const number = num.map((args) => new Num(args));
399399
const stringChar = alt(
400400
str("\\\\").map((_) => "\\"),
401401
str('\\"').map((_) => '"'),
402+
str("\\'").map((_) => "'"),
402403
str("\\t").map((_) => "\t"),
403404
str("\\n").map((_) => "\n"),
404405
anyChar,
405406
);
406-
const string = whitespace
407-
.then(str('"'))
408-
.then(stringChar.until(str('"')).optional([]).concat())
409-
.skip(str('"'))
410-
.skip(whitespace)
411-
.map((args) => new Str(args));
407+
const string = alt(
408+
whitespace
409+
.then(str('"'))
410+
.then(stringChar.until(str('"')).optional([]).concat())
411+
.skip(str('"'))
412+
.skip(whitespace)
413+
.map((args) => new Str(args)),
414+
whitespace
415+
.then(str("'"))
416+
.then(stringChar.until(str("'")).optional([]).concat())
417+
.skip(str("'"))
418+
.skip(whitespace)
419+
.map((args) => new Str(args)),
420+
);
412421

413422
const logic = forwardDeclaration();
414423
const value = lex(

test/sheet-and-formula.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,3 +644,14 @@ test("Operator overloading with monkeypatching", async () => {
644644
["test ".repeat(3), "test ".repeat(9), "tEsT"],
645645
]);
646646
});
647+
648+
test("Single-quoted strings", async () => {
649+
const state = createSheet([
650+
["'test'", "='test'", "='test' + \"toast\""],
651+
["=bold('test')", "='te\\'st\\n\\n'", "='te\\\\\\'st'"],
652+
]);
653+
await expectSheet(state.currentSheet, [
654+
["'test'", "test", "testtoast"],
655+
["test", "te'st\n\n", "te\\'st"],
656+
]);
657+
});

0 commit comments

Comments
 (0)