stringent 0.0.1 → 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 +96 -0
- package/dist/context.d.ts +45 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +14 -0
- package/dist/context.js.map +1 -0
- package/dist/createParser.d.ts +159 -0
- package/dist/createParser.d.ts.map +1 -0
- package/dist/createParser.js +118 -0
- 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 +48 -0
- package/dist/grammar/index.d.ts.map +1 -0
- package/dist/grammar/index.js +13 -0
- package/dist/grammar/index.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/parse/index.d.ts +211 -0
- package/dist/parse/index.d.ts.map +1 -0
- package/dist/parse/index.js +16 -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 +96 -0
- package/dist/primitive/index.d.ts.map +1 -0
- package/dist/primitive/index.js +102 -0
- 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 +27 -0
- package/dist/runtime/infer.d.ts.map +1 -0
- package/dist/runtime/infer.js +35 -0
- package/dist/runtime/infer.js.map +1 -0
- package/dist/runtime/parser.d.ts +115 -0
- package/dist/runtime/parser.d.ts.map +1 -0
- package/dist/runtime/parser.js +746 -0
- package/dist/runtime/parser.js.map +1 -0
- package/dist/schema/index.d.ts +476 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +137 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/static/infer.d.ts +27 -0
- package/dist/static/infer.d.ts.map +1 -0
- package/dist/static/infer.js +10 -0
- package/dist/static/infer.js.map +1 -0
- package/package.json +62 -8
package/dist/errors.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Types and Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides rich error information for parse failures including:
|
|
5
|
+
* - Position tracking (offset, line, column)
|
|
6
|
+
* - Source snippets showing where errors occurred
|
|
7
|
+
* - Descriptive messages for different error types
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Calculate position information from input and current offset.
|
|
11
|
+
*
|
|
12
|
+
* @param input - The original input string
|
|
13
|
+
* @param offset - Character offset into the input
|
|
14
|
+
* @returns Position with line and column numbers
|
|
15
|
+
*/
|
|
16
|
+
export function calculatePosition(input, offset) {
|
|
17
|
+
const textBeforeOffset = input.slice(0, offset);
|
|
18
|
+
const lines = textBeforeOffset.split('\n');
|
|
19
|
+
const line = lines.length;
|
|
20
|
+
const column = lines[lines.length - 1].length + 1;
|
|
21
|
+
return { offset, line, column };
|
|
22
|
+
}
|
|
23
|
+
// =============================================================================
|
|
24
|
+
// Error Creation Utilities
|
|
25
|
+
// =============================================================================
|
|
26
|
+
/**
|
|
27
|
+
* Create a snippet of the input around the error position.
|
|
28
|
+
*
|
|
29
|
+
* @param input - The full input string
|
|
30
|
+
* @param offset - Character offset where error occurred
|
|
31
|
+
* @param contextChars - Number of characters to show around the error
|
|
32
|
+
* @returns A snippet with error position marker
|
|
33
|
+
*/
|
|
34
|
+
export function createSnippet(input, offset, contextChars = 20) {
|
|
35
|
+
if (input.length === 0)
|
|
36
|
+
return '(empty input)';
|
|
37
|
+
const start = Math.max(0, offset - contextChars);
|
|
38
|
+
const end = Math.min(input.length, offset + contextChars);
|
|
39
|
+
let snippet = '';
|
|
40
|
+
// Add ellipsis if we're not at the start
|
|
41
|
+
if (start > 0)
|
|
42
|
+
snippet += '...';
|
|
43
|
+
// Add the snippet content
|
|
44
|
+
snippet += input.slice(start, offset);
|
|
45
|
+
snippet += '→'; // Position marker
|
|
46
|
+
snippet += input.slice(offset, end);
|
|
47
|
+
// Add ellipsis if we're not at the end
|
|
48
|
+
if (end < input.length)
|
|
49
|
+
snippet += '...';
|
|
50
|
+
// Escape control characters for display
|
|
51
|
+
snippet = snippet.replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/\r/g, '\\r');
|
|
52
|
+
return snippet;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a RichParseError.
|
|
56
|
+
*/
|
|
57
|
+
export function createParseError(kind, message, input, offset, context) {
|
|
58
|
+
return {
|
|
59
|
+
__error: true,
|
|
60
|
+
kind,
|
|
61
|
+
message,
|
|
62
|
+
position: calculatePosition(input, offset),
|
|
63
|
+
snippet: createSnippet(input, offset),
|
|
64
|
+
input,
|
|
65
|
+
context,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Create a "no match" error.
|
|
70
|
+
*/
|
|
71
|
+
export function noMatchError(input, offset) {
|
|
72
|
+
const position = calculatePosition(input, offset);
|
|
73
|
+
const remaining = input.slice(offset).trim();
|
|
74
|
+
const preview = remaining.slice(0, 20) + (remaining.length > 20 ? '...' : '');
|
|
75
|
+
let message;
|
|
76
|
+
if (input.trim().length === 0) {
|
|
77
|
+
message = 'Empty or whitespace-only input';
|
|
78
|
+
}
|
|
79
|
+
else if (offset >= input.length) {
|
|
80
|
+
message = 'Unexpected end of input';
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
message = `No grammar rule matched at position ${position.line}:${position.column}: "${preview}"`;
|
|
84
|
+
}
|
|
85
|
+
return createParseError('no_match', message, input, offset);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create a "type mismatch" error.
|
|
89
|
+
*/
|
|
90
|
+
export function typeMismatchError(input, offset, expected, actual, parsing) {
|
|
91
|
+
const position = calculatePosition(input, offset);
|
|
92
|
+
let message = `Type mismatch at ${position.line}:${position.column}: expected '${expected}', got '${actual}'`;
|
|
93
|
+
if (parsing) {
|
|
94
|
+
message += ` while parsing ${parsing}`;
|
|
95
|
+
}
|
|
96
|
+
return createParseError('type_mismatch', message, input, offset, {
|
|
97
|
+
expected,
|
|
98
|
+
actual,
|
|
99
|
+
parsing,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create an "unterminated string" error.
|
|
104
|
+
*/
|
|
105
|
+
export function unterminatedStringError(input, offset, quote) {
|
|
106
|
+
const position = calculatePosition(input, offset);
|
|
107
|
+
const message = `Unterminated string literal at ${position.line}:${position.column}: missing closing ${quote}`;
|
|
108
|
+
return createParseError('unterminated_string', message, input, offset, {
|
|
109
|
+
parsing: 'string literal',
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Create an "unclosed parenthesis" error.
|
|
114
|
+
*/
|
|
115
|
+
export function unclosedParenError(input, offset) {
|
|
116
|
+
const position = calculatePosition(input, offset);
|
|
117
|
+
const message = `Unclosed parenthesis at ${position.line}:${position.column}: missing ')'`;
|
|
118
|
+
return createParseError('unclosed_paren', message, input, offset, {
|
|
119
|
+
parsing: 'parenthesized expression',
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Create an "unexpected token" error.
|
|
124
|
+
*/
|
|
125
|
+
export function unexpectedTokenError(input, offset, found, expected) {
|
|
126
|
+
const position = calculatePosition(input, offset);
|
|
127
|
+
let message = `Unexpected token at ${position.line}:${position.column}: found '${found}'`;
|
|
128
|
+
if (expected) {
|
|
129
|
+
message += `, expected ${expected}`;
|
|
130
|
+
}
|
|
131
|
+
return createParseError('unexpected_token', message, input, offset, {
|
|
132
|
+
expected,
|
|
133
|
+
parsing: 'expression',
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Create an "empty input" error.
|
|
138
|
+
*/
|
|
139
|
+
export function emptyInputError(input) {
|
|
140
|
+
return createParseError('empty_input', 'Cannot parse empty or whitespace-only input', input, 0);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Check if a result includes errors.
|
|
144
|
+
*/
|
|
145
|
+
export function hasErrors(result) {
|
|
146
|
+
return result.length === 3 && result[2].length > 0;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get errors from a result, or empty array if none.
|
|
150
|
+
*/
|
|
151
|
+
export function getErrors(result) {
|
|
152
|
+
if (result.length === 3) {
|
|
153
|
+
return result[2];
|
|
154
|
+
}
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
// =============================================================================
|
|
158
|
+
// Error Formatting
|
|
159
|
+
// =============================================================================
|
|
160
|
+
/**
|
|
161
|
+
* Format an error for display with source context.
|
|
162
|
+
*/
|
|
163
|
+
export function formatError(error) {
|
|
164
|
+
const { position, message, snippet } = error;
|
|
165
|
+
const lines = [];
|
|
166
|
+
lines.push(`Error at line ${position.line}, column ${position.column}:`);
|
|
167
|
+
lines.push(` ${message}`);
|
|
168
|
+
lines.push('');
|
|
169
|
+
lines.push(` ${snippet}`);
|
|
170
|
+
if (error.context) {
|
|
171
|
+
const ctx = error.context;
|
|
172
|
+
if (ctx.expected && ctx.actual) {
|
|
173
|
+
lines.push('');
|
|
174
|
+
lines.push(` Expected: ${ctx.expected}`);
|
|
175
|
+
lines.push(` Actual: ${ctx.actual}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return lines.join('\n');
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Format multiple errors for display.
|
|
182
|
+
*/
|
|
183
|
+
export function formatErrors(errors) {
|
|
184
|
+
return errors.map(formatError).join('\n\n');
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|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gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAqB;IAC/C,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC7C,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,CAAC,IAAI,CAAC,iBAAiB,QAAQ,CAAC,IAAI,YAAY,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IACzE,KAAK,CAAC,IAAI,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC;IAC3B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC;IAE3B,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC;QAC1B,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;YAC/B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACf,KAAK,CAAC,IAAI,CAAC,eAAe,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC1C,KAAK,CAAC,IAAI,CAAC,eAAe,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAAwB;IACnD,OAAO,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grammar Type Computation
|
|
3
|
+
*
|
|
4
|
+
* Computes a grammar TYPE from operator schemas. The grammar is a flat tuple
|
|
5
|
+
* of precedence levels, sorted from lowest to highest precedence, with
|
|
6
|
+
* built-in atoms as the final element.
|
|
7
|
+
*
|
|
8
|
+
* Example:
|
|
9
|
+
* [[AddOps], [MulOps], [BuiltInAtoms]]
|
|
10
|
+
* // level 0 (lowest prec) → level 1 → atoms (last)
|
|
11
|
+
*/
|
|
12
|
+
import type { Pipe, Numbers, Objects, Tuples, Fn, Unions, Call } from 'hotscript';
|
|
13
|
+
import type { NodeSchema } from '../schema/index.js';
|
|
14
|
+
import type { BUILT_IN_ATOMS } from '../runtime/parser.js';
|
|
15
|
+
/**
|
|
16
|
+
* A grammar is a tuple of levels, where each level is an array of node schemas.
|
|
17
|
+
* Sorted by precedence (lowest first), built-in atoms last.
|
|
18
|
+
*/
|
|
19
|
+
export type Grammar = readonly (readonly NodeSchema[])[];
|
|
20
|
+
/** Built-in atoms type - derived from the runtime definitions */
|
|
21
|
+
export type BuiltInAtoms = typeof BUILT_IN_ATOMS;
|
|
22
|
+
/**
|
|
23
|
+
* Compare precedence entries: numbers sort ascending.
|
|
24
|
+
* Entry format: [precedence, nodes[]]
|
|
25
|
+
*/
|
|
26
|
+
interface SortByPrecedence extends Fn {
|
|
27
|
+
return: Call<Numbers.LessThanOrEqual, this['arg0'][0], this['arg1'][0]>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Compute the grammar tuple from operator schemas.
|
|
31
|
+
*
|
|
32
|
+
* 1. Group operators by precedence
|
|
33
|
+
* 2. Convert to entries and sort (numbers ascending)
|
|
34
|
+
* 3. Extract just the node arrays
|
|
35
|
+
* 4. Append built-in atoms as the last level
|
|
36
|
+
*/
|
|
37
|
+
type ComputeOperatorLevels<TNodes extends readonly NodeSchema[]> = Pipe<[
|
|
38
|
+
...TNodes
|
|
39
|
+
], [
|
|
40
|
+
Tuples.GroupBy<Objects.Get<'precedence'>>,
|
|
41
|
+
Objects.Entries,
|
|
42
|
+
Unions.ToTuple,
|
|
43
|
+
Tuples.Sort<SortByPrecedence>,
|
|
44
|
+
Tuples.Map<Tuples.At<1>>
|
|
45
|
+
]>;
|
|
46
|
+
export type ComputeGrammar<TNodes extends readonly NodeSchema[]> = ComputeOperatorLevels<TNodes> extends infer Levels extends readonly (readonly NodeSchema[])[] ? readonly [...Levels, BuiltInAtoms] : never;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/grammar/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC,SAAS,UAAU,EAAE,CAAC,EAAE,CAAC;AAMzD,iEAAiE;AACjE,MAAM,MAAM,YAAY,GAAG,OAAO,cAAc,CAAC;AAMjD;;;GAGG;AACH,UAAU,gBAAiB,SAAQ,EAAE;IACnC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACzE;AAMD;;;;;;;GAOG;AACH,KAAK,qBAAqB,CAAC,MAAM,SAAS,SAAS,UAAU,EAAE,IAAI,IAAI,CACrE;IAAC,GAAG,MAAM;CAAC,EACX;IACE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACzC,OAAO,CAAC,OAAO;IACf,MAAM,CAAC,OAAO;IACd,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC;IAC7B,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CACzB,CACF,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,SAAS,UAAU,EAAE,IAC7D,qBAAqB,CAAC,MAAM,CAAC,SAAS,MAAM,MAAM,SAAS,SAAS,CAAC,SAAS,UAAU,EAAE,CAAC,EAAE,GACzF,SAAS,CAAC,GAAG,MAAM,EAAE,YAAY,CAAC,GAClC,KAAK,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grammar Type Computation
|
|
3
|
+
*
|
|
4
|
+
* Computes a grammar TYPE from operator schemas. The grammar is a flat tuple
|
|
5
|
+
* of precedence levels, sorted from lowest to highest precedence, with
|
|
6
|
+
* built-in atoms as the final element.
|
|
7
|
+
*
|
|
8
|
+
* Example:
|
|
9
|
+
* [[AddOps], [MulOps], [BuiltInAtoms]]
|
|
10
|
+
* // level 0 (lowest prec) → level 1 → atoms (last)
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/grammar/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stringent - Type-safe Expression Parser
|
|
3
|
+
*
|
|
4
|
+
* Main entry points:
|
|
5
|
+
* - defineNode: Create grammar node schemas
|
|
6
|
+
* - createParser: Build a type-safe parser from nodes
|
|
7
|
+
* - Parse<Grammar, Input, Context>: Type-level parsing
|
|
8
|
+
*/
|
|
9
|
+
export { defineNode, number, string, ident, constVal, lhs, rhs, expr, nullLiteral, booleanLiteral, undefinedLiteral, } from './schema/index.js';
|
|
10
|
+
export type { NodeSchema, PatternSchema, NumberSchema, StringSchema, IdentSchema, ConstSchema, NullSchema, BooleanSchema, UndefinedSchema, ExprSchema, ExprRole, Precedence, ConfigureFn, EvalFn, SchemaToType, InferBindings, InferEvaluatedBindings, UnionResultType, ResultTypeSpec, } from './schema/index.js';
|
|
11
|
+
export { createParser } from './createParser.js';
|
|
12
|
+
export type { Parser, Evaluator, ParseResult, SchemaRecordToData } from './createParser.js';
|
|
13
|
+
export type { Parse, BinaryNode, ParseError, TypeMismatchError, NoMatchError, } from './parse/index.js';
|
|
14
|
+
export type { ComputeGrammar, Grammar } from './grammar/index.js';
|
|
15
|
+
export type { Context, EmptyContext } from './context.js';
|
|
16
|
+
export { emptyContext } from './context.js';
|
|
17
|
+
export type { ASTNode, LiteralNode, NumberNode, StringNode, IdentNode, ConstNode, NullNode, BooleanNode, UndefinedNode, } from './primitive/index.js';
|
|
18
|
+
export { processEscapeSequences, parseWithErrors, formatParseError } from './runtime/parser.js';
|
|
19
|
+
export type { RichParseError, ParseResultWithErrors, ParseWithErrorsResult, } from './runtime/parser.js';
|
|
20
|
+
export { calculatePosition, createSnippet, createParseError, noMatchError, typeMismatchError, unterminatedStringError, unclosedParenError, unexpectedTokenError, emptyInputError, hasErrors, getErrors, formatError, formatErrors, } from './errors.js';
|
|
21
|
+
export type { SourcePosition, ParseErrorKind, ErrorContext } from './errors.js';
|
|
22
|
+
export { evaluate, createEvaluator } from './runtime/eval.js';
|
|
23
|
+
export type { EvalContext } from './runtime/eval.js';
|
|
24
|
+
export { infer } from './runtime/infer.js';
|
|
25
|
+
export type { InferredType } from './runtime/infer.js';
|
|
26
|
+
export type { Infer } from './static/infer.js';
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EACL,UAAU,EACV,MAAM,EACN,MAAM,EACN,KAAK,EACL,QAAQ,EACR,GAAG,EACH,GAAG,EACH,IAAI,EAC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AE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMhF,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC9D,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMrD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stringent - Type-safe Expression Parser
|
|
3
|
+
*
|
|
4
|
+
* Main entry points:
|
|
5
|
+
* - defineNode: Create grammar node schemas
|
|
6
|
+
* - createParser: Build a type-safe parser from nodes
|
|
7
|
+
* - Parse<Grammar, Input, Context>: Type-level parsing
|
|
8
|
+
*/
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// Main API: defineNode & createParser
|
|
11
|
+
// =============================================================================
|
|
12
|
+
export { defineNode, number, string, ident, constVal, lhs, rhs, expr, nullLiteral, booleanLiteral, undefinedLiteral, } from './schema/index.js';
|
|
13
|
+
export { createParser } from './createParser.js';
|
|
14
|
+
export { emptyContext } from './context.js';
|
|
15
|
+
// =============================================================================
|
|
16
|
+
// Runtime Utilities
|
|
17
|
+
// =============================================================================
|
|
18
|
+
export { processEscapeSequences, parseWithErrors, formatParseError } from './runtime/parser.js';
|
|
19
|
+
// =============================================================================
|
|
20
|
+
// Error Types and Utilities
|
|
21
|
+
// =============================================================================
|
|
22
|
+
export { calculatePosition, createSnippet, createParseError, noMatchError, typeMismatchError, unterminatedStringError, unclosedParenError, unexpectedTokenError, emptyInputError, hasErrors, getErrors, formatError, formatErrors, } from './errors.js';
|
|
23
|
+
// =============================================================================
|
|
24
|
+
// Runtime Evaluation
|
|
25
|
+
// =============================================================================
|
|
26
|
+
export { evaluate, createEvaluator } from './runtime/eval.js';
|
|
27
|
+
// =============================================================================
|
|
28
|
+
// Inference
|
|
29
|
+
// =============================================================================
|
|
30
|
+
export { infer } from './runtime/infer.js';
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,gFAAgF;AAChF,sCAAsC;AACtC,gFAAgF;AAEhF,OAAO,EACL,UAAU,EACV,MAAM,EACN,MAAM,EACN,KAAK,EACL,QAAQ,EACR,GAAG,EACH,GAAG,EACH,IAAI,EACJ,WAAW,EACX,cAAc,EACd,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAuB3B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAgBjD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAkB5C,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAOhG,gFAAgF;AAChF,4BAA4B;AAC5B,gFAAgF;AAEhF,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,SAAS,EACT,SAAS,EACT,WAAW,EACX,YAAY,GACb,MAAM,aAAa,CAAC;AAGrB,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAG9D,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse Type - Type-Level Parsing with Grammar Support
|
|
3
|
+
*
|
|
4
|
+
* Parse<Grammar, Input, Context> computes the exact result type of parsing
|
|
5
|
+
* an input string against a grammar.
|
|
6
|
+
*
|
|
7
|
+
* The grammar is a flat tuple of precedence levels:
|
|
8
|
+
* [[Level0Ops], [Level1Ops], ..., [Atoms]]
|
|
9
|
+
*
|
|
10
|
+
* Parsing proceeds:
|
|
11
|
+
* 1. Try operators at current level (index 0, lowest precedence)
|
|
12
|
+
* 2. Fall back to next level (index 1, higher precedence)
|
|
13
|
+
* 3. Continue until atoms (last element)
|
|
14
|
+
*/
|
|
15
|
+
import type { Token } from '@sinclair/parsebox';
|
|
16
|
+
import type { Context } from '../context.js';
|
|
17
|
+
import type { Grammar } from '../grammar/index.js';
|
|
18
|
+
import type { NodeSchema, PatternSchema, PatternSchemaBase, NamedSchema, NumberSchema, StringSchema, IdentSchema, ConstSchema, NullSchema, BooleanSchema, UndefinedSchema, UnionResultType } from '../schema/index.js';
|
|
19
|
+
import type { NumberNode, StringNode, IdentNode, ConstNode, NullNode, BooleanNode, UndefinedNode } from '../primitive/index.js';
|
|
20
|
+
/** Base parse error */
|
|
21
|
+
export interface ParseError<TMessage extends string = string> {
|
|
22
|
+
readonly __error: true;
|
|
23
|
+
readonly message: TMessage;
|
|
24
|
+
}
|
|
25
|
+
/** Type mismatch error (expression has wrong type) */
|
|
26
|
+
export type TypeMismatchError<TExpected extends string, TActual extends string> = ParseError<`Type mismatch: expected ${TExpected}, got ${TActual}`>;
|
|
27
|
+
/** No match error (no grammar rule matched) */
|
|
28
|
+
export type NoMatchError = ParseError<'No grammar rule matched'>;
|
|
29
|
+
/** Binary operator node */
|
|
30
|
+
export interface BinaryNode<TName extends string = string, TLeft = unknown, TRight = unknown, TOutputSchema extends string = string> {
|
|
31
|
+
readonly node: TName;
|
|
32
|
+
readonly outputSchema: TOutputSchema;
|
|
33
|
+
readonly left: TLeft;
|
|
34
|
+
readonly right: TRight;
|
|
35
|
+
}
|
|
36
|
+
type ParseNumberPrimitive<TInput extends string> = Token.TNumber<TInput> extends [infer V extends string, infer R extends string] ? [NumberNode<V>, R] : [];
|
|
37
|
+
type ParseStringPrimitive<TQuotes extends readonly string[], TInput extends string> = Token.TString<[...TQuotes], TInput> extends [infer V extends string, infer R extends string] ? [StringNode<V>, R] : [];
|
|
38
|
+
type ParseIdentPrimitive<TInput extends string, TContext extends Context> = Token.TIdent<TInput> extends [infer V extends string, infer R extends string] ? V extends keyof TContext['data'] ? [IdentNode<V, TContext['data'][V] & string>, R] : [IdentNode<V, 'unknown'>, R] : [];
|
|
39
|
+
type ParseConstPrimitive<TValue extends string, TInput extends string> = Token.TConst<TValue, TInput> extends [infer _V extends string, infer R extends string] ? [ConstNode<TValue>, R] : [];
|
|
40
|
+
/**
|
|
41
|
+
* Parse null literal - matches "null" keyword followed by non-identifier char.
|
|
42
|
+
*/
|
|
43
|
+
type ParseNullPrimitive<TInput extends string> = Token.TConst<'null', TInput> extends [string, infer R extends string] ? R extends `${infer C}${string}` ? C extends 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '_' | '$' ? [] : [NullNode, R] : [NullNode, R] : [];
|
|
44
|
+
/**
|
|
45
|
+
* Parse boolean literal - matches "true" or "false" keywords followed by non-identifier char.
|
|
46
|
+
*/
|
|
47
|
+
type ParseBooleanPrimitive<TInput extends string> = Token.TConst<'true', TInput> extends [string, infer R extends string] ? R extends `${infer C}${string}` ? C extends 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '_' | '$' ? ParseBooleanFalse<TInput> : [BooleanNode<'true'>, R] : [BooleanNode<'true'>, R] : ParseBooleanFalse<TInput>;
|
|
48
|
+
type ParseBooleanFalse<TInput extends string> = Token.TConst<'false', TInput> extends [string, infer R extends string] ? R extends `${infer C}${string}` ? C extends 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '_' | '$' ? [] : [BooleanNode<'false'>, R] : [BooleanNode<'false'>, R] : [];
|
|
49
|
+
/**
|
|
50
|
+
* Parse undefined literal - matches "undefined" keyword followed by non-identifier char.
|
|
51
|
+
*/
|
|
52
|
+
type ParseUndefinedPrimitive<TInput extends string> = Token.TConst<'undefined', TInput> extends [string, infer R extends string] ? R extends `${infer C}${string}` ? C extends 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '_' | '$' ? [] : [UndefinedNode, R] : [UndefinedNode, R] : [];
|
|
53
|
+
/**
|
|
54
|
+
* Parse a single pattern element (non-Expr).
|
|
55
|
+
* Works with both plain schemas and NamedSchema (intersection type).
|
|
56
|
+
*/
|
|
57
|
+
type ParseElement<TElement extends PatternSchema, TInput extends string, TContext extends Context> = TElement extends NumberSchema ? ParseNumberPrimitive<TInput> : TElement extends StringSchema<infer Q> ? ParseStringPrimitive<Q, TInput> : TElement extends IdentSchema ? ParseIdentPrimitive<TInput, TContext> : TElement extends ConstSchema<infer V> ? ParseConstPrimitive<V, TInput> : TElement extends NullSchema ? ParseNullPrimitive<TInput> : TElement extends BooleanSchema ? ParseBooleanPrimitive<TInput> : TElement extends UndefinedSchema ? ParseUndefinedPrimitive<TInput> : never;
|
|
58
|
+
/**
|
|
59
|
+
* Parse a tuple of pattern elements.
|
|
60
|
+
*
|
|
61
|
+
* TCurrentLevels - grammar from current level onward (for rhs)
|
|
62
|
+
* TNextLevels - grammar from next level onward (for lhs, avoids left-recursion)
|
|
63
|
+
* TFullGrammar - complete grammar (for expr role, full reset)
|
|
64
|
+
*/
|
|
65
|
+
type ParsePatternTuple<TPattern extends readonly PatternSchema[], TInput extends string, TContext extends Context, TCurrentLevels extends Grammar, TNextLevels extends Grammar, TFullGrammar extends Grammar, TAcc extends unknown[] = []> = TPattern extends readonly [
|
|
66
|
+
infer First extends PatternSchema,
|
|
67
|
+
...infer Rest extends readonly PatternSchema[]
|
|
68
|
+
] ? ParseElementWithLevel<First, TInput, TContext, TCurrentLevels, TNextLevels, TFullGrammar> extends [infer R, infer Remaining extends string] ? ParsePatternTuple<Rest, Remaining, TContext, TCurrentLevels, TNextLevels, TFullGrammar, [
|
|
69
|
+
...TAcc,
|
|
70
|
+
R
|
|
71
|
+
]> : [] : [TAcc, TInput];
|
|
72
|
+
/**
|
|
73
|
+
* Extract constraint from an ExprSchema by accessing the property directly.
|
|
74
|
+
* The constraint property is optional, so we exclude undefined from the result.
|
|
75
|
+
* Returns the constraint string type, or undefined if not constrained.
|
|
76
|
+
*/
|
|
77
|
+
type ExtractConstraint<T> = T extends {
|
|
78
|
+
constraint: infer C extends string;
|
|
79
|
+
} ? C : undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Parse an expression element based on its role.
|
|
82
|
+
* Works with both plain schemas and NamedSchema (intersection type).
|
|
83
|
+
*
|
|
84
|
+
* Role determines which grammar slice is used:
|
|
85
|
+
* - "lhs": TNextLevels (avoids left-recursion)
|
|
86
|
+
* - "rhs": TCurrentLevels (maintains precedence, enables right-associativity)
|
|
87
|
+
* - "expr": TFullGrammar (full reset for delimited contexts)
|
|
88
|
+
*
|
|
89
|
+
* Uses structural matching on `kind: "expr"` and `role` property to handle
|
|
90
|
+
* both plain ExprSchema and NamedSchema<ExprSchema, ...> intersection types.
|
|
91
|
+
*/
|
|
92
|
+
type ParseElementWithLevel<TElement extends PatternSchema, TInput extends string, TContext extends Context, TCurrentLevels extends Grammar, TNextLevels extends Grammar, TFullGrammar extends Grammar> = TElement extends {
|
|
93
|
+
kind: 'expr';
|
|
94
|
+
role: infer Role;
|
|
95
|
+
} ? Role extends 'lhs' ? ParseExprWithConstraint<TNextLevels, TInput, TContext, ExtractConstraint<TElement>, TFullGrammar> : Role extends 'rhs' ? ParseExprWithConstraint<TCurrentLevels, TInput, TContext, ExtractConstraint<TElement>, TFullGrammar> : ParseExprWithConstraint<TFullGrammar, TInput, TContext, ExtractConstraint<TElement>, TFullGrammar> : ParseElement<TElement, TInput, TContext>;
|
|
96
|
+
/**
|
|
97
|
+
* Parse a node's pattern and build the result node.
|
|
98
|
+
*/
|
|
99
|
+
type ParseNodePattern<TNode extends NodeSchema, TInput extends string, TContext extends Context, TCurrentLevels extends Grammar, TNextLevels extends Grammar, TFullGrammar extends Grammar> = ParsePatternTuple<TNode['pattern'], TInput, TContext, TCurrentLevels, TNextLevels, TFullGrammar> extends [infer Children extends unknown[], infer Rest extends string] ? [BuildNodeResult<TNode, Children>, Rest] : [];
|
|
100
|
+
/**
|
|
101
|
+
* Extract bindings from pattern and children (recursive zip).
|
|
102
|
+
* Only includes children where the pattern element is a NamedSchema.
|
|
103
|
+
*/
|
|
104
|
+
type ExtractBindings<TPattern extends readonly PatternSchema[], TChildren extends unknown[], TAcc extends {} = {}> = TPattern extends readonly [
|
|
105
|
+
infer First extends PatternSchema,
|
|
106
|
+
...infer RestPattern extends readonly PatternSchema[]
|
|
107
|
+
] ? TChildren extends [infer Child, ...infer RestChildren] ? First extends NamedSchema<PatternSchemaBase, infer Name> ? ExtractBindings<RestPattern, RestChildren, {
|
|
108
|
+
[P in keyof TAcc | Name]: P extends Name ? Child : P extends keyof TAcc ? TAcc[P] : never;
|
|
109
|
+
}> : ExtractBindings<RestPattern, RestChildren, TAcc> : TAcc : TAcc;
|
|
110
|
+
/**
|
|
111
|
+
* Helper: Check if type has exactly one key.
|
|
112
|
+
*/
|
|
113
|
+
type HasExactlyOneKey<T> = keyof T extends infer K ? K extends unknown ? [K] extends [keyof T] ? keyof T extends K ? true : false : false : false : false;
|
|
114
|
+
/**
|
|
115
|
+
* Helper: Get the single key from a type with exactly one key.
|
|
116
|
+
*/
|
|
117
|
+
type SingleKey<T> = keyof T extends infer K ? K extends keyof T ? keyof T extends K ? K : never : never : never;
|
|
118
|
+
/**
|
|
119
|
+
* Helper: Extract outputSchema from the single binding.
|
|
120
|
+
* If there's exactly one binding and it has an outputSchema, return it.
|
|
121
|
+
* Otherwise return 'unknown'.
|
|
122
|
+
*/
|
|
123
|
+
type SingleBindingOutputSchema<Bindings> = HasExactlyOneKey<Bindings> extends true ? SingleKey<Bindings> extends infer K ? K extends keyof Bindings ? Bindings[K] extends {
|
|
124
|
+
outputSchema: infer S;
|
|
125
|
+
} ? S : 'unknown' : 'unknown' : 'unknown' : 'unknown';
|
|
126
|
+
/**
|
|
127
|
+
* Helper: Extract outputSchema from a binding by name.
|
|
128
|
+
* Returns the outputSchema if the binding exists and has one, otherwise 'unknown'.
|
|
129
|
+
*/
|
|
130
|
+
type BindingOutputSchema<Bindings, TName extends string> = TName extends keyof Bindings ? Bindings[TName] extends {
|
|
131
|
+
outputSchema: infer S;
|
|
132
|
+
} ? S : 'unknown' : 'unknown';
|
|
133
|
+
/**
|
|
134
|
+
* Helper: Compute the union outputSchema string from multiple bindings.
|
|
135
|
+
* Given a tuple of binding names, extracts each binding's outputSchema and
|
|
136
|
+
* constructs a union string like "type1 | type2".
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* // Bindings = { then: { outputSchema: 'boolean' }, else: { outputSchema: 'number' } }
|
|
140
|
+
* // Names = ['then', 'else']
|
|
141
|
+
* // Result = 'boolean | number'
|
|
142
|
+
*/
|
|
143
|
+
type ComputeUnionOutputSchema<Bindings, TNames extends readonly string[], TAcc extends string = never> = TNames extends readonly [infer First extends string, ...infer Rest extends readonly string[]] ? BindingOutputSchema<Bindings, First> extends infer S extends string ? ComputeUnionOutputSchema<Bindings, Rest, TAcc | S> : ComputeUnionOutputSchema<Bindings, Rest, TAcc> : [TAcc] extends [never] ? 'unknown' : TAcc;
|
|
144
|
+
/**
|
|
145
|
+
* Helper: Compute the effective outputSchema.
|
|
146
|
+
* - If resultType is a UnionResultType, compute the union from the specified bindings
|
|
147
|
+
* - If resultType is 'unknown' and there's exactly one binding with an outputSchema,
|
|
148
|
+
* propagate that binding's outputSchema (matches runtime behavior).
|
|
149
|
+
* - Otherwise use the static resultType.
|
|
150
|
+
*/
|
|
151
|
+
type ComputeOutputSchema<TResultType, Bindings> = TResultType extends UnionResultType<infer TNames extends readonly string[]> ? ComputeUnionOutputSchema<Bindings, TNames> : TResultType extends 'unknown' ? SingleBindingOutputSchema<Bindings> extends infer S ? S extends 'unknown' ? 'unknown' : S : 'unknown' : TResultType;
|
|
152
|
+
/**
|
|
153
|
+
* Build the result node from parsed children.
|
|
154
|
+
*
|
|
155
|
+
* Uses named bindings from .as() to determine node fields.
|
|
156
|
+
* - Single unnamed child: passthrough (atom behavior)
|
|
157
|
+
* - Otherwise: bindings become node fields
|
|
158
|
+
*
|
|
159
|
+
* For nodes with resultType 'unknown' and exactly one binding,
|
|
160
|
+
* the outputSchema is propagated from the binding (matches runtime).
|
|
161
|
+
*/
|
|
162
|
+
type BuildNodeResult<TNode extends NodeSchema, TChildren extends unknown[]> = ExtractBindings<TNode['pattern'], TChildren> extends infer Bindings ? keyof Bindings extends never ? TChildren extends [infer Only] ? Only : never : {
|
|
163
|
+
readonly node: TNode['name'];
|
|
164
|
+
readonly outputSchema: ComputeOutputSchema<TNode['resultType'], Bindings>;
|
|
165
|
+
} & Bindings : never;
|
|
166
|
+
/**
|
|
167
|
+
* Parse an expression with optional type constraint.
|
|
168
|
+
*/
|
|
169
|
+
type ParseExprWithConstraint<TStartLevels extends Grammar, TInput extends string, TContext extends Context, TConstraint extends string | undefined, TFullGrammar extends Grammar> = ParseLevels<TStartLevels, TInput, TContext, TFullGrammar> extends [
|
|
170
|
+
infer Node extends {
|
|
171
|
+
outputSchema: string;
|
|
172
|
+
},
|
|
173
|
+
infer Rest extends string
|
|
174
|
+
] ? TConstraint extends string ? Node['outputSchema'] extends TConstraint ? [Node, Rest] : [] : [Node, Rest] : [];
|
|
175
|
+
/**
|
|
176
|
+
* Try parsing each node in a level.
|
|
177
|
+
*/
|
|
178
|
+
type ParseNodes<TNodes extends readonly NodeSchema[], TInput extends string, TContext extends Context, TCurrentLevels extends Grammar, TNextLevels extends Grammar, TFullGrammar extends Grammar> = TNodes extends readonly [
|
|
179
|
+
infer First extends NodeSchema,
|
|
180
|
+
...infer Rest extends readonly NodeSchema[]
|
|
181
|
+
] ? ParseNodePattern<First, TInput, TContext, TCurrentLevels, TNextLevels, TFullGrammar> extends [
|
|
182
|
+
infer R,
|
|
183
|
+
infer Remaining extends string
|
|
184
|
+
] ? [R, Remaining] : ParseNodes<Rest, TInput, TContext, TCurrentLevels, TNextLevels, TFullGrammar> : [];
|
|
185
|
+
/**
|
|
186
|
+
* Parse using grammar levels (flat tuple).
|
|
187
|
+
*
|
|
188
|
+
* TLevels is the remaining levels to try, starting from current.
|
|
189
|
+
* - Try nodes at first level (TLevels[0])
|
|
190
|
+
* - If no match, fall back to rest of levels
|
|
191
|
+
* - Base case: single level (atoms) - just try those nodes
|
|
192
|
+
*/
|
|
193
|
+
type ParseLevels<TLevels extends Grammar, TInput extends string, TContext extends Context, TFullGrammar extends Grammar> = TLevels extends readonly [
|
|
194
|
+
infer CurrentNodes extends readonly NodeSchema[],
|
|
195
|
+
...infer NextNodes extends Grammar
|
|
196
|
+
] ? ParseNodes<CurrentNodes, TInput, TContext, TLevels, NextNodes, TFullGrammar> extends [
|
|
197
|
+
infer R,
|
|
198
|
+
infer Remaining extends string
|
|
199
|
+
] ? [R, Remaining] : ParseLevels<NextNodes, TInput, TContext, TFullGrammar> : TLevels extends readonly [infer LastNodes extends readonly NodeSchema[]] ? ParseNodes<LastNodes, TInput, TContext, TLevels, TLevels, TFullGrammar> : [];
|
|
200
|
+
/**
|
|
201
|
+
* Parse<Grammar, Input, Context>
|
|
202
|
+
*
|
|
203
|
+
* Main entry point for type-level parsing.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* type Result = Parse<MyGrammar, "1+2", Context>;
|
|
207
|
+
* // [BinaryNode<"add", NumberNode<"1">, NumberNode<"2">, "number">, ""]
|
|
208
|
+
*/
|
|
209
|
+
export type Parse<TGrammar extends Grammar, TInput extends string, TContext extends Context> = ParseLevels<TGrammar, TInput, TContext, TGrammar>;
|
|
210
|
+
export {};
|
|
211
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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O,SAAS,SAAS;IAC3B,MAAM,YAAY,SAAS,SAAS,UAAU,EAAE;IAChD,GAAG,MAAM,SAAS,SAAS,OAAO;CACnC,GAEG,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,CAAC,SAAS;IACnF,MAAM,CAAC;IACP,MAAM,SAAS,SAAS,MAAM;CAC/B,GACC,CAAC,CAAC,EAAE,SAAS,CAAC,GACd,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,CAAC,GACxD,OAAO,SAAS,SAAS,CAAC,MAAM,SAAS,SAAS,SAAS,UAAU,EAAE,CAAC,GAEtE,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,GACvE,EAAE,CAAC;AAMT;;;;;;;;GAQG;AACH,MAAM,MAAM,KAAK,CACf,QAAQ,SAAS,OAAO,EACxB,MAAM,SAAS,MAAM,EACrB,QAAQ,SAAS,OAAO,IACtB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse Type - Type-Level Parsing with Grammar Support
|
|
3
|
+
*
|
|
4
|
+
* Parse<Grammar, Input, Context> computes the exact result type of parsing
|
|
5
|
+
* an input string against a grammar.
|
|
6
|
+
*
|
|
7
|
+
* The grammar is a flat tuple of precedence levels:
|
|
8
|
+
* [[Level0Ops], [Level1Ops], ..., [Atoms]]
|
|
9
|
+
*
|
|
10
|
+
* Parsing proceeds:
|
|
11
|
+
* 1. Try operators at current level (index 0, lowest precedence)
|
|
12
|
+
* 2. Fall back to next level (index 1, higher precedence)
|
|
13
|
+
* 3. Continue until atoms (last element)
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/parse/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performance Benchmarks for Stringent Parser
|
|
3
|
+
*
|
|
4
|
+
* This file contains benchmarks to measure and document the performance
|
|
5
|
+
* characteristics of the runtime parser.
|
|
6
|
+
*
|
|
7
|
+
* Run with: pnpm bench
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=performance.bench.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performance.bench.d.ts","sourceRoot":"","sources":["../src/performance.bench.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|