Skip to content

Commit

Permalink
fix: accept newlines before an operator (#1101)
Browse files Browse the repository at this point in the history
  • Loading branch information
refi64 authored Aug 28, 2024
1 parent 8876a4b commit 1532a39
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions ark/type/__tests__/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ contextualize(() => {

it("ignores whitespace between identifiers/operators", () => {
const t = type(` \n string |
\tboolean [] `)
attest<string | boolean[]>(t.infer)
attest(t.json).equals(type("string|boolean[]").json)
number
\t|boolean [] `)
attest<string | number | boolean[]>(t.infer)
attest(t.json).equals(type("string|number|boolean[]").json)
})

it("errors on bad whitespace", () => {
Expand Down
4 changes: 2 additions & 2 deletions ark/type/parser/string/shift/operator/operator.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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))
)
}
Expand Down
4 changes: 2 additions & 2 deletions ark/type/parser/string/shift/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ export class Scanner<lookahead extends string = string> {
")": true,
"[": true,
"%": true,
" ": true,
",": true,
":": true
":": true,
...whiteSpaceTokens
} as const

static finalizingLookaheads = {
Expand Down

0 comments on commit 1532a39

Please sign in to comment.