arktype 2.0.0-dev.0 → 2.0.0-dev.10
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 +270 -151
- package/__tests__/badDefinitionType.test.ts +10 -3
- package/__tests__/basis.test.ts +6 -2
- package/__tests__/bounds.test.ts +282 -352
- package/__tests__/cast.test.ts +7 -2
- package/__tests__/completions.test.ts +8 -3
- package/__tests__/config.test.ts +95 -167
- package/__tests__/dateLiteral.test.ts +8 -4
- package/__tests__/declared.test.ts +7 -6
- package/__tests__/discrimination.test.ts +1 -1
- package/__tests__/divisor.test.ts +46 -22
- package/__tests__/enclosed.test.ts +39 -25
- package/__tests__/examples.test.ts +56 -56
- package/__tests__/expressions.test.ts +184 -112
- package/__tests__/generic.test.ts +307 -288
- package/__tests__/group.test.ts +67 -54
- package/__tests__/imports.test.ts +62 -49
- package/__tests__/instanceof.test.ts +25 -23
- package/__tests__/intersection.test.ts +52 -48
- package/__tests__/keyTraversal.test.ts +77 -73
- package/__tests__/keyof.test.ts +68 -52
- package/__tests__/keywords.test.ts +164 -138
- package/__tests__/literal.test.ts +60 -21
- package/__tests__/match.bench.ts +31 -0
- package/__tests__/match.test.ts +222 -22
- package/__tests__/narrow.test.ts +52 -54
- package/__tests__/objectLiteral.test.ts +347 -205
- package/__tests__/operator.bench.ts +4 -4
- package/__tests__/pipe.test.ts +501 -0
- package/__tests__/realWorld.test.ts +63 -0
- package/__tests__/regex.test.ts +17 -7
- package/__tests__/scope.bench.ts +1 -1
- package/__tests__/scope.test.ts +257 -23
- package/__tests__/serialization.test.ts +19 -0
- package/__tests__/string.test.ts +11 -7
- package/__tests__/submodule.test.ts +26 -39
- package/__tests__/this.test.ts +83 -57
- package/__tests__/thunk.test.ts +13 -7
- package/__tests__/traverse.test.ts +76 -54
- package/__tests__/tsGenerics.test.ts +12 -12
- package/__tests__/type.test.ts +36 -0
- package/__tests__/typeReference.test.ts +7 -7
- package/__tests__/unenclosed.test.ts +116 -100
- package/__tests__/union.test.ts +171 -104
- package/ark.ts +21 -65
- package/generic.ts +69 -0
- package/main.ts +6 -18
- package/match.ts +195 -93
- package/module.ts +15 -0
- package/out/ark.d.ts +15 -39
- package/out/ark.js +9 -18
- package/out/ark.js.map +1 -1
- package/out/generic.d.ts +21 -0
- package/out/generic.js +24 -0
- package/out/generic.js.map +1 -0
- package/out/main.d.ts +6 -7
- package/out/main.js +4 -3
- package/out/main.js.map +1 -1
- package/out/match.d.ts +57 -34
- package/out/match.js +51 -17
- package/out/match.js.map +1 -1
- package/out/module.d.ts +10 -0
- package/out/module.js +3 -0
- package/out/module.js.map +1 -0
- package/out/parser/definition.d.ts +11 -13
- package/out/parser/definition.js +10 -13
- package/out/parser/definition.js.map +1 -1
- package/out/parser/generic.d.ts +5 -7
- package/out/parser/generic.js +7 -11
- package/out/parser/generic.js.map +1 -1
- package/out/parser/objectLiteral.d.ts +45 -14
- package/out/parser/objectLiteral.js +61 -52
- package/out/parser/objectLiteral.js.map +1 -1
- package/out/parser/semantic/bounds.d.ts +10 -8
- package/out/parser/semantic/bounds.js +0 -1
- package/out/parser/semantic/bounds.js.map +1 -1
- package/out/parser/semantic/divisor.d.ts +5 -7
- package/out/parser/semantic/divisor.js +0 -1
- package/out/parser/semantic/infer.d.ts +24 -0
- package/out/parser/semantic/infer.js +1 -0
- package/out/parser/semantic/infer.js.map +1 -0
- package/out/parser/semantic/utils.d.ts +3 -7
- package/out/parser/semantic/utils.js +0 -1
- package/out/parser/semantic/validate.d.ts +15 -14
- package/out/parser/semantic/validate.js +1 -1
- package/out/parser/semantic/validate.js.map +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -13
- package/out/parser/string/reduce/dynamic.js +31 -26
- package/out/parser/string/reduce/dynamic.js.map +1 -1
- package/out/parser/string/reduce/shared.d.ts +6 -20
- package/out/parser/string/reduce/shared.js +0 -1
- package/out/parser/string/reduce/shared.js.map +1 -1
- package/out/parser/string/reduce/static.d.ts +27 -24
- package/out/parser/string/reduce/static.js +0 -1
- package/out/parser/string/shift/operand/date.d.ts +3 -3
- package/out/parser/string/shift/operand/date.js +4 -7
- package/out/parser/string/shift/operand/date.js.map +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts +4 -19
- package/out/parser/string/shift/operand/enclosed.js +12 -13
- package/out/parser/string/shift/operand/enclosed.js.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +9 -10
- package/out/parser/string/shift/operand/genericArgs.js +6 -10
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
- package/out/parser/string/shift/operand/operand.d.ts +3 -4
- package/out/parser/string/shift/operand/operand.js +8 -12
- package/out/parser/string/shift/operand/operand.js.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +15 -22
- package/out/parser/string/shift/operand/unenclosed.js +24 -36
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
- package/out/parser/string/shift/operator/bounds.d.ts +9 -13
- package/out/parser/string/shift/operator/bounds.js +43 -54
- package/out/parser/string/shift/operator/bounds.js.map +1 -1
- package/out/parser/string/shift/operator/divisor.d.ts +2 -4
- package/out/parser/string/shift/operator/divisor.js +1 -3
- package/out/parser/string/shift/operator/divisor.js.map +1 -1
- package/out/parser/string/shift/operator/operator.d.ts +2 -3
- package/out/parser/string/shift/operator/operator.js +12 -19
- package/out/parser/string/shift/operator/operator.js.map +1 -1
- package/out/parser/string/shift/scanner.d.ts +2 -2
- package/out/parser/string/shift/scanner.js +14 -16
- package/out/parser/string/shift/scanner.js.map +1 -1
- package/out/parser/string/string.d.ts +8 -6
- package/out/parser/string/string.js +1 -3
- package/out/parser/string/string.js.map +1 -1
- package/out/parser/tuple.d.ts +102 -43
- package/out/parser/tuple.js +119 -87
- package/out/parser/tuple.js.map +1 -1
- package/out/scope.d.ts +43 -120
- package/out/scope.js +39 -209
- package/out/scope.js.map +1 -1
- package/out/type.d.ts +43 -64
- package/out/type.js +30 -131
- package/out/type.js.map +1 -1
- package/package.json +7 -3
- package/parser/definition.ts +77 -93
- package/parser/generic.ts +38 -40
- package/parser/objectLiteral.ts +172 -136
- package/parser/semantic/bounds.ts +33 -32
- package/parser/semantic/divisor.ts +8 -10
- package/parser/semantic/infer.ts +141 -0
- package/parser/semantic/utils.ts +12 -23
- package/parser/semantic/validate.ts +81 -73
- package/parser/string/reduce/dynamic.ts +67 -55
- package/parser/string/reduce/shared.ts +1 -3
- package/parser/string/reduce/static.ts +67 -69
- package/parser/string/shift/operand/date.ts +15 -14
- package/parser/string/shift/operand/enclosed.ts +30 -25
- package/parser/string/shift/operand/genericArgs.ts +46 -45
- package/parser/string/shift/operand/operand.ts +32 -38
- package/parser/string/shift/operand/unenclosed.ts +107 -158
- package/parser/string/shift/operator/bounds.ts +118 -112
- package/parser/string/shift/operator/divisor.ts +14 -17
- package/parser/string/shift/operator/operator.ts +35 -46
- package/parser/string/shift/scanner.ts +51 -50
- package/parser/string/string.ts +30 -35
- package/parser/tuple.ts +375 -307
- package/scope.ts +170 -453
- package/type.ts +193 -274
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/cyclic.test.ts +0 -144
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/morph.test.ts +0 -409
- package/__tests__/nodeDefinitions.test.ts +0 -190
- package/__tests__/typeMethods.test.ts +0 -69
- package/out/ark.d.ts.map +0 -1
- package/out/arkConfig.d.ts +0 -2
- package/out/arkConfig.d.ts.map +0 -1
- package/out/arkConfig.js +0 -10
- package/out/arkConfig.js.map +0 -1
- package/out/main.d.ts.map +0 -1
- package/out/match.d.ts.map +0 -1
- package/out/parser/definition.d.ts.map +0 -1
- package/out/parser/generic.d.ts.map +0 -1
- package/out/parser/objectLiteral.d.ts.map +0 -1
- package/out/parser/semantic/bounds.d.ts.map +0 -1
- package/out/parser/semantic/divisor.d.ts.map +0 -1
- package/out/parser/semantic/intersections.d.ts +0 -14
- package/out/parser/semantic/intersections.d.ts.map +0 -1
- package/out/parser/semantic/intersections.js +0 -2
- package/out/parser/semantic/intersections.js.map +0 -1
- package/out/parser/semantic/semantic.d.ts +0 -33
- package/out/parser/semantic/semantic.d.ts.map +0 -1
- package/out/parser/semantic/semantic.js +0 -2
- package/out/parser/semantic/semantic.js.map +0 -1
- package/out/parser/semantic/utils.d.ts.map +0 -1
- package/out/parser/semantic/validate.d.ts.map +0 -1
- package/out/parser/shared.d.ts +0 -54
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -47
- package/out/parser/shared.js.map +0 -1
- package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
- package/out/parser/string/reduce/shared.d.ts.map +0 -1
- package/out/parser/string/reduce/static.d.ts.map +0 -1
- package/out/parser/string/shift/operand/date.d.ts.map +0 -1
- package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
- package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
- package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
- package/out/parser/string/shift/scanner.d.ts.map +0 -1
- package/out/parser/string/string.d.ts.map +0 -1
- package/out/parser/tuple.d.ts.map +0 -1
- package/out/scope.d.ts.map +0 -1
- package/out/test.d.ts +0 -2
- package/out/test.d.ts.map +0 -1
- package/out/test.js +0 -7
- package/out/test.js.map +0 -1
- package/out/tsconfig.build.tsbuildinfo +0 -1
- package/out/type.d.ts.map +0 -1
- package/out/util.d.ts +0 -19
- package/out/util.d.ts.map +0 -1
- package/out/util.js +0 -7
- package/out/util.js.map +0 -1
- package/parser/semantic/intersections.ts +0 -46
- package/parser/semantic/semantic.ts +0 -144
- package/parser/shared.ts +0 -152
- package/util.ts +0 -36
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isKeyOf, throwParseError
|
|
3
|
-
import { maxComparators, writeUnpairableComparatorMessage } from "../../reduce/shared.js";
|
|
1
|
+
import { internalKeywords, jsObjects, tsKeywords, writeUnboundableMessage } from "@arktype/schema";
|
|
2
|
+
import { isKeyOf, throwParseError } from "@arktype/util";
|
|
3
|
+
import { invertedComparators, maxComparators, writeUnpairableComparatorMessage } from "../../reduce/shared.js";
|
|
4
4
|
import { extractDateLiteralSource, isDateLiteral } from "../operand/date.js";
|
|
5
5
|
export const parseBound = (s, start) => {
|
|
6
6
|
const comparator = shiftComparator(s, start);
|
|
7
|
-
if (s.root.
|
|
7
|
+
if (s.root.hasKind("unit")) {
|
|
8
8
|
if (typeof s.root.unit === "number") {
|
|
9
|
+
s.reduceLeftBound(s.root.unit, comparator);
|
|
9
10
|
s.unsetRoot();
|
|
10
|
-
return
|
|
11
|
+
return;
|
|
11
12
|
}
|
|
12
13
|
if (s.root.unit instanceof Date) {
|
|
13
|
-
s.unsetRoot();
|
|
14
14
|
const literal = `d'${s.root.description ?? s.root.unit.toISOString()}'`;
|
|
15
|
-
|
|
15
|
+
s.unsetRoot();
|
|
16
|
+
s.reduceLeftBound(literal, comparator);
|
|
17
|
+
return;
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
return parseRightBound(s, comparator);
|
|
@@ -26,49 +28,39 @@ export const comparatorStartChars = {
|
|
|
26
28
|
">": 1,
|
|
27
29
|
"=": 1
|
|
28
30
|
};
|
|
29
|
-
const shiftComparator = (s, start) => s.scanner.lookaheadIs("=")
|
|
30
|
-
?
|
|
31
|
-
: isKeyOf(start, oneCharComparators)
|
|
32
|
-
? start
|
|
31
|
+
const shiftComparator = (s, start) => s.scanner.lookaheadIs("=") ? `${start}${s.scanner.shift()}`
|
|
32
|
+
: isKeyOf(start, oneCharComparators) ? start
|
|
33
33
|
: s.error(singleEqualsMessage);
|
|
34
|
-
export const writeUnboundableMessage = (root) => `Bounded expression ${root} must be a number, string, Array, or Date`;
|
|
35
34
|
export const writeIncompatibleRangeMessage = (l, r) => `Bound kinds ${l} and ${r} are incompatible`;
|
|
36
|
-
export const
|
|
37
|
-
|
|
38
|
-
if (root.extends(keywords.number)) {
|
|
35
|
+
export const getBoundKinds = (comparator, limit, root, boundKind) => {
|
|
36
|
+
if (root.extends(tsKeywords.number)) {
|
|
39
37
|
if (typeof limit !== "number") {
|
|
40
|
-
return throwParseError(
|
|
38
|
+
return throwParseError(writeInvalidLimitMessage(comparator, limit, boundKind));
|
|
41
39
|
}
|
|
42
|
-
return comparator === "=="
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
? ["min"]
|
|
46
|
-
: ["max"];
|
|
40
|
+
return (comparator === "==" ? ["min", "max"]
|
|
41
|
+
: comparator[0] === ">" ? ["min"]
|
|
42
|
+
: ["max"]);
|
|
47
43
|
}
|
|
48
|
-
if (root.extends(
|
|
44
|
+
if (root.extends(internalKeywords.lengthBoundable)) {
|
|
49
45
|
if (typeof limit !== "number") {
|
|
50
|
-
return throwParseError(
|
|
46
|
+
return throwParseError(writeInvalidLimitMessage(comparator, limit, boundKind));
|
|
51
47
|
}
|
|
52
|
-
return comparator === "=="
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
? ["minLength"]
|
|
56
|
-
: ["maxLength"];
|
|
48
|
+
return (comparator === "==" ? ["minLength", "maxLength"]
|
|
49
|
+
: comparator[0] === ">" ? ["minLength"]
|
|
50
|
+
: ["maxLength"]);
|
|
57
51
|
}
|
|
58
|
-
if (root.extends(
|
|
52
|
+
if (root.extends(jsObjects.Date)) {
|
|
59
53
|
// allow either numeric or date limits
|
|
60
|
-
return comparator === "=="
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
? ["after"]
|
|
64
|
-
: ["before"];
|
|
54
|
+
return (comparator === "==" ? ["after", "before"]
|
|
55
|
+
: comparator[0] === ">" ? ["after"]
|
|
56
|
+
: ["before"]);
|
|
65
57
|
}
|
|
66
|
-
return throwParseError(writeUnboundableMessage(root.
|
|
58
|
+
return throwParseError(writeUnboundableMessage(root.expression));
|
|
67
59
|
};
|
|
68
|
-
export const singleEqualsMessage =
|
|
60
|
+
export const singleEqualsMessage = "= is not a valid comparator. Use == to check for equality";
|
|
69
61
|
const openLeftBoundToSchema = (leftBound) => ({
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
rule: isDateLiteral(leftBound.limit) ?
|
|
63
|
+
extractDateLiteralSource(leftBound.limit)
|
|
72
64
|
: leftBound.limit,
|
|
73
65
|
exclusive: leftBound.comparator.length === 1
|
|
74
66
|
});
|
|
@@ -77,30 +69,27 @@ export const parseRightBound = (s, comparator) => {
|
|
|
77
69
|
const previousRoot = s.unsetRoot();
|
|
78
70
|
const previousScannerIndex = s.scanner.location;
|
|
79
71
|
s.parseOperand();
|
|
72
|
+
const limitNode = s.unsetRoot();
|
|
80
73
|
// after parsing the next operand, use the locations to get the
|
|
81
74
|
// token from which it was parsed
|
|
82
75
|
const limitToken = s.scanner.sliceChars(previousScannerIndex, s.scanner.location);
|
|
83
|
-
s.
|
|
84
|
-
|
|
85
|
-
(
|
|
86
|
-
|
|
87
|
-
|
|
76
|
+
s.root = previousRoot;
|
|
77
|
+
if (!limitNode.hasKind("unit") ||
|
|
78
|
+
(typeof limitNode.unit !== "number" && !(limitNode.unit instanceof Date)))
|
|
79
|
+
return s.error(writeInvalidLimitMessage(comparator, limitToken, "right"));
|
|
80
|
+
const limit = limitNode.unit;
|
|
88
81
|
// apply the newly-parsed right bound
|
|
89
82
|
const exclusive = comparator.length === 1;
|
|
90
83
|
// if the comparator is ==, both the min and max of that pair will be applied
|
|
91
|
-
for (const kind of getBoundKinds(comparator, limit, previousRoot))
|
|
92
|
-
s.constrainRoot(kind, { limit, exclusive });
|
|
93
|
-
|
|
94
|
-
if (!s.branches.leftBound) {
|
|
84
|
+
for (const kind of getBoundKinds(comparator, typeof limit === "number" ? limit : limitToken, previousRoot, "right"))
|
|
85
|
+
s.constrainRoot(kind, { rule: limit, exclusive });
|
|
86
|
+
if (!s.branches.leftBound)
|
|
95
87
|
return;
|
|
96
|
-
}
|
|
97
88
|
// if there's an open left bound, perform additional validation and apply it
|
|
98
|
-
if (!isKeyOf(comparator, maxComparators))
|
|
89
|
+
if (!isKeyOf(comparator, maxComparators))
|
|
99
90
|
return s.error(writeUnpairableComparatorMessage(comparator));
|
|
100
|
-
|
|
101
|
-
const lowerBoundKind = getBoundKinds(s.branches.leftBound.comparator, s.branches.leftBound.limit, previousRoot);
|
|
91
|
+
const lowerBoundKind = getBoundKinds(s.branches.leftBound.comparator, s.branches.leftBound.limit, previousRoot, "left");
|
|
102
92
|
s.constrainRoot(lowerBoundKind[0], openLeftBoundToSchema(s.branches.leftBound));
|
|
103
|
-
|
|
93
|
+
s.branches.leftBound = null;
|
|
104
94
|
};
|
|
105
|
-
export const writeInvalidLimitMessage = (comparator, limit, boundKind) => `Comparator ${comparator} must be ${boundKind === "left" ? "preceded" : "followed"} by a corresponding literal (was '${limit}')`;
|
|
106
|
-
//# sourceMappingURL=bounds.js.map
|
|
95
|
+
export const writeInvalidLimitMessage = (comparator, limit, boundKind) => `Comparator ${boundKind === "left" ? invertedComparators[comparator] : comparator} must be ${boundKind === "left" ? "preceded" : "followed"} by a corresponding literal (was '${limit}')`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounds.js","sourceRoot":"","sources":["../../../../../parser/string/shift/operator/bounds.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"bounds.js","sourceRoot":"","sources":["../../../../../parser/string/shift/operator/bounds.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,uBAAuB,EACvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,OAAO,EAAe,eAAe,EAAE,MAAM,eAAe,CAAA;AAMrE,OAAO,EAKN,mBAAmB,EACnB,cAAc,EACd,gCAAgC,EAChC,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,oB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CAAC,SAAS,GAAG,IAAI,CAAA;AAC5B,CAAC,CAAA;AA+BD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAKvC,UAAsB,EACtB,KAAY,EACZ,SAAoB,EACqC,EAAE,CAC3D,cACC,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAE,UAC3D,YACC,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAE,UACtC,qCAAqC,KAAK,IAAI,CAAA"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { type NumberLiteral } from "@arktype/util";
|
|
2
1
|
import type { DynamicStateWithRoot } from "../../reduce/dynamic.js";
|
|
3
2
|
import type { StaticState, state } from "../../reduce/static.js";
|
|
4
3
|
import type { Scanner } from "../scanner.js";
|
|
5
4
|
export declare const parseDivisor: (s: DynamicStateWithRoot) => void;
|
|
6
|
-
export type parseDivisor<s extends StaticState, unscanned extends string> = Scanner.shiftUntilNextTerminator<Scanner.skipWhitespace<unscanned>> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? scanned extends
|
|
7
|
-
export declare const writeInvalidDivisorMessage: <divisor extends string | number>(divisor: divisor) =>
|
|
5
|
+
export type parseDivisor<s extends StaticState, unscanned extends string> = Scanner.shiftUntilNextTerminator<Scanner.skipWhitespace<unscanned>> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? scanned extends `${infer divisor extends number}` ? divisor extends 0 ? state.error<writeInvalidDivisorMessage<0>> : state.setRoot<s, [s["root"], "%", divisor], nextUnscanned> : state.error<writeInvalidDivisorMessage<scanned>> : never;
|
|
6
|
+
export declare const writeInvalidDivisorMessage: <divisor extends string | number>(divisor: divisor) => writeInvalidDivisorMessage<divisor>;
|
|
8
7
|
export type writeInvalidDivisorMessage<divisor extends string | number> = `% operator must be followed by a non-zero integer literal (was ${divisor})`;
|
|
9
|
-
//# sourceMappingURL=divisor.d.ts.map
|
|
@@ -4,10 +4,8 @@ export const parseDivisor = (s) => {
|
|
|
4
4
|
const divisor = tryParseInteger(divisorToken, {
|
|
5
5
|
errorOnFail: writeInvalidDivisorMessage(divisorToken)
|
|
6
6
|
});
|
|
7
|
-
if (divisor === 0)
|
|
7
|
+
if (divisor === 0)
|
|
8
8
|
s.error(writeInvalidDivisorMessage(0));
|
|
9
|
-
}
|
|
10
9
|
s.root = s.root.constrain("divisor", divisor);
|
|
11
10
|
};
|
|
12
11
|
export const writeInvalidDivisorMessage = (divisor) => `% operator must be followed by a non-zero integer literal (was ${divisor})`;
|
|
13
|
-
//# sourceMappingURL=divisor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"divisor.js","sourceRoot":"","sources":["../../../../../parser/string/shift/operator/divisor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"divisor.js","sourceRoot":"","sources":["../../../../../parser/string/shift/operator/divisor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAK/C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAuB,EAAQ,EAAE;IAC7D,MAAM,YAAY,GAAG,CAAC,CAAC,OAAO,CAAC,wBAAwB,EAAE,CAAA;IACzD,MAAM,OAAO,GAAG,eAAe,CAAC,YAAY,EAAE;QAC7C,WAAW,EAAE,0BAA0B,CAAC,YAAY,CAAC;KACrD,CAAC,CAAA;IACF,IAAI,OAAO,KAAK,CAAC;QAAE,CAAC,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,CAAA;IAEzD,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;AAC9C,CAAC,CAAA;AAaD,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACzC,OAAgB,EACsB,EAAE,CACxC,kEAAkE,OAAO,GAAG,CAAA"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { DynamicStateWithRoot } from "../../reduce/dynamic.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { StaticState, state } from "../../reduce/static.js";
|
|
3
3
|
import { Scanner } from "../scanner.js";
|
|
4
4
|
import { parseBound, type ComparatorStartChar } from "./bounds.js";
|
|
5
5
|
import { parseDivisor } from "./divisor.js";
|
|
6
6
|
export declare const parseOperator: (s: DynamicStateWithRoot) => void;
|
|
7
7
|
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : Scanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & Scanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends Scanner.WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
|
|
8
|
-
export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) =>
|
|
8
|
+
export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
|
|
9
9
|
export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
|
|
10
10
|
export declare const incompleteArrayTokenMessage = "Missing expected ']'";
|
|
11
11
|
type incompleteArrayTokenMessage = typeof incompleteArrayTokenMessage;
|
|
12
12
|
export {};
|
|
13
|
-
//# sourceMappingURL=operator.d.ts.map
|
|
@@ -4,26 +4,19 @@ import { comparatorStartChars, parseBound } from "./bounds.js";
|
|
|
4
4
|
import { parseDivisor } from "./divisor.js";
|
|
5
5
|
export const parseOperator = (s) => {
|
|
6
6
|
const lookahead = s.scanner.shift();
|
|
7
|
-
return lookahead === ""
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
? s.setRoot(s.root.array())
|
|
7
|
+
return (lookahead === "" ? s.finalize("")
|
|
8
|
+
: lookahead === "[" ?
|
|
9
|
+
s.scanner.shift() === "]" ?
|
|
10
|
+
s.setRoot(s.root.array())
|
|
12
11
|
: s.error(incompleteArrayTokenMessage)
|
|
13
|
-
: lookahead === "|" || lookahead === "&"
|
|
14
|
-
? s.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
: lookahead === "%"
|
|
22
|
-
? parseDivisor(s)
|
|
23
|
-
: lookahead === " "
|
|
24
|
-
? parseOperator(s)
|
|
25
|
-
: s.error(writeUnexpectedCharacterMessage(lookahead));
|
|
12
|
+
: lookahead === "|" || lookahead === "&" ? s.pushRootToBranch(lookahead)
|
|
13
|
+
: lookahead === ")" ? s.finalizeGroup()
|
|
14
|
+
: Scanner.lookaheadIsFinalizing(lookahead, s.scanner.unscanned) ?
|
|
15
|
+
s.finalize(lookahead)
|
|
16
|
+
: isKeyOf(lookahead, comparatorStartChars) ? parseBound(s, lookahead)
|
|
17
|
+
: lookahead === "%" ? parseDivisor(s)
|
|
18
|
+
: lookahead === " " ? parseOperator(s)
|
|
19
|
+
: s.error(writeUnexpectedCharacterMessage(lookahead)));
|
|
26
20
|
};
|
|
27
21
|
export const writeUnexpectedCharacterMessage = (char, shouldBe = "") => `'${char}' is not allowed here${shouldBe && ` (should be ${shouldBe})`}`;
|
|
28
22
|
export const incompleteArrayTokenMessage = `Missing expected ']'`;
|
|
29
|
-
//# sourceMappingURL=operator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operator.js","sourceRoot":"","sources":["../../../../../parser/string/shift/operator/operator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAGvC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EACN,oBAAoB,EACpB,UAAU,EAEV,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAuB,EAAQ,EAAE;IAC9D,MAAM,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IACnC,OAAO,SAAS,KAAK,EAAE
|
|
1
|
+
{"version":3,"file":"operator.js","sourceRoot":"","sources":["../../../../../parser/string/shift/operator/operator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAGvC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EACN,oBAAoB,EACpB,UAAU,EAEV,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAuB,EAAQ,EAAE;IAC9D,MAAM,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IACnC,OAAO,CACN,SAAS,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjC,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,CAAC;YACpB,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC;gBAC1B,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;gBAC1B,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,2BAA2B,CAAC;YACvC,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,SAAS,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,SAAS,CAAC;gBACxE,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE;oBACvC,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;wBAChE,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;wBACtB,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,EAAE,SAAS,CAAC;4BACrE,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;gCACrC,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;oCACtC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,+BAA+B,CAAC,SAAS,CAAC,CAAC,CACrD,CAAA;AACF,CAAC,CAAA;AAuBD,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAI9C,IAAU,EACV,WAAqB,EAAc,EACe,EAAE,CACpD,IAAI,IAAI,wBACP,QAAQ,IAAK,eAAe,QAAQ,GACrC,EAAE,CAAA;AAQH,MAAM,CAAC,MAAM,2BAA2B,GAAG,sBAAsB,CAAA"}
|
|
@@ -54,10 +54,11 @@ export declare namespace Scanner {
|
|
|
54
54
|
const whiteSpaceTokens: {
|
|
55
55
|
readonly " ": true;
|
|
56
56
|
readonly "\n": true;
|
|
57
|
+
readonly "\t": true;
|
|
57
58
|
};
|
|
58
59
|
type WhiteSpaceToken = keyof typeof whiteSpaceTokens;
|
|
59
60
|
const lookaheadIsFinalizing: (lookahead: string, unscanned: string) => lookahead is ">" | ",";
|
|
60
|
-
type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : Scanner.skipWhitespace<unscanned> extends "" | `${TerminatingChar}${string}` ? true : false : lookahead extends "," ? true : false;
|
|
61
|
+
type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : Scanner.skipWhitespace<unscanned> extends ("" | `${TerminatingChar}${string}`) ? true : false : lookahead extends "," ? true : false;
|
|
61
62
|
type shift<lookahead extends string, unscanned extends string> = `${lookahead}${unscanned}`;
|
|
62
63
|
type shiftUntil<unscanned extends string, terminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends terminator ? scanned extends `${infer base}${EscapeToken}` ? shiftUntil<nextUnscanned, terminator, `${base}${lookahead}`> : [scanned, unscanned] : shiftUntil<nextUnscanned, terminator, `${scanned}${lookahead}`> : [scanned, ""];
|
|
63
64
|
type shiftUntilNot<unscanned extends string, nonTerminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends nonTerminator ? shiftUntilNot<nextUnscanned, nonTerminator, `${scanned}${lookahead}`> : [scanned, unscanned] : [scanned, ""];
|
|
@@ -68,4 +69,3 @@ export declare namespace Scanner {
|
|
|
68
69
|
unscanned
|
|
69
70
|
];
|
|
70
71
|
}
|
|
71
|
-
//# sourceMappingURL=scanner.d.ts.map
|
|
@@ -20,12 +20,10 @@ export class Scanner {
|
|
|
20
20
|
let shifted = "";
|
|
21
21
|
while (this.lookahead) {
|
|
22
22
|
if (condition(this, shifted)) {
|
|
23
|
-
if (shifted[shifted.length - 1] === Scanner.escapeToken)
|
|
23
|
+
if (shifted[shifted.length - 1] === Scanner.escapeToken)
|
|
24
24
|
shifted = shifted.slice(0, -1);
|
|
25
|
-
|
|
26
|
-
else {
|
|
25
|
+
else
|
|
27
26
|
break;
|
|
28
|
-
}
|
|
29
27
|
}
|
|
30
28
|
shifted += this.shift();
|
|
31
29
|
}
|
|
@@ -83,17 +81,17 @@ export class Scanner {
|
|
|
83
81
|
Scanner.escapeToken = "\\";
|
|
84
82
|
Scanner.whiteSpaceTokens = {
|
|
85
83
|
" ": true,
|
|
86
|
-
"\n": true
|
|
84
|
+
"\n": true,
|
|
85
|
+
"\t": true
|
|
87
86
|
};
|
|
88
|
-
Scanner.lookaheadIsFinalizing = (lookahead, unscanned) => lookahead === ">"
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
87
|
+
Scanner.lookaheadIsFinalizing = (lookahead, unscanned) => lookahead === ">" ?
|
|
88
|
+
unscanned[0] === "=" ?
|
|
89
|
+
// >== would only occur in an expression like Array<number>==5
|
|
90
|
+
// otherwise, >= would only occur as part of a bound like number>=5
|
|
91
|
+
unscanned[1] === "="
|
|
92
|
+
// if > is the end of a generic instantiation, the next token will be an operator or the end of the string
|
|
93
|
+
: unscanned.trimStart() === "" ||
|
|
94
|
+
isKeyOf(unscanned.trimStart()[0], Scanner.terminatingChars)
|
|
95
|
+
// if the lookahead is a finalizing token but not >, it's unambiguously a finalizer (currently just ",")
|
|
96
|
+
: lookahead === ",";
|
|
98
97
|
})(Scanner || (Scanner = {}));
|
|
99
|
-
//# sourceMappingURL=scanner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../../../parser/string/shift/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../../../parser/string/shift/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,OAAO,EAAE,MAAM,eAAe,CAAA;AAGlD,MAAM,OAAO,OAAO;IACX,KAAK,CAAU;IACf,CAAC,CAAQ;IAEjB,Y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GAAG,EAAE,IAAI;KACA,CAAA;IAIG,4BAAoB,GAAG;QACnC,GAAG,EAAE,IAAI;QACT,GAAG,EAAE,IAAI;QACT,EAAE,EAAE,IAAI;KACC,CAAA;IAUG,mBAAW,GAAG,IAAI,CAAA;IAIlB,wBAAgB,GAAG;QAC/B,GAAG,EAAE,IAAI;QACT,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,IAAI;KACD,CAAA;IAIG,6BAAqB,GAAG,CACpC,SAAiB,EACjB,SAAiB,EACQ,EAAE,CAC3B,SAAS,KAAK,GAAG,CAAC,CAAC;QAClB,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;YACrB,8DAA8D;YAC9D,mEAAmE;YACnE,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG;YACpB,0GAA0G;YAC3G,CAAC,CAAC,SAAS,CAAC,SAAS,EAAE,KAAK,EAAE;gBAC7B,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;QAC5D,wGAAwG;QACzG,CAAC,CAAC,SAAS,KAAK,GAAG,CAAA;AA8DrB,CAAC,EAnIgB,OAAO,KAAP,OAAO,QAmIvB"}
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RawSchema } from "@arktype/schema";
|
|
2
2
|
import { type ErrorMessage } from "@arktype/util";
|
|
3
|
-
import type { inferAstRoot } from "../semantic/
|
|
3
|
+
import type { inferAstRoot } from "../semantic/infer.js";
|
|
4
4
|
import type { DynamicState, DynamicStateWithRoot } from "./reduce/dynamic.js";
|
|
5
5
|
import type { StringifiablePrefixOperator } from "./reduce/shared.js";
|
|
6
6
|
import type { StaticState, state } from "./reduce/static.js";
|
|
7
7
|
import type { parseOperand } from "./shift/operand/operand.js";
|
|
8
|
-
import {
|
|
8
|
+
import { type parseOperator, writeUnexpectedCharacterMessage } from "./shift/operator/operator.js";
|
|
9
9
|
/**
|
|
10
10
|
* Try to parse the definition from right to left using the most common syntax.
|
|
11
11
|
* This can be much more efficient for simple definitions.
|
|
12
12
|
*/
|
|
13
|
-
export type parseString<def extends string, $, args> = def extends keyof $ ? def : def extends `${infer child}[]` ? child extends keyof $ ? [
|
|
13
|
+
export type parseString<def extends string, $, args> = def extends keyof $ ? def : def extends `${infer child}[]` ? child extends keyof $ ? [
|
|
14
|
+
child,
|
|
15
|
+
"[]"
|
|
16
|
+
] : fullStringParse<state.initialize<def>, $, args> : fullStringParse<state.initialize<def>, $, args>;
|
|
14
17
|
export type inferString<def extends string, $, args> = inferAstRoot<parseString<def, $, args>, $, args>;
|
|
15
18
|
export type BaseCompletions<$, args, otherSuggestions extends string = never> = (keyof $ & string) | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
|
|
16
|
-
export declare const fullStringParse: (s: DynamicState) =>
|
|
19
|
+
export declare const fullStringParse: (s: DynamicState) => RawSchema;
|
|
17
20
|
type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<parseUntilFinalizer<s, $, args>>;
|
|
18
21
|
export declare const parseUntilFinalizer: (s: DynamicState) => DynamicStateWithRoot;
|
|
19
22
|
export type parseUntilFinalizer<s extends StaticState, $, args> = s["finalizer"] extends undefined ? parseUntilFinalizer<next<s, $, args>, $, args> : s;
|
|
@@ -21,4 +24,3 @@ declare const next: (s: DynamicState) => void;
|
|
|
21
24
|
type next<s extends StaticState, $, args> = s["root"] extends undefined ? parseOperand<s, $, args> : parseOperator<s, $, args>;
|
|
22
25
|
export type extractFinalizedResult<s extends StaticState> = s["finalizer"] extends ErrorMessage ? s["finalizer"] : s["finalizer"] extends "" ? s["root"] : state.error<writeUnexpectedCharacterMessage<`${s["finalizer"]}`>>;
|
|
23
26
|
export {};
|
|
24
|
-
//# sourceMappingURL=string.d.ts.map
|
|
@@ -14,10 +14,8 @@ export const fullStringParse = (s) => {
|
|
|
14
14
|
return result;
|
|
15
15
|
};
|
|
16
16
|
export const parseUntilFinalizer = (s) => {
|
|
17
|
-
while (s.finalizer === undefined)
|
|
17
|
+
while (s.finalizer === undefined)
|
|
18
18
|
next(s);
|
|
19
|
-
}
|
|
20
19
|
return s;
|
|
21
20
|
};
|
|
22
21
|
const next = (s) => s.hasRoot() ? s.parseOperator() : s.parseOperand();
|
|
23
|
-
//# sourceMappingURL=string.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../../parser/string/string.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../../parser/string/string.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,kBAAkB,EAClB,eAAe,EACf,MAAM,eAAe,CAAA;AAMtB,OAAO,EAEN,+BAA+B,EAC/B,MAAM,8BAA8B,CAAA;AA6BrC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAe,EAAa,EAAE;IAC7D,CAAC,CAAC,YAAY,EAAE,CAAA;IAChB,MAAM,MAAM,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,kBAAkB,CACxB,qDAAqD,CAAC,CAAC,OAAO,CAAC,OAAO,GAAG,CACzE,CAAA;IACF,CAAC;IACD,CAAC,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAA;IACnC,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACzB,qFAAqF;QACrF,eAAe,CAAC,+BAA+B,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;IACtE,CAAC;IACD,OAAO,MAAM,CAAA;AACd,CAAC,CAAA;AAMD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAe,EAAwB,EAAE;IAC5E,OAAO,CAAC,CAAC,SAAS,KAAK,SAAS;QAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IAEzC,OAAO,CAAyB,CAAA;AACjC,CAAC,CAAA;AAOD,MAAM,IAAI,GAAG,CAAC,CAAe,EAAE,EAAE,CAChC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAA"}
|