arktype 1.1.0-dev-1 → 2.0.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/array.test.ts +272 -0
- package/__tests__/astUtils.test.ts +17 -0
- package/__tests__/badDefinitionType.test.ts +51 -0
- package/__tests__/basis.test.ts +46 -0
- package/__tests__/bounds.test.ts +388 -0
- package/__tests__/cast.test.ts +32 -0
- package/__tests__/completions.test.ts +46 -0
- package/__tests__/config.test.ts +168 -0
- package/__tests__/cyclic.test.ts +144 -0
- package/__tests__/dateLiteral.test.ts +32 -0
- package/__tests__/declared.test.ts +123 -0
- package/__tests__/discrimination.test.ts +74 -0
- package/__tests__/divisor.test.ts +90 -0
- package/__tests__/enclosed.test.ts +93 -0
- package/__tests__/examples.test.ts +56 -0
- package/__tests__/expressions.test.ts +138 -0
- package/__tests__/generateBenchData.ts +89 -0
- package/__tests__/generated/cyclic.ts +3058 -0
- package/__tests__/generic.test.ts +294 -0
- package/__tests__/group.test.ts +72 -0
- package/__tests__/hkt.test.ts +22 -0
- package/__tests__/imports.test.ts +113 -0
- package/__tests__/instanceof.test.ts +102 -0
- package/__tests__/intersection.test.ts +104 -0
- package/__tests__/jsdoc.test.ts +64 -0
- package/__tests__/keyTraversal.test.ts +73 -0
- package/__tests__/keyof.test.ts +134 -0
- package/__tests__/keywords.test.ts +188 -0
- package/__tests__/literal.test.ts +51 -0
- package/__tests__/match.test.ts +34 -0
- package/__tests__/methods.bench.ts +22 -0
- package/__tests__/morph.test.ts +409 -0
- package/__tests__/narrow.test.ts +102 -0
- package/__tests__/nodeDefinitions.test.ts +190 -0
- package/__tests__/object.bench.ts +28 -0
- package/__tests__/objectLiteral.test.ts +300 -0
- package/__tests__/operand.bench.ts +45 -0
- package/__tests__/operator.bench.ts +130 -0
- package/__tests__/regex.test.ts +58 -0
- package/__tests__/scope.bench.ts +39 -0
- package/__tests__/scope.test.ts +140 -0
- package/__tests__/string.test.ts +48 -0
- package/__tests__/submodule.test.ts +99 -0
- package/__tests__/this.test.ts +57 -0
- package/__tests__/thunk.test.ts +80 -0
- package/__tests__/traverse.test.ts +119 -0
- package/__tests__/tsGenerics.test.ts +12 -0
- package/__tests__/typeMethods.test.ts +69 -0
- package/__tests__/typeReference.test.ts +39 -0
- package/__tests__/unenclosed.test.ts +120 -0
- package/__tests__/union.test.ts +147 -0
- package/ark.ts +91 -0
- package/main.ts +18 -0
- package/match.ts +116 -0
- package/out/ark.d.ts +52 -0
- package/out/ark.d.ts.map +1 -0
- package/out/ark.js +19 -0
- package/out/ark.js.map +1 -0
- package/out/arkConfig.d.ts +2 -0
- package/out/arkConfig.d.ts.map +1 -0
- package/out/arkConfig.js +10 -0
- package/out/arkConfig.js.map +1 -0
- package/out/main.d.ts +7 -0
- package/out/main.d.ts.map +1 -0
- package/out/main.js +4 -0
- package/out/main.js.map +1 -0
- package/out/match.d.ts +48 -0
- package/out/match.d.ts.map +1 -0
- package/out/match.js +18 -0
- package/out/match.js.map +1 -0
- package/out/parser/definition.d.ts +32 -0
- package/out/parser/definition.d.ts.map +1 -0
- package/out/parser/definition.js +32 -0
- package/out/parser/definition.js.map +1 -0
- package/out/parser/generic.d.ts +18 -0
- package/out/parser/generic.d.ts.map +1 -0
- package/out/parser/generic.js +19 -0
- package/out/parser/generic.js.map +1 -0
- package/out/parser/objectLiteral.d.ts +33 -0
- package/out/parser/objectLiteral.d.ts.map +1 -0
- package/out/parser/objectLiteral.js +66 -0
- package/out/parser/objectLiteral.js.map +1 -0
- package/out/parser/semantic/bounds.d.ts +13 -0
- package/out/parser/semantic/bounds.d.ts.map +1 -0
- package/out/parser/semantic/bounds.js +2 -0
- package/out/parser/semantic/bounds.js.map +1 -0
- package/out/parser/semantic/divisor.d.ts +9 -0
- package/out/parser/semantic/divisor.d.ts.map +1 -0
- package/out/parser/semantic/divisor.js +2 -0
- package/out/parser/semantic/divisor.js.map +1 -0
- package/out/parser/semantic/intersections.d.ts +14 -0
- package/out/parser/semantic/intersections.d.ts.map +1 -0
- package/out/parser/semantic/intersections.js +2 -0
- package/out/parser/semantic/intersections.js.map +1 -0
- package/out/parser/semantic/semantic.d.ts +33 -0
- package/out/parser/semantic/semantic.d.ts.map +1 -0
- package/out/parser/semantic/semantic.js +2 -0
- package/out/parser/semantic/semantic.js.map +1 -0
- package/out/parser/semantic/utils.d.ts +8 -0
- package/out/parser/semantic/utils.d.ts.map +1 -0
- package/out/parser/semantic/utils.js +2 -0
- package/out/parser/semantic/utils.js.map +1 -0
- package/out/parser/semantic/validate.d.ts +24 -0
- package/out/parser/semantic/validate.d.ts.map +1 -0
- package/out/parser/semantic/validate.js +2 -0
- package/out/parser/semantic/validate.js.map +1 -0
- package/out/parser/shared.d.ts +54 -0
- package/out/parser/shared.d.ts.map +1 -0
- package/out/parser/shared.js +47 -0
- package/out/parser/shared.js.map +1 -0
- package/out/parser/string/reduce/dynamic.d.ts +42 -0
- package/out/parser/string/reduce/dynamic.d.ts.map +1 -0
- package/out/parser/string/reduce/dynamic.js +133 -0
- package/out/parser/string/reduce/dynamic.js.map +1 -0
- package/out/parser/string/reduce/shared.d.ts +56 -0
- package/out/parser/string/reduce/shared.d.ts.map +1 -0
- package/out/parser/string/reduce/shared.js +26 -0
- package/out/parser/string/reduce/shared.js.map +1 -0
- package/out/parser/string/reduce/static.d.ts +176 -0
- package/out/parser/string/reduce/static.d.ts.map +1 -0
- package/out/parser/string/reduce/static.js +2 -0
- package/out/parser/string/reduce/static.js.map +1 -0
- package/out/parser/string/shift/operand/date.d.ts +11 -0
- package/out/parser/string/shift/operand/date.d.ts.map +1 -0
- package/out/parser/string/shift/operand/date.js +26 -0
- package/out/parser/string/shift/operand/date.js.map +1 -0
- package/out/parser/string/shift/operand/enclosed.d.ts +49 -0
- package/out/parser/string/shift/operand/enclosed.d.ts.map +1 -0
- package/out/parser/string/shift/operand/enclosed.js +50 -0
- package/out/parser/string/shift/operand/enclosed.js.map +1 -0
- package/out/parser/string/shift/operand/genericArgs.d.ts +29 -0
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +1 -0
- package/out/parser/string/shift/operand/genericArgs.js +25 -0
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -0
- package/out/parser/string/shift/operand/operand.d.ts +9 -0
- package/out/parser/string/shift/operand/operand.d.ts.map +1 -0
- package/out/parser/string/shift/operand/operand.js +17 -0
- package/out/parser/string/shift/operand/operand.js.map +1 -0
- package/out/parser/string/shift/operand/unenclosed.d.ts +34 -0
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +1 -0
- package/out/parser/string/shift/operand/unenclosed.js +68 -0
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -0
- package/out/parser/string/shift/operator/bounds.d.ts +33 -0
- package/out/parser/string/shift/operator/bounds.d.ts.map +1 -0
- package/out/parser/string/shift/operator/bounds.js +106 -0
- package/out/parser/string/shift/operator/bounds.js.map +1 -0
- package/out/parser/string/shift/operator/divisor.d.ts +9 -0
- package/out/parser/string/shift/operator/divisor.d.ts.map +1 -0
- package/out/parser/string/shift/operator/divisor.js +13 -0
- package/out/parser/string/shift/operator/divisor.js.map +1 -0
- package/out/parser/string/shift/operator/operator.d.ts +13 -0
- package/out/parser/string/shift/operator/operator.d.ts.map +1 -0
- package/out/parser/string/shift/operator/operator.js +29 -0
- package/out/parser/string/shift/operator/operator.js.map +1 -0
- package/out/parser/string/shift/scanner.d.ts +71 -0
- package/out/parser/string/shift/scanner.d.ts.map +1 -0
- package/out/parser/string/shift/scanner.js +99 -0
- package/out/parser/string/shift/scanner.js.map +1 -0
- package/out/parser/string/string.d.ts +24 -0
- package/out/parser/string/string.d.ts.map +1 -0
- package/out/parser/string/string.js +23 -0
- package/out/parser/string/string.js.map +1 -0
- package/out/parser/tuple.d.ts +71 -0
- package/out/parser/tuple.d.ts.map +1 -0
- package/out/parser/tuple.js +137 -0
- package/out/parser/tuple.js.map +1 -0
- package/out/scope.d.ts +159 -0
- package/out/scope.d.ts.map +1 -0
- package/out/scope.js +253 -0
- package/out/scope.js.map +1 -0
- package/out/test.d.ts +2 -0
- package/out/test.d.ts.map +1 -0
- package/out/test.js +7 -0
- package/out/test.js.map +1 -0
- package/out/tsconfig.build.tsbuildinfo +1 -0
- package/out/type.d.ts +77 -0
- package/out/type.d.ts.map +1 -0
- package/out/type.js +134 -0
- package/out/type.js.map +1 -0
- package/out/util.d.ts +19 -0
- package/out/util.d.ts.map +1 -0
- package/out/util.js +7 -0
- package/out/util.js.map +1 -0
- package/package.json +13 -10
- package/parser/definition.ts +159 -0
- package/parser/generic.ts +68 -0
- package/parser/objectLiteral.ts +197 -0
- package/parser/semantic/bounds.ts +61 -0
- package/parser/semantic/divisor.ts +13 -0
- package/parser/semantic/intersections.ts +46 -0
- package/parser/semantic/semantic.ts +144 -0
- package/parser/semantic/utils.ts +26 -0
- package/parser/semantic/validate.ts +109 -0
- package/parser/shared.ts +152 -0
- package/parser/string/reduce/dynamic.ts +196 -0
- package/parser/string/reduce/shared.ts +101 -0
- package/parser/string/reduce/static.ts +298 -0
- package/parser/string/shift/operand/date.ts +54 -0
- package/parser/string/shift/operand/enclosed.ts +118 -0
- package/parser/string/shift/operand/genericArgs.ts +127 -0
- package/parser/string/shift/operand/operand.ts +48 -0
- package/parser/string/shift/operand/unenclosed.ts +268 -0
- package/parser/string/shift/operator/bounds.ts +264 -0
- package/parser/string/shift/operator/divisor.ts +36 -0
- package/parser/string/shift/operator/operator.ts +82 -0
- package/parser/string/shift/scanner.ts +209 -0
- package/parser/string/string.ts +90 -0
- package/parser/tuple.ts +474 -0
- package/scope.ts +574 -0
- package/type.ts +347 -0
- package/util.ts +36 -0
- package/dist/main.d.ts +0 -1018
- package/dist/main.js +0 -1450
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { isKeyOf, type Dict } from "@arktype/util"
|
|
2
|
+
import type { Comparator } from "../reduce/shared.js"
|
|
3
|
+
|
|
4
|
+
export class Scanner<Lookahead extends string = string> {
|
|
5
|
+
private chars: string[]
|
|
6
|
+
private i: number
|
|
7
|
+
|
|
8
|
+
constructor(def: string) {
|
|
9
|
+
this.chars = [...def]
|
|
10
|
+
this.i = 0
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Get lookahead and advance scanner by one */
|
|
14
|
+
shift() {
|
|
15
|
+
return (this.chars[this.i++] ?? "") as Lookahead
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get lookahead() {
|
|
19
|
+
return (this.chars[this.i] ?? "") as Lookahead
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get length() {
|
|
23
|
+
return this.chars.length
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
shiftUntil(condition: Scanner.UntilCondition): string {
|
|
27
|
+
let shifted = ""
|
|
28
|
+
while (this.lookahead) {
|
|
29
|
+
if (condition(this, shifted)) {
|
|
30
|
+
if (shifted[shifted.length - 1] === Scanner.escapeToken) {
|
|
31
|
+
shifted = shifted.slice(0, -1)
|
|
32
|
+
} else {
|
|
33
|
+
break
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
shifted += this.shift()
|
|
37
|
+
}
|
|
38
|
+
return shifted
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
shiftUntilNextTerminator() {
|
|
42
|
+
this.shiftUntilNonWhitespace()
|
|
43
|
+
return this.shiftUntil(Scanner.lookaheadIsTerminator)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
shiftUntilNonWhitespace() {
|
|
47
|
+
return this.shiftUntil(Scanner.lookaheadIsNotWhitespace)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
jumpToIndex(i: number) {
|
|
51
|
+
this.i = i < 0 ? this.length + i : i
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get location() {
|
|
55
|
+
return this.i
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get unscanned() {
|
|
59
|
+
return this.chars.slice(this.i, this.length).join("")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get scanned() {
|
|
63
|
+
return this.chars.slice(0, this.i).join("")
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
sliceChars(start: number, end?: number) {
|
|
67
|
+
return this.chars.slice(start, end).join("")
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
lookaheadIs<Char extends Lookahead>(char: Char): this is Scanner<Char> {
|
|
71
|
+
return this.lookahead === char
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
lookaheadIsIn<Tokens extends Dict>(
|
|
75
|
+
tokens: Tokens
|
|
76
|
+
): this is Scanner<Extract<keyof Tokens, string>> {
|
|
77
|
+
return this.lookahead in tokens
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export namespace Scanner {
|
|
82
|
+
export type UntilCondition = (scanner: Scanner, shifted: string) => boolean
|
|
83
|
+
|
|
84
|
+
export type OnInputEndFn = (scanner: Scanner, shifted: string) => string
|
|
85
|
+
|
|
86
|
+
export type ShiftUntilOptions = {
|
|
87
|
+
onInputEnd?: OnInputEndFn
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const lookaheadIsTerminator: UntilCondition = (scanner: Scanner) =>
|
|
91
|
+
scanner.lookahead in terminatingChars
|
|
92
|
+
|
|
93
|
+
export const lookaheadIsNotWhitespace: UntilCondition = (scanner: Scanner) =>
|
|
94
|
+
!(scanner.lookahead in whiteSpaceTokens)
|
|
95
|
+
|
|
96
|
+
export const terminatingChars = {
|
|
97
|
+
"<": true,
|
|
98
|
+
">": true,
|
|
99
|
+
"=": true,
|
|
100
|
+
"|": true,
|
|
101
|
+
"&": true,
|
|
102
|
+
")": true,
|
|
103
|
+
"[": true,
|
|
104
|
+
"%": true,
|
|
105
|
+
" ": true,
|
|
106
|
+
",": true
|
|
107
|
+
} as const
|
|
108
|
+
|
|
109
|
+
export type TerminatingChar = keyof typeof terminatingChars
|
|
110
|
+
|
|
111
|
+
export const finalizingLookaheads = {
|
|
112
|
+
">": true,
|
|
113
|
+
",": true,
|
|
114
|
+
"": true
|
|
115
|
+
} as const
|
|
116
|
+
|
|
117
|
+
export type FinalizingLookahead = keyof typeof finalizingLookaheads
|
|
118
|
+
|
|
119
|
+
export type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>"
|
|
120
|
+
|
|
121
|
+
export type PostfixToken = "[]"
|
|
122
|
+
|
|
123
|
+
export type OperatorToken = InfixToken | PostfixToken
|
|
124
|
+
|
|
125
|
+
export const escapeToken = "\\"
|
|
126
|
+
|
|
127
|
+
export type EscapeToken = typeof escapeToken
|
|
128
|
+
|
|
129
|
+
export const whiteSpaceTokens = {
|
|
130
|
+
" ": true,
|
|
131
|
+
"\n": true
|
|
132
|
+
} as const
|
|
133
|
+
|
|
134
|
+
export type WhiteSpaceToken = keyof typeof whiteSpaceTokens
|
|
135
|
+
|
|
136
|
+
export const lookaheadIsFinalizing = (
|
|
137
|
+
lookahead: string,
|
|
138
|
+
unscanned: string
|
|
139
|
+
): lookahead is ">" | "," =>
|
|
140
|
+
lookahead === ">"
|
|
141
|
+
? unscanned[0] === "="
|
|
142
|
+
? // >== would only occur in an expression like Array<number>==5
|
|
143
|
+
// otherwise, >= would only occur as part of a bound like number>=5
|
|
144
|
+
unscanned[1] === "="
|
|
145
|
+
: // if > is the end of a generic instantiation, the next token will be an operator or the end of the string
|
|
146
|
+
unscanned.trimStart() === "" ||
|
|
147
|
+
isKeyOf(unscanned.trimStart()[0], Scanner.terminatingChars)
|
|
148
|
+
: // if the lookahead is a finalizing token but not >, it's unambiguously a finalizer (currently just ",")
|
|
149
|
+
lookahead === ","
|
|
150
|
+
|
|
151
|
+
export type lookaheadIsFinalizing<
|
|
152
|
+
lookahead extends string,
|
|
153
|
+
unscanned extends string
|
|
154
|
+
> = lookahead extends ">"
|
|
155
|
+
? unscanned extends `=${infer nextUnscanned}`
|
|
156
|
+
? nextUnscanned extends `=${string}`
|
|
157
|
+
? true
|
|
158
|
+
: false
|
|
159
|
+
: Scanner.skipWhitespace<unscanned> extends
|
|
160
|
+
| ""
|
|
161
|
+
| `${TerminatingChar}${string}`
|
|
162
|
+
? true
|
|
163
|
+
: false
|
|
164
|
+
: lookahead extends ","
|
|
165
|
+
? true
|
|
166
|
+
: false
|
|
167
|
+
|
|
168
|
+
export type shift<
|
|
169
|
+
lookahead extends string,
|
|
170
|
+
unscanned extends string
|
|
171
|
+
> = `${lookahead}${unscanned}`
|
|
172
|
+
|
|
173
|
+
export type shiftUntil<
|
|
174
|
+
unscanned extends string,
|
|
175
|
+
terminator extends string,
|
|
176
|
+
scanned extends string = ""
|
|
177
|
+
> = unscanned extends shift<infer lookahead, infer nextUnscanned>
|
|
178
|
+
? lookahead extends terminator
|
|
179
|
+
? scanned extends `${infer base}${EscapeToken}`
|
|
180
|
+
? shiftUntil<nextUnscanned, terminator, `${base}${lookahead}`>
|
|
181
|
+
: [scanned, unscanned]
|
|
182
|
+
: shiftUntil<nextUnscanned, terminator, `${scanned}${lookahead}`>
|
|
183
|
+
: [scanned, ""]
|
|
184
|
+
|
|
185
|
+
export type shiftUntilNot<
|
|
186
|
+
unscanned extends string,
|
|
187
|
+
nonTerminator extends string,
|
|
188
|
+
scanned extends string = ""
|
|
189
|
+
> = unscanned extends shift<infer lookahead, infer nextUnscanned>
|
|
190
|
+
? lookahead extends nonTerminator
|
|
191
|
+
? shiftUntilNot<nextUnscanned, nonTerminator, `${scanned}${lookahead}`>
|
|
192
|
+
: [scanned, unscanned]
|
|
193
|
+
: [scanned, ""]
|
|
194
|
+
|
|
195
|
+
export type shiftUntilNextTerminator<unscanned extends string> = shiftUntil<
|
|
196
|
+
unscanned,
|
|
197
|
+
TerminatingChar
|
|
198
|
+
>
|
|
199
|
+
|
|
200
|
+
export type skipWhitespace<unscanned extends string> = shiftUntilNot<
|
|
201
|
+
unscanned,
|
|
202
|
+
WhiteSpaceToken
|
|
203
|
+
>[1]
|
|
204
|
+
|
|
205
|
+
export type shiftResult<scanned extends string, unscanned extends string> = [
|
|
206
|
+
scanned,
|
|
207
|
+
unscanned
|
|
208
|
+
]
|
|
209
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { TypeNode } from "@arktype/schema"
|
|
2
|
+
import {
|
|
3
|
+
throwInternalError,
|
|
4
|
+
throwParseError,
|
|
5
|
+
type ErrorMessage
|
|
6
|
+
} from "@arktype/util"
|
|
7
|
+
import type { inferAstRoot } from "../semantic/semantic.js"
|
|
8
|
+
import type { DynamicState, DynamicStateWithRoot } from "./reduce/dynamic.js"
|
|
9
|
+
import type { StringifiablePrefixOperator } from "./reduce/shared.js"
|
|
10
|
+
import type { StaticState, state } from "./reduce/static.js"
|
|
11
|
+
import type { parseOperand } from "./shift/operand/operand.js"
|
|
12
|
+
import {
|
|
13
|
+
writeUnexpectedCharacterMessage,
|
|
14
|
+
type parseOperator
|
|
15
|
+
} from "./shift/operator/operator.js"
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Try to parse the definition from right to left using the most common syntax.
|
|
19
|
+
* This can be much more efficient for simple definitions.
|
|
20
|
+
*/
|
|
21
|
+
export type parseString<def extends string, $, args> = def extends keyof $
|
|
22
|
+
? // def could also be a generic reference here, in which case it will
|
|
23
|
+
// fail semantic validation because it has no args
|
|
24
|
+
def
|
|
25
|
+
: def extends `${infer child}[]`
|
|
26
|
+
? child extends keyof $
|
|
27
|
+
? [child, "[]"]
|
|
28
|
+
: fullStringParse<state.initialize<def>, $, args>
|
|
29
|
+
: fullStringParse<state.initialize<def>, $, args>
|
|
30
|
+
|
|
31
|
+
export type inferString<def extends string, $, args> = inferAstRoot<
|
|
32
|
+
parseString<def, $, args>,
|
|
33
|
+
$,
|
|
34
|
+
args
|
|
35
|
+
>
|
|
36
|
+
|
|
37
|
+
export type BaseCompletions<$, args, otherSuggestions extends string = never> =
|
|
38
|
+
| (keyof $ & string)
|
|
39
|
+
| (keyof args & string)
|
|
40
|
+
| StringifiablePrefixOperator
|
|
41
|
+
| otherSuggestions
|
|
42
|
+
|
|
43
|
+
export const fullStringParse = (s: DynamicState): TypeNode => {
|
|
44
|
+
s.parseOperand()
|
|
45
|
+
const result = parseUntilFinalizer(s).root
|
|
46
|
+
if (!result) {
|
|
47
|
+
return throwInternalError(
|
|
48
|
+
`Root was unexpectedly unset after parsing string '${s.scanner.scanned}'`
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
s.scanner.shiftUntilNonWhitespace()
|
|
52
|
+
if (s.scanner.lookahead) {
|
|
53
|
+
// throw a parse error if non-whitespace characters made it here without being parsed
|
|
54
|
+
throwParseError(writeUnexpectedCharacterMessage(s.scanner.lookahead))
|
|
55
|
+
}
|
|
56
|
+
return result
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<
|
|
60
|
+
parseUntilFinalizer<s, $, args>
|
|
61
|
+
>
|
|
62
|
+
|
|
63
|
+
export const parseUntilFinalizer = (s: DynamicState) => {
|
|
64
|
+
while (s.finalizer === undefined) {
|
|
65
|
+
next(s)
|
|
66
|
+
}
|
|
67
|
+
return s as DynamicStateWithRoot
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type parseUntilFinalizer<
|
|
71
|
+
s extends StaticState,
|
|
72
|
+
$,
|
|
73
|
+
args
|
|
74
|
+
> = s["finalizer"] extends undefined
|
|
75
|
+
? parseUntilFinalizer<next<s, $, args>, $, args>
|
|
76
|
+
: s
|
|
77
|
+
|
|
78
|
+
const next = (s: DynamicState) =>
|
|
79
|
+
s.hasRoot() ? s.parseOperator() : s.parseOperand()
|
|
80
|
+
|
|
81
|
+
type next<s extends StaticState, $, args> = s["root"] extends undefined
|
|
82
|
+
? parseOperand<s, $, args>
|
|
83
|
+
: parseOperator<s, $, args>
|
|
84
|
+
|
|
85
|
+
export type extractFinalizedResult<s extends StaticState> =
|
|
86
|
+
s["finalizer"] extends ErrorMessage
|
|
87
|
+
? s["finalizer"]
|
|
88
|
+
: s["finalizer"] extends ""
|
|
89
|
+
? s["root"]
|
|
90
|
+
: state.error<writeUnexpectedCharacterMessage<`${s["finalizer"]}`>>
|