stringent 0.0.2 → 0.0.4
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/README.md +61 -73
- package/dist/context.d.ts +20 -2
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +1 -0
- package/dist/context.js.map +1 -0
- package/dist/createParser.d.ts +109 -26
- package/dist/createParser.d.ts.map +1 -0
- package/dist/createParser.js +80 -19
- package/dist/createParser.js.map +1 -0
- package/dist/errors.d.ts +121 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +186 -0
- package/dist/errors.js.map +1 -0
- package/dist/grammar/index.d.ts +19 -14
- package/dist/grammar/index.d.ts.map +1 -0
- package/dist/grammar/index.js +4 -3
- package/dist/grammar/index.js.map +1 -0
- package/dist/index.d.ts +19 -11
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -7
- package/dist/index.js.map +1 -0
- package/dist/parse/index.d.ts +101 -27
- package/dist/parse/index.d.ts.map +1 -0
- package/dist/parse/index.js +1 -0
- package/dist/parse/index.js.map +1 -0
- package/dist/performance.bench.d.ts +10 -0
- package/dist/performance.bench.d.ts.map +1 -0
- package/dist/performance.bench.js +379 -0
- package/dist/performance.bench.js.map +1 -0
- package/dist/primitive/index.d.ts +27 -35
- package/dist/primitive/index.d.ts.map +1 -0
- package/dist/primitive/index.js +22 -17
- package/dist/primitive/index.js.map +1 -0
- package/dist/runtime/eval.d.ts +157 -0
- package/dist/runtime/eval.d.ts.map +1 -0
- package/dist/runtime/eval.js +206 -0
- package/dist/runtime/eval.js.map +1 -0
- package/dist/runtime/infer.d.ts +2 -1
- package/dist/runtime/infer.d.ts.map +1 -0
- package/dist/runtime/infer.js +3 -2
- package/dist/runtime/infer.js.map +1 -0
- package/dist/runtime/parser.d.ts +92 -11
- package/dist/runtime/parser.d.ts.map +1 -0
- package/dist/runtime/parser.js +522 -47
- package/dist/runtime/parser.js.map +1 -0
- package/dist/schema/index.d.ts +230 -27
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +54 -28
- package/dist/schema/index.js.map +1 -0
- package/dist/static/infer.d.ts +4 -3
- package/dist/static/infer.d.ts.map +1 -0
- package/dist/static/infer.js +1 -0
- package/dist/static/infer.js.map +1 -0
- package/package.json +35 -4
- package/dist/combinators/index.d.ts +0 -57
- package/dist/combinators/index.js +0 -104
- package/dist/static/parser.d.ts +0 -7
- package/dist/static/parser.js +0 -6
package/package.json
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stringent",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "A smart and type-safe expression parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"parser",
|
|
7
7
|
"expression",
|
|
8
|
-
"typescript"
|
|
8
|
+
"typescript",
|
|
9
|
+
"type-safe",
|
|
10
|
+
"compile-time",
|
|
11
|
+
"type-level",
|
|
12
|
+
"expression-parser",
|
|
13
|
+
"dsl",
|
|
14
|
+
"ast",
|
|
15
|
+
"grammar",
|
|
16
|
+
"validation",
|
|
17
|
+
"inference"
|
|
9
18
|
],
|
|
10
19
|
"homepage": "https://github.com/formeddable/stringent#readme",
|
|
11
20
|
"bugs": {
|
|
@@ -18,6 +27,9 @@
|
|
|
18
27
|
"license": "MIT",
|
|
19
28
|
"author": "Essam Almansouri",
|
|
20
29
|
"type": "module",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18.0.0"
|
|
32
|
+
},
|
|
21
33
|
"files": [
|
|
22
34
|
"dist"
|
|
23
35
|
],
|
|
@@ -29,10 +41,20 @@
|
|
|
29
41
|
"types": "./dist/index.d.ts"
|
|
30
42
|
}
|
|
31
43
|
},
|
|
44
|
+
"packageManager": "pnpm@10.28.1",
|
|
32
45
|
"scripts": {
|
|
33
46
|
"build": "tsc -p tsconfig.build.json",
|
|
34
47
|
"typecheck": "tsc --noEmit",
|
|
35
|
-
"
|
|
48
|
+
"lint": "eslint src/",
|
|
49
|
+
"lint:fix": "eslint src/ --fix",
|
|
50
|
+
"format": "prettier --write \"src/**/*.ts\" \"examples/**/*.ts\"",
|
|
51
|
+
"format:check": "prettier --check \"src/**/*.ts\" \"examples/**/*.ts\"",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"test:watch": "vitest",
|
|
54
|
+
"test:coverage": "vitest run --coverage",
|
|
55
|
+
"bench": "vitest bench",
|
|
56
|
+
"docs": "typedoc",
|
|
57
|
+
"docs:watch": "typedoc --watch",
|
|
36
58
|
"prepublishOnly": "pnpm build"
|
|
37
59
|
},
|
|
38
60
|
"dependencies": {
|
|
@@ -40,9 +62,18 @@
|
|
|
40
62
|
"arktype": "^2.1.29"
|
|
41
63
|
},
|
|
42
64
|
"devDependencies": {
|
|
65
|
+
"@eslint/js": "^9.39.2",
|
|
43
66
|
"@types/node": "^22.10.5",
|
|
67
|
+
"@vitest/coverage-v8": "^4.0.17",
|
|
68
|
+
"eslint": "^9.39.2",
|
|
69
|
+
"eslint-config-prettier": "^10.1.8",
|
|
70
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
44
71
|
"hotscript": "^1.0.13",
|
|
72
|
+
"prettier": "^3.8.0",
|
|
45
73
|
"tsx": "^4.21.0",
|
|
46
|
-
"
|
|
74
|
+
"typedoc": "^0.28.16",
|
|
75
|
+
"typescript": "^5.7.2",
|
|
76
|
+
"typescript-eslint": "^8.53.0",
|
|
77
|
+
"vitest": "^4.0.17"
|
|
47
78
|
}
|
|
48
79
|
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parser Combinators
|
|
3
|
-
*
|
|
4
|
-
* Composable parsers that work at both runtime and compile-time.
|
|
5
|
-
* Parse methods are generic - return types computed from input literals.
|
|
6
|
-
* All combinators thread context ($) through to child parsers.
|
|
7
|
-
*
|
|
8
|
-
* IMPORTANT: All parse methods MUST be generic in context:
|
|
9
|
-
* parse<TInput extends string, $ extends Context>(input: TInput, $: $)
|
|
10
|
-
*/
|
|
11
|
-
import type { Context } from "../context.js";
|
|
12
|
-
import type { IParser, ParseNumber, ParseString, ParseIdent, ParseConst, _Number, _String, _Ident, _Const } from "../primitive/index.js";
|
|
13
|
-
/** Static type for parsing any parser */
|
|
14
|
-
export type Parse<P, TInput extends string, $ extends Context> = P extends _Number ? ParseNumber<TInput> : P extends _String<infer Q> ? ParseString<Q, TInput> : P extends _Const<infer V> ? ParseConst<V, TInput> : P extends _Ident ? ParseIdent<TInput, $> : P extends _Union<infer Parsers> ? ParseUnion<Parsers, TInput, $> : P extends _Tuple<infer Parsers> ? ParseTuple<Parsers, TInput, $> : P extends _Optional<infer Parser> ? ParseOptional<Parser, TInput, $> : P extends _Many<infer Parser> ? ParseMany<Parser, TInput, $> : never;
|
|
15
|
-
/** Static type for Union parsing */
|
|
16
|
-
export type ParseUnion<TParsers extends IParser[], TInput extends string, $ extends Context> = TParsers extends [
|
|
17
|
-
infer First extends IParser,
|
|
18
|
-
...infer Rest extends IParser[]
|
|
19
|
-
] ? Parse<First, TInput, $> extends [infer R, infer Remaining extends string] ? [R, Remaining] : ParseUnion<Rest, TInput, $> : [];
|
|
20
|
-
/** Static type for Tuple parsing */
|
|
21
|
-
export type ParseTuple<TParsers extends IParser[], TInput extends string, $ extends Context, TAcc extends unknown[] = []> = TParsers extends [
|
|
22
|
-
infer First extends IParser,
|
|
23
|
-
...infer Rest extends IParser[]
|
|
24
|
-
] ? Parse<First, TInput, $> extends [infer R, infer Remaining extends string] ? ParseTuple<Rest, Remaining, $, [...TAcc, R]> : [] : [TAcc, TInput];
|
|
25
|
-
/** Static type for Optional parsing */
|
|
26
|
-
export type ParseOptional<TParser extends IParser, TInput extends string, $ extends Context> = Parse<TParser, TInput, $> extends [infer R, infer Remaining extends string] ? [R, Remaining] : [undefined, TInput];
|
|
27
|
-
/** Static type for Many parsing */
|
|
28
|
-
export type ParseMany<TParser extends IParser, TInput extends string, $ extends Context, TAcc extends unknown[] = []> = Parse<TParser, TInput, $> extends [infer R, infer Remaining extends string] ? Remaining extends TInput ? [TAcc, TInput] : ParseMany<TParser, Remaining, $, [...TAcc, R]> : [TAcc, TInput];
|
|
29
|
-
declare class _Union<TParsers extends IParser[]> {
|
|
30
|
-
readonly __combinator: "union";
|
|
31
|
-
readonly parsers: TParsers;
|
|
32
|
-
constructor(parsers: TParsers);
|
|
33
|
-
parse<TInput extends string, $ extends Context>(input: TInput, $: $): ParseUnion<TParsers, TInput, $>;
|
|
34
|
-
}
|
|
35
|
-
declare class _Tuple<TParsers extends IParser[]> {
|
|
36
|
-
readonly __combinator: "tuple";
|
|
37
|
-
readonly parsers: TParsers;
|
|
38
|
-
constructor(parsers: TParsers);
|
|
39
|
-
parse<TInput extends string, $ extends Context>(input: TInput, $: $): ParseTuple<TParsers, TInput, $>;
|
|
40
|
-
}
|
|
41
|
-
declare class _Optional<TParser extends IParser> {
|
|
42
|
-
readonly __combinator: "optional";
|
|
43
|
-
readonly parser: TParser;
|
|
44
|
-
constructor(parser: TParser);
|
|
45
|
-
parse<TInput extends string, $ extends Context>(input: TInput, $: $): ParseOptional<TParser, TInput, $>;
|
|
46
|
-
}
|
|
47
|
-
declare class _Many<TParser extends IParser> {
|
|
48
|
-
readonly __combinator: "many";
|
|
49
|
-
readonly parser: TParser;
|
|
50
|
-
constructor(parser: TParser);
|
|
51
|
-
parse<TInput extends string, $ extends Context>(input: TInput, $: $): ParseMany<TParser, TInput, $>;
|
|
52
|
-
}
|
|
53
|
-
export declare const Union: <TParsers extends IParser[]>(parsers: [...TParsers]) => _Union<TParsers>;
|
|
54
|
-
export declare const Tuple: <TParsers extends IParser[]>(parsers: [...TParsers]) => _Tuple<TParsers>;
|
|
55
|
-
export declare const Optional: <TParser extends IParser>(parser: TParser) => _Optional<TParser>;
|
|
56
|
-
export declare const Many: <TParser extends IParser>(parser: TParser) => _Many<TParser>;
|
|
57
|
-
export type { _Union, _Tuple, _Optional, _Many };
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parser Combinators
|
|
3
|
-
*
|
|
4
|
-
* Composable parsers that work at both runtime and compile-time.
|
|
5
|
-
* Parse methods are generic - return types computed from input literals.
|
|
6
|
-
* All combinators thread context ($) through to child parsers.
|
|
7
|
-
*
|
|
8
|
-
* IMPORTANT: All parse methods MUST be generic in context:
|
|
9
|
-
* parse<TInput extends string, $ extends Context>(input: TInput, $: $)
|
|
10
|
-
*/
|
|
11
|
-
// =============================================================================
|
|
12
|
-
// Union Combinator
|
|
13
|
-
// =============================================================================
|
|
14
|
-
class _Union {
|
|
15
|
-
__combinator = "union";
|
|
16
|
-
parsers;
|
|
17
|
-
constructor(parsers) {
|
|
18
|
-
this.parsers = parsers;
|
|
19
|
-
}
|
|
20
|
-
parse(input, $) {
|
|
21
|
-
for (const parser of this.parsers) {
|
|
22
|
-
const result = parser.parse(input, $);
|
|
23
|
-
if (result.length === 2) {
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
// =============================================================================
|
|
31
|
-
// Tuple Combinator
|
|
32
|
-
// =============================================================================
|
|
33
|
-
class _Tuple {
|
|
34
|
-
__combinator = "tuple";
|
|
35
|
-
parsers;
|
|
36
|
-
constructor(parsers) {
|
|
37
|
-
this.parsers = parsers;
|
|
38
|
-
}
|
|
39
|
-
parse(input, $) {
|
|
40
|
-
const results = [];
|
|
41
|
-
let remaining = input;
|
|
42
|
-
for (const parser of this.parsers) {
|
|
43
|
-
const result = parser.parse(remaining, $);
|
|
44
|
-
if (result.length !== 2) {
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
|
-
results.push(result[0]);
|
|
48
|
-
remaining = result[1];
|
|
49
|
-
}
|
|
50
|
-
return [results, remaining];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// =============================================================================
|
|
54
|
-
// Optional Combinator
|
|
55
|
-
// =============================================================================
|
|
56
|
-
class _Optional {
|
|
57
|
-
__combinator = "optional";
|
|
58
|
-
parser;
|
|
59
|
-
constructor(parser) {
|
|
60
|
-
this.parser = parser;
|
|
61
|
-
}
|
|
62
|
-
parse(input, $) {
|
|
63
|
-
const result = this.parser.parse(input, $);
|
|
64
|
-
if (result.length === 2) {
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
return [undefined, input];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// =============================================================================
|
|
71
|
-
// Many Combinator
|
|
72
|
-
// =============================================================================
|
|
73
|
-
class _Many {
|
|
74
|
-
__combinator = "many";
|
|
75
|
-
parser;
|
|
76
|
-
constructor(parser) {
|
|
77
|
-
this.parser = parser;
|
|
78
|
-
}
|
|
79
|
-
parse(input, $) {
|
|
80
|
-
const results = [];
|
|
81
|
-
let remaining = input;
|
|
82
|
-
while (true) {
|
|
83
|
-
const result = this.parser.parse(remaining, $);
|
|
84
|
-
if (result.length !== 2) {
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
results.push(result[0]);
|
|
88
|
-
const newRemaining = result[1];
|
|
89
|
-
// Prevent infinite loop on zero-width matches
|
|
90
|
-
if (newRemaining === remaining) {
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
remaining = newRemaining;
|
|
94
|
-
}
|
|
95
|
-
return [results, remaining];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
// =============================================================================
|
|
99
|
-
// Exported Factories
|
|
100
|
-
// =============================================================================
|
|
101
|
-
export const Union = (parsers) => new _Union(parsers);
|
|
102
|
-
export const Tuple = (parsers) => new _Tuple(parsers);
|
|
103
|
-
export const Optional = (parser) => new _Optional(parser);
|
|
104
|
-
export const Many = (parser) => new _Many(parser);
|
package/dist/static/parser.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Static Parser Types
|
|
3
|
-
*
|
|
4
|
-
* Parse<Parser, Input, $> - type-level parsing with context threading
|
|
5
|
-
*/
|
|
6
|
-
export { Parse, ParseUnion, ParseTuple, ParseOptional, ParseMany, } from "../combinators/index.js";
|
|
7
|
-
export type { LiteralNode, NumberNode, StringNode, IdentNode, ConstNode, ASTNode, } from "../primitive/index.js";
|