Skip to content

Commit 0f190a7

Browse files
committed
fix: lenient parse "foo"
1 parent 24eb8f8 commit 0f190a7

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/compute-engine/latex-syntax/parse.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,11 @@ export class _Parser implements Parser {
15521552

15531553
const start = this.index;
15541554

1555+
// Word boundary: if the preceding token is a letter, we're in the
1556+
// middle of a word that was partially consumed — don't match.
1557+
if (start > 0 && /^[a-zA-Z]$/.test(this._tokens[start - 1]))
1558+
return null;
1559+
15551560
// Collect consecutive letter tokens to form a potential function name
15561561
let name = '';
15571562
while (!this.atEnd && /^[a-zA-Z]$/.test(this.peek)) {
@@ -1711,6 +1716,11 @@ export class _Parser implements Parser {
17111716

17121717
const start = this.index;
17131718

1719+
// Word boundary: if the preceding token is a letter, we're in the
1720+
// middle of a word that was partially consumed — don't match.
1721+
if (start > 0 && /^[a-zA-Z]$/.test(this._tokens[start - 1]))
1722+
return null;
1723+
17141724
// Collect consecutive letter tokens
17151725
let name = '';
17161726
while (!this.atEnd && /^[a-zA-Z]$/.test(this.peek)) {

test/compute-engine/latex-syntax/parsing.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ describe('NON-STRICT MODE (Math-ASCII/Typst-like syntax)', () => {
215215
});
216216

217217
test('Unknown function names are rejected', () => {
218-
// 'foo' is not a recognized function: 'f' is a symbol, 'oo' is infinity
218+
// 'foo' is not a recognized function, should parse as individual symbols
219219
expect(ce.parse('foo(x)', { strict: false })).toMatchInlineSnapshot(
220-
`["Triple", "f", "PositiveInfinity", "x"]`
220+
`["Tuple", "f", "o", "o", "x"]`
221221
);
222222
});
223223
});

0 commit comments

Comments
 (0)