@sinclair/typebox 0.33.19 → 0.33.21
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/build/cjs/index.d.ts +1 -0
- package/build/cjs/index.js +5 -1
- package/build/cjs/parse/index.d.ts +1 -0
- package/build/cjs/parse/index.js +18 -0
- package/build/cjs/parse/parse.d.ts +11 -0
- package/build/cjs/parse/parse.js +18 -0
- package/build/cjs/parse/parsebox/index.d.ts +2 -0
- package/build/cjs/parse/parsebox/index.js +6 -0
- package/build/cjs/parse/parsebox/runtime/guard.d.ts +17 -0
- package/build/cjs/parse/parsebox/runtime/guard.js +75 -0
- package/build/cjs/parse/parsebox/runtime/index.d.ts +5 -0
- package/build/cjs/parse/parsebox/runtime/index.js +23 -0
- package/build/cjs/parse/parsebox/runtime/module.d.ts +9 -0
- package/build/cjs/parse/parsebox/runtime/module.js +22 -0
- package/build/cjs/parse/parsebox/runtime/parse.d.ts +9 -0
- package/build/cjs/parse/parsebox/runtime/parse.js +99 -0
- package/build/cjs/parse/parsebox/runtime/token.d.ts +8 -0
- package/build/cjs/parse/parsebox/runtime/token.js +230 -0
- package/build/cjs/parse/parsebox/runtime/types.d.ts +68 -0
- package/build/cjs/parse/parsebox/runtime/types.js +45 -0
- package/build/cjs/parse/parsebox/static/index.d.ts +3 -0
- package/build/cjs/parse/parsebox/static/index.js +21 -0
- package/build/cjs/parse/parsebox/static/parse.d.ts +17 -0
- package/build/cjs/parse/parsebox/static/parse.js +3 -0
- package/build/cjs/parse/parsebox/static/token.d.ts +108 -0
- package/build/cjs/parse/parsebox/static/token.js +3 -0
- package/build/cjs/parse/parsebox/static/types.d.ts +46 -0
- package/build/cjs/parse/parsebox/static/types.js +3 -0
- package/build/cjs/parse/runtime.d.ts +55 -0
- package/build/cjs/parse/runtime.js +621 -0
- package/build/cjs/parse/static.d.ts +471 -0
- package/build/cjs/parse/static.js +3 -0
- package/build/esm/index.d.mts +1 -0
- package/build/esm/index.mjs +5 -1
- package/build/esm/parse/index.d.mts +1 -0
- package/build/esm/parse/index.mjs +1 -0
- package/build/esm/parse/parse.d.mts +11 -0
- package/build/esm/parse/parse.mjs +13 -0
- package/build/esm/parse/parsebox/index.d.mts +2 -0
- package/build/esm/parse/parsebox/index.mjs +2 -0
- package/build/esm/parse/parsebox/runtime/guard.d.mts +17 -0
- package/build/esm/parse/parsebox/runtime/guard.mjs +64 -0
- package/build/esm/parse/parsebox/runtime/index.d.mts +5 -0
- package/build/esm/parse/parsebox/runtime/index.mjs +5 -0
- package/build/esm/parse/parsebox/runtime/module.d.mts +9 -0
- package/build/esm/parse/parsebox/runtime/module.mjs +17 -0
- package/build/esm/parse/parsebox/runtime/parse.d.mts +9 -0
- package/build/esm/parse/parsebox/runtime/parse.mjs +95 -0
- package/build/esm/parse/parsebox/runtime/token.d.mts +8 -0
- package/build/esm/parse/parsebox/runtime/token.mjs +223 -0
- package/build/esm/parse/parsebox/runtime/types.d.mts +68 -0
- package/build/esm/parse/parsebox/runtime/types.mjs +32 -0
- package/build/esm/parse/parsebox/static/index.d.mts +3 -0
- package/build/esm/parse/parsebox/static/index.mjs +3 -0
- package/build/esm/parse/parsebox/static/parse.d.mts +17 -0
- package/build/esm/parse/parsebox/static/parse.mjs +1 -0
- package/build/esm/parse/parsebox/static/token.d.mts +108 -0
- package/build/esm/parse/parsebox/static/token.mjs +1 -0
- package/build/esm/parse/parsebox/static/types.d.mts +46 -0
- package/build/esm/parse/parsebox/static/types.mjs +1 -0
- package/build/esm/parse/runtime.d.mts +55 -0
- package/build/esm/parse/runtime.mjs +617 -0
- package/build/esm/parse/static.d.mts +471 -0
- package/build/esm/parse/static.mjs +1 -0
- package/package.json +11 -1
- package/parse/package.json +4 -0
- package/readme.md +5 -4
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export type IModuleProperties = Record<PropertyKey, IParser>;
|
|
2
|
+
/** Infers the Output Parameter for a Parser */
|
|
3
|
+
export type StaticParser<Parser extends IParser> = Parser extends IParser<infer Output extends unknown> ? Output : unknown;
|
|
4
|
+
export type IMapping<Input extends unknown = any, Output extends unknown = unknown> = (input: Input, context: any) => Output;
|
|
5
|
+
/** Maps input to output. This is the default Mapping */
|
|
6
|
+
export declare const Identity: (value: unknown) => unknown;
|
|
7
|
+
/** Maps the output as the given parameter T */
|
|
8
|
+
export declare const As: <T>(mapping: T) => ((value: unknown) => T);
|
|
9
|
+
export interface IParser<Output extends unknown = unknown> {
|
|
10
|
+
type: string;
|
|
11
|
+
mapping: IMapping<any, Output>;
|
|
12
|
+
}
|
|
13
|
+
export type TupleParameter<Parsers extends IParser[], Result extends unknown[] = []> = Parsers extends [infer L extends IParser, ...infer R extends IParser[]] ? TupleParameter<R, [...Result, StaticParser<L>]> : Result;
|
|
14
|
+
export interface ITuple<Output extends unknown = unknown> extends IParser<Output> {
|
|
15
|
+
type: 'Tuple';
|
|
16
|
+
parsers: IParser[];
|
|
17
|
+
}
|
|
18
|
+
/** Creates a Tuple parser */
|
|
19
|
+
export declare function Tuple<Parsers extends IParser[], Mapping extends IMapping = IMapping<TupleParameter<Parsers>>>(parsers: [...Parsers], mapping: Mapping): ITuple<ReturnType<Mapping>>;
|
|
20
|
+
/** Creates a Tuple parser */
|
|
21
|
+
export declare function Tuple<Parsers extends IParser[]>(parsers: [...Parsers]): ITuple<TupleParameter<Parsers>>;
|
|
22
|
+
export type UnionParameter<Parsers extends IParser[], Result extends unknown = never> = Parsers extends [infer L extends IParser, ...infer R extends IParser[]] ? UnionParameter<R, Result | StaticParser<L>> : Result;
|
|
23
|
+
export interface IUnion<Output extends unknown = unknown> extends IParser<Output> {
|
|
24
|
+
type: 'Union';
|
|
25
|
+
parsers: IParser[];
|
|
26
|
+
}
|
|
27
|
+
/** Creates a Union parser */
|
|
28
|
+
export declare function Union<Parsers extends IParser[], Mapping extends IMapping = IMapping<UnionParameter<Parsers>>>(parsers: [...Parsers], mapping: Mapping): IUnion<ReturnType<Mapping>>;
|
|
29
|
+
/** Creates a Union parser */
|
|
30
|
+
export declare function Union<Parsers extends IParser[]>(parsers: [...Parsers]): IUnion<UnionParameter<Parsers>>;
|
|
31
|
+
export interface IConst<Output extends unknown = unknown> extends IParser<Output> {
|
|
32
|
+
type: 'Const';
|
|
33
|
+
value: string;
|
|
34
|
+
}
|
|
35
|
+
/** Creates a Const parser */
|
|
36
|
+
export declare function Const<Value extends string, Mapping extends IMapping<Value>>(value: Value, mapping: Mapping): IConst<ReturnType<Mapping>>;
|
|
37
|
+
/** Creates a Const parser */
|
|
38
|
+
export declare function Const<Value extends string>(value: Value): IConst<Value>;
|
|
39
|
+
export interface IRef<Output extends unknown = unknown> extends IParser<Output> {
|
|
40
|
+
type: 'Ref';
|
|
41
|
+
ref: string;
|
|
42
|
+
}
|
|
43
|
+
/** Creates a Ref parser */
|
|
44
|
+
export declare function Ref<Type extends unknown, Mapping extends IMapping<Type>>(ref: string, mapping: Mapping): IRef<ReturnType<Mapping>>;
|
|
45
|
+
/** Creates a Ref parser */
|
|
46
|
+
export declare function Ref<Type extends unknown>(ref: string): IRef<Type>;
|
|
47
|
+
export interface IString<Output extends unknown = unknown> extends IParser<Output> {
|
|
48
|
+
type: 'String';
|
|
49
|
+
options: string[];
|
|
50
|
+
}
|
|
51
|
+
/** Creates a String Parser. Options are an array of permissable quote characters */
|
|
52
|
+
export declare function String<Mapping extends IMapping<string>>(options: string[], mapping: Mapping): IString<ReturnType<Mapping>>;
|
|
53
|
+
/** Creates a String Parser. Options are an array of permissable quote characters */
|
|
54
|
+
export declare function String(options: string[]): IString<string>;
|
|
55
|
+
export interface IIdent<Output extends unknown = unknown> extends IParser<Output> {
|
|
56
|
+
type: 'Ident';
|
|
57
|
+
}
|
|
58
|
+
/** Creates an Ident parser */
|
|
59
|
+
export declare function Ident<Mapping extends IMapping<string>>(mapping: Mapping): IIdent<ReturnType<Mapping>>;
|
|
60
|
+
/** Creates an Ident parser */
|
|
61
|
+
export declare function Ident(): IIdent<string>;
|
|
62
|
+
export interface INumber<Output extends unknown = unknown> extends IParser<Output> {
|
|
63
|
+
type: 'Number';
|
|
64
|
+
}
|
|
65
|
+
/** Creates a Number parser */
|
|
66
|
+
export declare function Number<Mapping extends IMapping<string>>(mapping: Mapping): INumber<ReturnType<Mapping>>;
|
|
67
|
+
/** Creates a Number parser */
|
|
68
|
+
export declare function Number(): INumber<string>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.As = exports.Identity = void 0;
|
|
5
|
+
exports.Tuple = Tuple;
|
|
6
|
+
exports.Union = Union;
|
|
7
|
+
exports.Const = Const;
|
|
8
|
+
exports.Ref = Ref;
|
|
9
|
+
exports.String = String;
|
|
10
|
+
exports.Ident = Ident;
|
|
11
|
+
exports.Number = Number;
|
|
12
|
+
/** Maps input to output. This is the default Mapping */
|
|
13
|
+
const Identity = (value) => value;
|
|
14
|
+
exports.Identity = Identity;
|
|
15
|
+
/** Maps the output as the given parameter T */
|
|
16
|
+
const As = (mapping) => (_) => mapping;
|
|
17
|
+
exports.As = As;
|
|
18
|
+
function Tuple(...args) {
|
|
19
|
+
const [parsers, mapping] = args.length === 2 ? [args[0], args[1]] : [args[0], exports.Identity];
|
|
20
|
+
return { type: 'Tuple', parsers, mapping };
|
|
21
|
+
}
|
|
22
|
+
function Union(...args) {
|
|
23
|
+
const [parsers, mapping] = args.length === 2 ? [args[0], args[1]] : [args[0], exports.Identity];
|
|
24
|
+
return { type: 'Union', parsers, mapping };
|
|
25
|
+
}
|
|
26
|
+
function Const(...args) {
|
|
27
|
+
const [value, mapping] = args.length === 2 ? [args[0], args[1]] : [args[0], exports.Identity];
|
|
28
|
+
return { type: 'Const', value, mapping };
|
|
29
|
+
}
|
|
30
|
+
function Ref(...args) {
|
|
31
|
+
const [ref, mapping] = args.length === 2 ? [args[0], args[1]] : [args[0], exports.Identity];
|
|
32
|
+
return { type: 'Ref', ref, mapping };
|
|
33
|
+
}
|
|
34
|
+
function String(...params) {
|
|
35
|
+
const [options, mapping] = params.length === 2 ? [params[0], params[1]] : [params[0], exports.Identity];
|
|
36
|
+
return { type: 'String', options, mapping };
|
|
37
|
+
}
|
|
38
|
+
function Ident(...params) {
|
|
39
|
+
const mapping = params.length === 1 ? params[0] : exports.Identity;
|
|
40
|
+
return { type: 'Ident', mapping };
|
|
41
|
+
}
|
|
42
|
+
function Number(...params) {
|
|
43
|
+
const mapping = params.length === 1 ? params[0] : exports.Identity;
|
|
44
|
+
return { type: 'Number', mapping };
|
|
45
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.Token = void 0;
|
|
19
|
+
exports.Token = require("./token");
|
|
20
|
+
__exportStar(require("./parse"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as Tokens from './token';
|
|
2
|
+
import * as Types from './types';
|
|
3
|
+
type TupleParser<Parsers extends Types.IParser[], Code extends string, Context extends unknown, Result extends unknown[] = []> = (Parsers extends [infer Left extends Types.IParser, ...infer Right extends Types.IParser[]] ? Parse<Left, Code, Context> extends [infer Value extends unknown, infer Rest extends string] ? TupleParser<Right, Rest, Context, [...Result, Value]> : [] : [Result, Code]);
|
|
4
|
+
type UnionParser<Parsers extends Types.IParser[], Code extends string, Context extends unknown> = (Parsers extends [infer Left extends Types.IParser, ...infer Right extends Types.IParser[]] ? Parse<Left, Code, Context> extends [infer Value extends unknown, infer Rest extends string] ? [Value, Rest] : UnionParser<Right, Code, Context> : []);
|
|
5
|
+
type ConstParser<Value extends string, Code extends string, _Context extends unknown> = (Tokens.Const<Value, Code> extends [infer Match extends Value, infer Rest extends string] ? [Match, Rest] : []);
|
|
6
|
+
type IdentParser<Code extends string, _Context extends unknown> = (Tokens.Ident<Code> extends [infer Match extends string, infer Rest extends string] ? [Match, Rest] : []);
|
|
7
|
+
type NumberParser<Code extends string, _Context extends unknown> = (Tokens.Number<Code> extends [infer Match extends string, infer Rest extends string] ? [Match, Rest] : []);
|
|
8
|
+
type StringParser<Options extends string[], Code extends string, _Context extends unknown> = (Tokens.String<Options, Code> extends [infer Match extends string, infer Rest extends string] ? [Match, Rest] : []);
|
|
9
|
+
type ParseCode<Type extends Types.IParser, Code extends string, Context extends unknown = unknown> = (Type extends Types.Union<infer S extends Types.IParser[]> ? UnionParser<S, Code, Context> : Type extends Types.Tuple<infer S extends Types.IParser[]> ? TupleParser<S, Code, Context> : Type extends Types.Const<infer S extends string> ? ConstParser<S, Code, Context> : Type extends Types.String<infer S extends string[]> ? StringParser<S, Code, Context> : Type extends Types.Ident ? IdentParser<Code, Context> : Type extends Types.Number ? NumberParser<Code, Context> : [
|
|
10
|
+
]);
|
|
11
|
+
type ParseMapping<Parser extends Types.IParser, Result extends unknown, Context extends unknown = unknown> = ((Parser['mapping'] & {
|
|
12
|
+
input: Result;
|
|
13
|
+
context: Context;
|
|
14
|
+
})['output']);
|
|
15
|
+
/** Parses code with the given parser */
|
|
16
|
+
export type Parse<Type extends Types.IParser, Code extends string, Context extends unknown = unknown> = (ParseCode<Type, Code, Context> extends [infer L extends unknown, infer R extends string] ? [ParseMapping<Type, L, Context>, R] : []);
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
declare namespace Chars {
|
|
2
|
+
type Empty = '';
|
|
3
|
+
type Space = ' ';
|
|
4
|
+
type Newline = '\n';
|
|
5
|
+
type Dot = '.';
|
|
6
|
+
type Hyphen = '-';
|
|
7
|
+
type Digit = [
|
|
8
|
+
'0',
|
|
9
|
+
'1',
|
|
10
|
+
'2',
|
|
11
|
+
'3',
|
|
12
|
+
'4',
|
|
13
|
+
'5',
|
|
14
|
+
'6',
|
|
15
|
+
'7',
|
|
16
|
+
'8',
|
|
17
|
+
'9'
|
|
18
|
+
];
|
|
19
|
+
type Alpha = [
|
|
20
|
+
'a',
|
|
21
|
+
'b',
|
|
22
|
+
'c',
|
|
23
|
+
'd',
|
|
24
|
+
'e',
|
|
25
|
+
'f',
|
|
26
|
+
'g',
|
|
27
|
+
'h',
|
|
28
|
+
'i',
|
|
29
|
+
'j',
|
|
30
|
+
'k',
|
|
31
|
+
'l',
|
|
32
|
+
'm',
|
|
33
|
+
'n',
|
|
34
|
+
'o',
|
|
35
|
+
'p',
|
|
36
|
+
'q',
|
|
37
|
+
'r',
|
|
38
|
+
's',
|
|
39
|
+
't',
|
|
40
|
+
'u',
|
|
41
|
+
'v',
|
|
42
|
+
'w',
|
|
43
|
+
'x',
|
|
44
|
+
'y',
|
|
45
|
+
'z',
|
|
46
|
+
'A',
|
|
47
|
+
'B',
|
|
48
|
+
'C',
|
|
49
|
+
'D',
|
|
50
|
+
'E',
|
|
51
|
+
'F',
|
|
52
|
+
'G',
|
|
53
|
+
'H',
|
|
54
|
+
'I',
|
|
55
|
+
'J',
|
|
56
|
+
'K',
|
|
57
|
+
'L',
|
|
58
|
+
'M',
|
|
59
|
+
'N',
|
|
60
|
+
'O',
|
|
61
|
+
'P',
|
|
62
|
+
'Q',
|
|
63
|
+
'R',
|
|
64
|
+
'S',
|
|
65
|
+
'T',
|
|
66
|
+
'U',
|
|
67
|
+
'V',
|
|
68
|
+
'W',
|
|
69
|
+
'X',
|
|
70
|
+
'Y',
|
|
71
|
+
'Z'
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
declare namespace Trim {
|
|
75
|
+
type W4 = `${W3}${W3}`;
|
|
76
|
+
type W3 = `${W2}${W2}`;
|
|
77
|
+
type W2 = `${W1}${W1}`;
|
|
78
|
+
type W1 = `${W0}${W0}`;
|
|
79
|
+
type W0 = ` `;
|
|
80
|
+
/** Trims whitespace only */
|
|
81
|
+
export type TrimWhitespace<Code extends string> = (Code extends `${W4}${infer Rest extends string}` ? TrimWhitespace<Rest> : Code extends `${W3}${infer Rest extends string}` ? TrimWhitespace<Rest> : Code extends `${W1}${infer Rest extends string}` ? TrimWhitespace<Rest> : Code extends `${W0}${infer Rest extends string}` ? TrimWhitespace<Rest> : Code);
|
|
82
|
+
/** Trims Whitespace and Newline */
|
|
83
|
+
export type TrimAll<Code extends string> = (Code extends `${W4}${infer Rest extends string}` ? TrimAll<Rest> : Code extends `${W3}${infer Rest extends string}` ? TrimAll<Rest> : Code extends `${W1}${infer Rest extends string}` ? TrimAll<Rest> : Code extends `${W0}${infer Rest extends string}` ? TrimAll<Rest> : Code extends `${Chars.Newline}${infer Rest extends string}` ? TrimAll<Rest> : Code);
|
|
84
|
+
export {};
|
|
85
|
+
}
|
|
86
|
+
/** Scans for the next match union */
|
|
87
|
+
type NextUnion<Variants extends string[], Code extends string> = (Variants extends [infer Variant extends string, ...infer Rest1 extends string[]] ? NextConst<Variant, Code> extends [infer Match extends string, infer Rest2 extends string] ? [Match, Rest2] : NextUnion<Rest1, Code> : []);
|
|
88
|
+
type NextConst<Value extends string, Code extends string> = (Code extends `${Value}${infer Rest extends string}` ? [Value, Rest] : []);
|
|
89
|
+
/** Scans for the next constant value */
|
|
90
|
+
export type Const<Value extends string, Code extends string> = (Value extends '' ? ['', Code] : Value extends `${infer First extends string}${string}` ? (First extends Chars.Newline ? NextConst<Value, Trim.TrimWhitespace<Code>> : First extends Chars.Space ? NextConst<Value, Code> : NextConst<Value, Trim.TrimAll<Code>>) : never);
|
|
91
|
+
type NextNumberNegate<Code extends string> = (Code extends `${Chars.Hyphen}${infer Rest extends string}` ? [Chars.Hyphen, Rest] : [Chars.Empty, Code]);
|
|
92
|
+
type NextNumberZeroCheck<Code extends string> = (Code extends `0${infer Rest}` ? NextUnion<Chars.Digit, Rest> extends [string, string] ? false : true : true);
|
|
93
|
+
type NextNumberScan<Code extends string, HasDecimal extends boolean = false, Result extends string = Chars.Empty> = (NextUnion<[...Chars.Digit, Chars.Dot], Code> extends [infer Char extends string, infer Rest extends string] ? Char extends Chars.Dot ? HasDecimal extends false ? NextNumberScan<Rest, true, `${Result}${Char}`> : [Result, `.${Rest}`] : NextNumberScan<Rest, HasDecimal, `${Result}${Char}`> : [Result, Code]);
|
|
94
|
+
export type NextNumber<Code extends string> = (NextNumberNegate<Code> extends [infer Negate extends string, infer Rest extends string] ? NextNumberZeroCheck<Rest> extends true ? NextNumberScan<Rest> extends [infer Number extends string, infer Rest2 extends string] ? Number extends Chars.Empty ? [] : [`${Negate}${Number}`, Rest2] : [] : [] : []);
|
|
95
|
+
/** Scans for the next literal number */
|
|
96
|
+
export type Number<Code extends string> = NextNumber<Trim.TrimAll<Code>>;
|
|
97
|
+
type NextStringQuote<Options extends string[], Code extends string> = NextUnion<Options, Code>;
|
|
98
|
+
type NextStringBody<Code extends string, Quote extends string, Result extends string = Chars.Empty> = (Code extends `${infer Char extends string}${infer Rest extends string}` ? Char extends Quote ? [Result, Rest] : NextStringBody<Rest, Quote, `${Result}${Char}`> : []);
|
|
99
|
+
type NextString<Options extends string[], Code extends string> = (NextStringQuote<Options, Code> extends [infer Quote extends string, infer Rest extends string] ? NextStringBody<Rest, Quote> extends [infer String extends string, infer Rest extends string] ? [String, Rest] : [] : []);
|
|
100
|
+
/** Scans for the next literal string */
|
|
101
|
+
export type String<Options extends string[], Code extends string> = NextString<Options, Trim.TrimAll<Code>>;
|
|
102
|
+
type IdentLeft = [...Chars.Alpha, '_', '$'];
|
|
103
|
+
type IdentRight = [...Chars.Digit, ...IdentLeft];
|
|
104
|
+
type NextIdentScan<Code extends string, Result extends string = Chars.Empty> = (NextUnion<IdentRight, Code> extends [infer Char extends string, infer Rest extends string] ? NextIdentScan<Rest, `${Result}${Char}`> : [Result, Code]);
|
|
105
|
+
type NextIdent<Code extends string> = (NextUnion<IdentLeft, Code> extends [infer Left extends string, infer Rest1 extends string] ? NextIdentScan<Rest1> extends [infer Right extends string, infer Rest2 extends string] ? [`${Left}${Right}`, Rest2] : [] : []);
|
|
106
|
+
/** Scans for the next Ident */
|
|
107
|
+
export type Ident<Code extends string> = NextIdent<Trim.TrimAll<Code>>;
|
|
108
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface IMapping {
|
|
2
|
+
context: unknown;
|
|
3
|
+
input: unknown;
|
|
4
|
+
output: unknown;
|
|
5
|
+
}
|
|
6
|
+
/** Maps input to output. This is the default Mapping */
|
|
7
|
+
export interface Identity extends IMapping {
|
|
8
|
+
output: this['input'];
|
|
9
|
+
}
|
|
10
|
+
/** Maps the output as the given parameter T */
|
|
11
|
+
export interface As<T> extends IMapping {
|
|
12
|
+
output: T;
|
|
13
|
+
}
|
|
14
|
+
/** Base type Parser implemented by all other parsers */
|
|
15
|
+
export interface IParser<Mapping extends IMapping = Identity> {
|
|
16
|
+
type: string;
|
|
17
|
+
mapping: Mapping;
|
|
18
|
+
}
|
|
19
|
+
/** Creates a Tuple Parser */
|
|
20
|
+
export interface Tuple<Parsers extends IParser[] = [], Mapping extends IMapping = Identity> extends IParser<Mapping> {
|
|
21
|
+
type: 'Tuple';
|
|
22
|
+
parsers: [...Parsers];
|
|
23
|
+
}
|
|
24
|
+
/** Creates a Union Parser */
|
|
25
|
+
export interface Union<Parsers extends IParser[] = [], Mapping extends IMapping = Identity> extends IParser<Mapping> {
|
|
26
|
+
type: 'Union';
|
|
27
|
+
parsers: [...Parsers];
|
|
28
|
+
}
|
|
29
|
+
/** Creates a Const Parser */
|
|
30
|
+
export interface Const<Value extends string = string, Mapping extends IMapping = Identity> extends IParser<Mapping> {
|
|
31
|
+
type: 'Const';
|
|
32
|
+
value: Value;
|
|
33
|
+
}
|
|
34
|
+
/** Creates a String Parser. Options are an array of permissable quote characters */
|
|
35
|
+
export interface String<Options extends string[], Mapping extends IMapping = Identity> extends IParser<Mapping> {
|
|
36
|
+
type: 'String';
|
|
37
|
+
quote: Options;
|
|
38
|
+
}
|
|
39
|
+
/** Creates an Ident Parser. */
|
|
40
|
+
export interface Ident<Mapping extends IMapping = Identity> extends IParser<Mapping> {
|
|
41
|
+
type: 'Ident';
|
|
42
|
+
}
|
|
43
|
+
/** Creates a Number Parser. */
|
|
44
|
+
export interface Number<Mapping extends IMapping = Identity> extends IParser<Mapping> {
|
|
45
|
+
type: 'Number';
|
|
46
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Runtime } from './parsebox/index';
|
|
2
|
+
import * as Types from '../type/index';
|
|
3
|
+
export declare const Module: Runtime.Module<{
|
|
4
|
+
Literal: Runtime.IUnion<Types.TLiteral<string> | Types.TLiteral<number> | Types.TLiteral<boolean>>;
|
|
5
|
+
Keyword: Runtime.IUnion<Types.TAny | Types.TNever | Types.TString | Types.TBoolean | Types.TNumber | Types.TInteger | Types.TBigInt | Types.TNull | Types.TSymbol | Types.TUndefined | Types.TUnknown | Types.TVoid>;
|
|
6
|
+
KeyOf: Runtime.IUnion<boolean>;
|
|
7
|
+
IndexArray: Runtime.IUnion<unknown[]>;
|
|
8
|
+
Extends: Runtime.IUnion<unknown[]>;
|
|
9
|
+
Base: Runtime.IUnion<unknown>;
|
|
10
|
+
Factor: Runtime.ITuple<Types.TSchema>;
|
|
11
|
+
ExprTermTail: Runtime.IUnion<[] | ["&", unknown, unknown]>;
|
|
12
|
+
ExprTerm: Runtime.ITuple<Types.TSchema>;
|
|
13
|
+
ExprTail: Runtime.IUnion<[] | ["|", unknown, unknown]>;
|
|
14
|
+
Expr: Runtime.ITuple<Types.TSchema>;
|
|
15
|
+
Type: Runtime.IRef<unknown>;
|
|
16
|
+
PropertyKey: Runtime.IUnion<string>;
|
|
17
|
+
PropertyReadonly: Runtime.IUnion<boolean>;
|
|
18
|
+
PropertyOptional: Runtime.IUnion<boolean>;
|
|
19
|
+
Property: Runtime.ITuple<{
|
|
20
|
+
[x: string]: Types.TSchema;
|
|
21
|
+
}>;
|
|
22
|
+
PropertyDelimiter: Runtime.IUnion<[","] | [",", "\n"] | [";"] | [";", "\n"] | ["\n"]>;
|
|
23
|
+
Properties: Runtime.IUnion<unknown[]>;
|
|
24
|
+
Object: Runtime.ITuple<Types.TObject<Record<string, Types.TSchema>>>;
|
|
25
|
+
Elements: Runtime.IUnion<unknown[]>;
|
|
26
|
+
Tuple: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
|
|
27
|
+
Parameter: Runtime.ITuple<Types.TSchema>;
|
|
28
|
+
Function: Runtime.ITuple<Types.TFunction<Types.TSchema[], Types.TSchema>>;
|
|
29
|
+
Parameters: Runtime.IUnion<unknown[]>;
|
|
30
|
+
Constructor: Runtime.ITuple<Types.TConstructor<Types.TSchema[], Types.TSchema>>;
|
|
31
|
+
Mapped: Runtime.ITuple<Types.TLiteral<"Mapped types not supported">>;
|
|
32
|
+
AsyncIterator: Runtime.ITuple<Types.TAsyncIterator<Types.TSchema>>;
|
|
33
|
+
Iterator: Runtime.ITuple<Types.TIterator<Types.TSchema>>;
|
|
34
|
+
Awaited: Runtime.ITuple<Types.TSchema>;
|
|
35
|
+
Array: Runtime.ITuple<Types.TArray<Types.TSchema>>;
|
|
36
|
+
Record: Runtime.ITuple<Types.TNever>;
|
|
37
|
+
Promise: Runtime.ITuple<Types.TPromise<Types.TSchema>>;
|
|
38
|
+
ConstructorParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
|
|
39
|
+
FunctionParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
|
|
40
|
+
InstanceType: Runtime.ITuple<Types.TSchema>;
|
|
41
|
+
ReturnType: Runtime.ITuple<Types.TSchema>;
|
|
42
|
+
Partial: Runtime.ITuple<Types.TObject<{}>>;
|
|
43
|
+
Required: Runtime.ITuple<Types.TObject<{}>>;
|
|
44
|
+
Pick: Runtime.ITuple<Types.TObject<{}>>;
|
|
45
|
+
Omit: Runtime.ITuple<Types.TObject<{}>>;
|
|
46
|
+
Exclude: Runtime.ITuple<Types.TNever>;
|
|
47
|
+
Extract: Runtime.ITuple<Types.TSchema>;
|
|
48
|
+
Uppercase: Runtime.ITuple<Types.TSchema>;
|
|
49
|
+
Lowercase: Runtime.ITuple<Types.TSchema>;
|
|
50
|
+
Capitalize: Runtime.ITuple<Types.TSchema>;
|
|
51
|
+
Uncapitalize: Runtime.ITuple<Types.TSchema>;
|
|
52
|
+
Date: Runtime.IConst<Types.TDate>;
|
|
53
|
+
Uint8Array: Runtime.IConst<Types.TUint8Array>;
|
|
54
|
+
Reference: Runtime.IIdent<Types.TSchema>;
|
|
55
|
+
}>;
|