diff --git a/ark/type/__tests__/string.test.ts b/ark/type/__tests__/string.test.ts index 9cce53b111..df718c3e64 100644 --- a/ark/type/__tests__/string.test.ts +++ b/ark/type/__tests__/string.test.ts @@ -12,9 +12,10 @@ contextualize(() => { it("ignores whitespace between identifiers/operators", () => { const t = type(` \n string | - \tboolean [] `) - attest(t.infer) - attest(t.json).equals(type("string|boolean[]").json) + number + \t|boolean [] `) + attest(t.infer) + attest(t.json).equals(type("string|number|boolean[]").json) }) it("errors on bad whitespace", () => { diff --git a/ark/type/parser/string/shift/operator/operator.ts b/ark/type/parser/string/shift/operator/operator.ts index 23e51602ca..6e3c6857f1 100644 --- a/ark/type/parser/string/shift/operator/operator.ts +++ b/ark/type/parser/string/shift/operator/operator.ts @@ -1,4 +1,4 @@ -import { isKeyOf, type WhiteSpaceToken } from "@ark/util" +import { isKeyOf, type WhiteSpaceToken, whiteSpaceTokens } from "@ark/util" import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts" import type { StaticState, state } from "../../reduce/static.ts" import { Scanner } from "../scanner.ts" @@ -23,7 +23,7 @@ export const parseOperator = (s: DynamicStateWithRoot): void => { s.finalize(lookahead) : isKeyOf(lookahead, comparatorStartChars) ? parseBound(s, lookahead) : lookahead === "%" ? parseDivisor(s) - : lookahead === " " ? parseOperator(s) + : lookahead in whiteSpaceTokens ? parseOperator(s) : s.error(writeUnexpectedCharacterMessage(lookahead)) ) } diff --git a/ark/type/parser/string/shift/scanner.ts b/ark/type/parser/string/shift/scanner.ts index 7387f8b624..ced4abcf5a 100644 --- a/ark/type/parser/string/shift/scanner.ts +++ b/ark/type/parser/string/shift/scanner.ts @@ -99,9 +99,9 @@ export class Scanner { ")": true, "[": true, "%": true, - " ": true, ",": true, - ":": true + ":": true, + ...whiteSpaceTokens } as const static finalizingLookaheads = {