arktype 2.1.22 → 2.1.24

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.
Files changed (68) hide show
  1. package/README.md +23 -29
  2. package/out/attributes.d.ts +22 -25
  3. package/out/declare.d.ts +30 -0
  4. package/out/fn.d.ts +61 -0
  5. package/out/fn.js +53 -0
  6. package/out/generic.d.ts +9 -10
  7. package/out/generic.js +4 -3
  8. package/out/index.d.ts +5 -4
  9. package/out/index.js +2 -1
  10. package/out/keywords/keywords.d.ts +6 -3
  11. package/out/keywords/keywords.js +1 -0
  12. package/out/keywords/string.js +1 -12
  13. package/out/match.d.ts +3 -8
  14. package/out/nary.d.ts +21 -20
  15. package/out/parser/ast/infer.d.ts +3 -3
  16. package/out/parser/ast/utils.d.ts +2 -2
  17. package/out/parser/definition.d.ts +2 -15
  18. package/out/parser/objectLiteral.d.ts +4 -4
  19. package/out/parser/objectLiteral.js +3 -3
  20. package/out/parser/reduce/dynamic.d.ts +12 -12
  21. package/out/parser/reduce/dynamic.js +7 -7
  22. package/out/parser/reduce/shared.d.ts +0 -4
  23. package/out/parser/reduce/shared.js +0 -2
  24. package/out/parser/reduce/static.d.ts +13 -13
  25. package/out/parser/shift/operand/enclosed.d.ts +17 -9
  26. package/out/parser/shift/operand/enclosed.js +6 -3
  27. package/out/parser/shift/operand/genericArgs.d.ts +7 -8
  28. package/out/parser/shift/operand/genericArgs.js +1 -1
  29. package/out/parser/shift/operand/operand.d.ts +5 -6
  30. package/out/parser/shift/operand/unenclosed.d.ts +14 -17
  31. package/out/parser/shift/operand/unenclosed.js +3 -2
  32. package/out/parser/shift/operator/bounds.d.ts +8 -9
  33. package/out/parser/shift/operator/brand.d.ts +6 -5
  34. package/out/parser/shift/operator/brand.js +2 -1
  35. package/out/parser/shift/operator/default.d.ts +16 -9
  36. package/out/parser/shift/operator/default.js +1 -1
  37. package/out/parser/shift/operator/divisor.d.ts +6 -5
  38. package/out/parser/shift/operator/divisor.js +3 -1
  39. package/out/parser/shift/operator/operator.d.ts +6 -6
  40. package/out/parser/shift/operator/operator.js +2 -2
  41. package/out/parser/shift/tokens.d.ts +33 -0
  42. package/out/parser/shift/tokens.js +37 -0
  43. package/out/parser/string.d.ts +6 -6
  44. package/out/parser/string.js +3 -4
  45. package/out/parser/tupleExpressions.d.ts +5 -8
  46. package/out/parser/tupleExpressions.js +2 -2
  47. package/out/scope.d.ts +5 -1
  48. package/out/scope.js +4 -3
  49. package/out/type.d.ts +18 -10
  50. package/out/type.js +3 -2
  51. package/out/{methods → variants}/base.d.ts +3 -3
  52. package/out/{methods → variants}/object.d.ts +1 -1
  53. package/out/{methods → variants}/string.d.ts +4 -1
  54. package/out/variants/string.js +1 -0
  55. package/package.json +8 -3
  56. package/out/parser/shift/scanner.d.ts +0 -47
  57. package/out/parser/shift/scanner.js +0 -43
  58. /package/out/{methods/array.js → declare.js} +0 -0
  59. /package/out/{methods → variants}/array.d.ts +0 -0
  60. /package/out/{methods/base.js → variants/array.js} +0 -0
  61. /package/out/{methods/date.js → variants/base.js} +0 -0
  62. /package/out/{methods → variants}/date.d.ts +0 -0
  63. /package/out/{methods/instantiate.js → variants/date.js} +0 -0
  64. /package/out/{methods → variants}/instantiate.d.ts +0 -0
  65. /package/out/{methods/number.js → variants/instantiate.js} +0 -0
  66. /package/out/{methods → variants}/number.d.ts +0 -0
  67. /package/out/{methods/object.js → variants/number.js} +0 -0
  68. /package/out/{methods/string.js → variants/object.js} +0 -0
package/out/scope.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { BaseScope, type AliasDefEntry, type ArkSchemaRegistry, type ArkSchemaScopeConfig, type BaseNode, type BaseParseContext, type BaseParseContextInput, type BaseParseOptions, type BaseRoot, type GenericAst, type GenericParamAst, type GenericParamDef, type NodeKind, type NodeSchema, type PreparsedNodeResolution, type PrivateDeclaration, type RootKind, type RootSchema, type arkKind, type exportedNameOf, type nodeOfKind, type reducibleKindOf, type toInternalScope, type writeDuplicateAliasError } from "@ark/schema";
2
2
  import { type Brand, type ErrorType, type JsonStructure, type anyOrNever, type array, type flattenListable, type noSuggest } from "@ark/util";
3
+ import type { DeclarationParser } from "./declare.ts";
4
+ import { InternalFnParser, type FnParser } from "./fn.ts";
3
5
  import { type GenericDeclaration, type GenericParser, type ParameterString, type baseGenericConstraints, type parseGenericParams, type parseValidGenericParams } from "./generic.ts";
4
6
  import type { Ark, type } from "./keywords/keywords.ts";
5
7
  import { InternalMatchParser, type MatchParser } from "./match.ts";
@@ -9,7 +11,7 @@ import type { DefAst, InferredAst } from "./parser/ast/infer.ts";
9
11
  import { type inferDefinition } from "./parser/definition.ts";
10
12
  import type { ParsedOptionalProperty } from "./parser/property.ts";
11
13
  import type { ParsedDefaultableProperty } from "./parser/shift/operator/default.ts";
12
- import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type EnumeratedTypeParser, type InstanceOfTypeParser, type SchemaParser, type TypeParser, type UnitTypeParser, type ValueOfTypeParser } from "./type.ts";
14
+ import { InternalTypeParser, type DefinitionParser, type EnumeratedTypeParser, type InstanceOfTypeParser, type SchemaParser, type TypeParser, type UnitTypeParser, type ValueOfTypeParser } from "./type.ts";
13
15
  /** The convenience properties attached to `scope` */
14
16
  export type ScopeParserAttachments = Omit<ScopeParser, never>;
15
17
  export interface ArkScopeConfig extends ArkSchemaScopeConfig {
@@ -83,6 +85,7 @@ export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
83
85
  and: NaryIntersectionParser<$>;
84
86
  merge: NaryMergeParser<$>;
85
87
  pipe: NaryPipeParser<$>;
88
+ fn: InternalFnParser;
86
89
  match: InternalMatchParser;
87
90
  declare: () => {
88
91
  type: InternalTypeParser;
@@ -118,6 +121,7 @@ export interface Scope<$ = {}> {
118
121
  instanceOf: InstanceOfTypeParser<$>;
119
122
  type: TypeParser<$>;
120
123
  match: MatchParser<$>;
124
+ fn: FnParser<$>;
121
125
  declare: DeclarationParser<$>;
122
126
  define: DefinitionParser<$>;
123
127
  generic: GenericParser<$>;
package/out/scope.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { $ark, BaseScope, hasArkKind, parseGeneric } from "@ark/schema";
2
- import { enumValues, flatMorph, isArray, isThunk, throwParseError } from "@ark/util";
2
+ import { Scanner, enumValues, flatMorph, isArray, isThunk, throwParseError } from "@ark/util";
3
+ import { InternalFnParser } from "./fn.js";
3
4
  import { parseGenericParamName } from "./generic.js";
4
5
  import { InternalMatchParser } from "./match.js";
5
6
  import { shallowDefaultableMessage, shallowOptionalMessage } from "./parser/ast/validate.js";
6
7
  import { parseInnerDefinition } from "./parser/definition.js";
7
- import { ArkTypeScanner } from "./parser/shift/scanner.js";
8
8
  import { InternalTypeParser } from "./type.js";
9
9
  export const $arkTypeRegistry = $ark;
10
10
  export class InternalScope extends BaseScope {
@@ -46,7 +46,7 @@ export class InternalScope extends BaseScope {
46
46
  ];
47
47
  }
48
48
  parseGenericParams(def, opts) {
49
- return parseGenericParamName(new ArkTypeScanner(def), [], this.createParseContext({
49
+ return parseGenericParamName(new Scanner(def), [], this.createParseContext({
50
50
  ...opts,
51
51
  def,
52
52
  prefix: "generic"
@@ -88,6 +88,7 @@ export class InternalScope extends BaseScope {
88
88
  and = (...defs) => defs.reduce((node, def) => node.and(this.parse(def)), this.intrinsic.unknown);
89
89
  merge = (...defs) => defs.reduce((node, def) => node.merge(this.parse(def)), this.intrinsic.object);
90
90
  pipe = (...morphs) => this.intrinsic.unknown.pipe(...morphs);
91
+ fn = new InternalFnParser(this);
91
92
  match = new InternalMatchParser(this);
92
93
  declare = () => ({
93
94
  type: this.type
package/out/type.d.ts CHANGED
@@ -1,15 +1,16 @@
1
- import { ArkErrors, BaseRoot, type BaseParseOptions, type Morph, type Predicate, type RootSchema, type TypeMeta } from "@ark/schema";
1
+ import { ArkErrors, BaseRoot, type BaseParseOptions, type Morph, type NodeSelector, type Predicate, type RootSchema, type TypeMeta } from "@ark/schema";
2
2
  import { Callable, Hkt, type Constructor, type array, type conform } from "@ark/util";
3
3
  import type { distill } from "./attributes.ts";
4
+ import type { DeclarationParser } from "./declare.ts";
5
+ import type { FnParser } from "./fn.ts";
4
6
  import type { Generic, GenericParser, ParameterString, baseGenericConstraints, parseValidGenericParams, validateParameterString } from "./generic.ts";
5
7
  import type { Ark, keywords, type } from "./keywords/keywords.ts";
6
8
  import type { MatchParser } from "./match.ts";
7
- import type { BaseType } from "./methods/base.ts";
8
- import type { instantiateType } from "./methods/instantiate.ts";
9
9
  import type { NaryIntersectionParser, NaryMergeParser, NaryPipeParser, NaryUnionParser } from "./nary.ts";
10
- import type { validateDeclared } from "./parser/definition.ts";
11
10
  import type { ArgTwoOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tupleExpressions.ts";
12
- import type { InternalScope, ModuleParser, Scope, ScopeParser, bindThis } from "./scope.ts";
11
+ import type { InternalScope, ModuleParser, Scope, ScopeParser } from "./scope.ts";
12
+ import type { BaseType } from "./variants/base.ts";
13
+ import type { instantiateType } from "./variants/instantiate.ts";
13
14
  /** The convenience properties attached to `type` */
14
15
  export type TypeParserAttachments = Omit<TypeParser, never>;
15
16
  export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
@@ -38,7 +39,7 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
38
39
  *
39
40
  * @example type("string", "|", { foo: "number" })
40
41
  */
41
- <const zero, const one, const rest extends array, r = type.instantiate<[zero, one, ...rest], $>>(_0: zero extends IndexZeroOperator ? zero : type.validate<zero, $>, _1: zero extends "keyof" ? type.validate<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, ArgTwoOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distill.In<type.infer<zero, $>>>] : one extends "=>" ? [Morph<distill.Out<type.infer<zero, $>>, unknown>] : one extends "|>" ? [type.validate<rest[0], $>] : one extends "@" ? [TypeMeta.MappableInput] : [type.validate<rest[0], $>] : []): r extends infer _ ? _ : never;
42
+ <const zero, const one, const rest extends array, r = type.instantiate<[zero, one, ...rest], $>>(_0: zero extends IndexZeroOperator ? zero : type.validate<zero, $>, _1: zero extends "keyof" ? type.validate<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, ArgTwoOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distill.In<type.infer<zero, $>>>] : one extends "=>" ? [Morph<distill.Out<type.infer<zero, $>>, unknown>] : one extends "|>" ? [type.validate<rest[0], $>] : one extends "@" ? [TypeMeta.MappableInput, NodeSelector?] : [type.validate<rest[0], $>] : []): r extends infer _ ? _ : never;
42
43
  /**
43
44
  * An alias of the {@link ArkErrors} class, an instance of which is returned when a {@link Type}
44
45
  * is invoked with invalid input.
@@ -47,7 +48,6 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
47
48
  * const out = myType(data)
48
49
  *
49
50
  * if(out instanceof type.errors) console.log(out.summary)
50
- *
51
51
  */
52
52
  errors: typeof ArkErrors;
53
53
  hkt: typeof Hkt;
@@ -65,6 +65,7 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
65
65
  module: ModuleParser;
66
66
  scope: ScopeParser;
67
67
  define: DefinitionParser<$>;
68
+ declare: DeclarationParser<$>;
68
69
  generic: GenericParser<$>;
69
70
  match: MatchParser<$>;
70
71
  schema: SchemaParser<$>;
@@ -118,13 +119,20 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
118
119
  * const T = type.pipe(type.string, s => JSON.parse(s), type.object)
119
120
  */
120
121
  pipe: NaryPipeParser<$>;
122
+ /**
123
+ * Define a validated function
124
+ * @example
125
+ * const len = type.fn("string | unknown[]", ":", "number")(s => s.length)
126
+ * len("foo") // 3
127
+ * // TypeScript: boolean is not assignable to string | unknown[]
128
+ * // Runtime (throws): must be a string or an object (was boolean)
129
+ * len(true)
130
+ */
131
+ fn: FnParser<$>;
121
132
  }
122
133
  export declare class InternalTypeParser extends Callable<(...args: unknown[]) => BaseRoot | Generic, TypeParserAttachments> {
123
134
  constructor($: InternalScope);
124
135
  }
125
- export type DeclarationParser<$> = <preinferred>() => {
126
- type: <const def>(def: validateDeclared<preinferred, def, $, bindThis<def>>) => Type<preinferred, $>;
127
- };
128
136
  export type UnitTypeParser<$> = <const t>(value: t) => Type<t, $>;
129
137
  export type InstanceOfTypeParser<$> = <const t extends object>(ctor: Constructor<t>) => Type<t, $>;
130
138
  export type EnumeratedTypeParser<$> = <const values extends readonly unknown[]>(...values: values) => Type<values[number], $>;
package/out/type.js CHANGED
@@ -9,6 +9,7 @@ export class InternalTypeParser extends Callable {
9
9
  raw: $.parse,
10
10
  module: $.constructor.module,
11
11
  scope: $.constructor.scope,
12
+ declare: $.declare,
12
13
  define: $.define,
13
14
  match: $.match,
14
15
  generic: $.generic,
@@ -22,7 +23,8 @@ export class InternalTypeParser extends Callable {
22
23
  or: $.or,
23
24
  and: $.and,
24
25
  merge: $.merge,
25
- pipe: $.pipe
26
+ pipe: $.pipe,
27
+ fn: $.fn
26
28
  },
27
29
  // also won't be defined during bootstrapping
28
30
  $.ambientAttachments);
@@ -46,7 +48,6 @@ export class InternalTypeParser extends Callable {
46
48
  // part of the API as specified by the associated types
47
49
  return $.parse(args);
48
50
  }, {
49
- bind: $,
50
51
  attach
51
52
  });
52
53
  }
@@ -142,7 +142,7 @@ export interface Inferred<out t = unknown, $ = {}> {
142
142
  *
143
143
  * @throws {TraversalError}
144
144
  */
145
- assert(data: unknown): this["infer"];
145
+ assert: (data: unknown) => this["infer"];
146
146
  /**
147
147
  * #### check input without applying morphs
148
148
  *
@@ -153,7 +153,7 @@ export interface Inferred<out t = unknown, $ = {}> {
153
153
  * // [0, 2n]
154
154
  * const numerics = [0, "one", 2n].filter(Numeric.allows)
155
155
  */
156
- allows(data: unknown): data is this["inferIn"];
156
+ allows: (data: unknown) => data is this["inferIn"];
157
157
  /**
158
158
  * #### add metadata to shallow references
159
159
  *
@@ -318,7 +318,7 @@ export interface Inferred<out t = unknown, $ = {}> {
318
318
  */
319
319
  filter<narrowed extends this["inferIn"] = never, r = instantiateType<[
320
320
  narrowed
321
- ] extends [never] ? t : t extends InferredMorph<any, infer o> ? (In: narrowed) => o : narrowed, $>>(predicate: Predicate.Castable<this["inferIn"], narrowed>): r extends infer _ ? _ : never;
321
+ ] extends [never] ? t : t extends InferredMorph<never, infer o> ? (In: narrowed) => o : narrowed, $>>(predicate: Predicate.Castable<this["inferIn"], narrowed>): r extends infer _ ? _ : never;
322
322
  /**
323
323
  * #### apply a predicate function to output
324
324
  *
@@ -38,7 +38,7 @@ interface Type<out t extends object = object, $ = {}> extends BaseType<t, $> {
38
38
  * Merge another `Type` definition, overriding properties of this `Type` with the duplicate keys.
39
39
  * @example type({ a: "1", b: "2" }).merge({ b: "3", c: "4" }) // Type<{ a: 1, b: 3, c: 4 }>
40
40
  */
41
- merge<const def, inferredDef = type.infer<def, $>, r = Type<merge<t, inferredDef>, $>>(def: type.validate<def, $> & (inferredDef extends object ? unknown : ErrorType<NonObjectMergeErrorMessage, [actual: inferredDef]>)): r extends infer _ ? _ : never;
41
+ merge<const def, inferredDef = type.infer<def, $>, r = Type<merge<t, inferredDef>, $>>(def: type.validate<def, $> & (inferredDef extends object ? unknown : ErrorType<[NonObjectMergeErrorMessage, actual: inferredDef]>)): r extends infer _ ? _ : never;
42
42
  /**
43
43
  * Create a copy of this `Type` with all properties required.
44
44
  * @example const T = type({ "foo?"": "string" }).required() // Type<{ foo: string }>
@@ -1,8 +1,11 @@
1
1
  import type { ExactLength, ExclusiveNumericRangeSchema, InclusiveNumericRangeSchema, Pattern } from "@ark/schema";
2
+ import type { regex } from "arkregex";
2
3
  import type { BaseType } from "./base.ts";
3
4
  /** @ts-ignore cast variance */
4
5
  interface Type<out t extends string = string, $ = {}> extends BaseType<t, $> {
5
- matching(schema: Pattern.Schema): this;
6
+ matching<const schema extends Pattern.Schema>(schema: schema): schema extends string ? Type<regex.infer<schema>, $> : schema extends {
7
+ rule: infer pattern extends string;
8
+ } ? Type<regex.infer<pattern>, $> : this;
6
9
  atLeastLength(schema: InclusiveNumericRangeSchema): this;
7
10
  atMostLength(schema: InclusiveNumericRangeSchema): this;
8
11
  moreThanLength(schema: ExclusiveNumericRangeSchema): this;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arktype",
3
3
  "description": "TypeScript's 1:1 validator, optimized from editor to runtime",
4
- "version": "2.1.22",
4
+ "version": "2.1.24",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -28,14 +28,19 @@
28
28
  "./internal/*.ts": {
29
29
  "ark-ts": "./*.ts",
30
30
  "default": "./out/*.js"
31
+ },
32
+ "./internal/*.js": {
33
+ "ark-ts": "./*.ts",
34
+ "default": "./out/*.js"
31
35
  }
32
36
  },
33
37
  "files": [
34
38
  "out"
35
39
  ],
36
40
  "dependencies": {
37
- "@ark/util": "0.49.0",
38
- "@ark/schema": "0.49.0"
41
+ "@ark/schema": "0.52.0",
42
+ "@ark/util": "0.52.0",
43
+ "arkregex": "0.0.1"
39
44
  },
40
45
  "publishConfig": {
41
46
  "access": "public"
@@ -1,47 +0,0 @@
1
- import { Scanner, type EscapeChar, type WhitespaceChar } from "@ark/util";
2
- import type { Comparator } from "../reduce/shared.ts";
3
- export declare class ArkTypeScanner<lookahead extends string = string> extends Scanner<lookahead> {
4
- shiftUntilNextTerminator(): string;
5
- static terminatingChars: {
6
- readonly " ": 1;
7
- readonly "\n": 1;
8
- readonly "\t": 1;
9
- readonly "<": 1;
10
- readonly ">": 1;
11
- readonly "=": 1;
12
- readonly "|": 1;
13
- readonly "&": 1;
14
- readonly ")": 1;
15
- readonly "[": 1;
16
- readonly "%": 1;
17
- readonly ",": 1;
18
- readonly ":": 1;
19
- readonly "?": 1;
20
- readonly "#": 1;
21
- };
22
- static finalizingLookaheads: {
23
- readonly ">": 1;
24
- readonly ",": 1;
25
- readonly "": 1;
26
- readonly "=": 1;
27
- readonly "?": 1;
28
- };
29
- static lookaheadIsFinalizing: (lookahead: string, unscanned: string) => lookahead is ">" | "," | "=" | "?";
30
- }
31
- export declare namespace ArkTypeScanner {
32
- type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : ArkTypeScanner.skipWhitespace<unscanned> extends ("" | `${TerminatingChar}${string}`) ? true : false : lookahead extends "=" ? unscanned extends `=${string}` ? false : true : lookahead extends "," | "?" ? true : false;
33
- type TerminatingChar = keyof typeof ArkTypeScanner.terminatingChars;
34
- type FinalizingLookahead = keyof typeof ArkTypeScanner.finalizingLookaheads;
35
- type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>" | "|>" | "#" | "@" | "=";
36
- type PostfixToken = "[]" | "?";
37
- type OperatorToken = InfixToken | PostfixToken;
38
- type shift<lookahead extends string, unscanned extends string> = `${lookahead}${unscanned}`;
39
- 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}${EscapeChar}` ? shiftUntil<nextUnscanned, terminator, `${base}${lookahead}`> : [scanned, unscanned] : shiftUntil<nextUnscanned, terminator, `${scanned}${lookahead}`> : [scanned, ""];
40
- 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, ""];
41
- type shiftUntilNextTerminator<unscanned extends string> = shiftUntil<unscanned, TerminatingChar>;
42
- type skipWhitespace<unscanned extends string> = shiftUntilNot<unscanned, WhitespaceChar>[1];
43
- type shiftResult<scanned extends string, unscanned extends string> = [
44
- scanned,
45
- unscanned
46
- ];
47
- }
@@ -1,43 +0,0 @@
1
- import { isKeyOf, Scanner, whitespaceChars } from "@ark/util";
2
- export class ArkTypeScanner extends Scanner {
3
- shiftUntilNextTerminator() {
4
- this.shiftUntilNonWhitespace();
5
- return this.shiftUntil(() => this.lookahead in ArkTypeScanner.terminatingChars);
6
- }
7
- static terminatingChars = {
8
- "<": 1,
9
- ">": 1,
10
- "=": 1,
11
- "|": 1,
12
- "&": 1,
13
- ")": 1,
14
- "[": 1,
15
- "%": 1,
16
- ",": 1,
17
- ":": 1,
18
- "?": 1,
19
- "#": 1,
20
- ...whitespaceChars
21
- };
22
- static finalizingLookaheads = {
23
- ">": 1,
24
- ",": 1,
25
- "": 1,
26
- "=": 1,
27
- "?": 1
28
- };
29
- static lookaheadIsFinalizing = (lookahead, unscanned) => lookahead === ">" ?
30
- unscanned[0] === "=" ?
31
- // >== would only occur in an expression like Array<number>==5
32
- // otherwise, >= would only occur as part of a bound like number>=5
33
- unscanned[1] === "="
34
- // if > is the end of a generic instantiation, the next token will be
35
- // an operator or the end of the string
36
- : unscanned.trimStart() === "" ||
37
- isKeyOf(unscanned.trimStart()[0], ArkTypeScanner.terminatingChars)
38
- // "=" is a finalizer on its own (representing a default value),
39
- // but not with a second "=" (an equality comparator)
40
- : lookahead === "=" ? unscanned[0] !== "="
41
- // "," and "?" are unambiguously finalizers
42
- : lookahead === "," || lookahead === "?";
43
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes