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.
Files changed (58) hide show
  1. package/README.md +61 -73
  2. package/dist/context.d.ts +20 -2
  3. package/dist/context.d.ts.map +1 -0
  4. package/dist/context.js +1 -0
  5. package/dist/context.js.map +1 -0
  6. package/dist/createParser.d.ts +109 -26
  7. package/dist/createParser.d.ts.map +1 -0
  8. package/dist/createParser.js +80 -19
  9. package/dist/createParser.js.map +1 -0
  10. package/dist/errors.d.ts +121 -0
  11. package/dist/errors.d.ts.map +1 -0
  12. package/dist/errors.js +186 -0
  13. package/dist/errors.js.map +1 -0
  14. package/dist/grammar/index.d.ts +19 -14
  15. package/dist/grammar/index.d.ts.map +1 -0
  16. package/dist/grammar/index.js +4 -3
  17. package/dist/grammar/index.js.map +1 -0
  18. package/dist/index.d.ts +19 -11
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +16 -7
  21. package/dist/index.js.map +1 -0
  22. package/dist/parse/index.d.ts +101 -27
  23. package/dist/parse/index.d.ts.map +1 -0
  24. package/dist/parse/index.js +1 -0
  25. package/dist/parse/index.js.map +1 -0
  26. package/dist/performance.bench.d.ts +10 -0
  27. package/dist/performance.bench.d.ts.map +1 -0
  28. package/dist/performance.bench.js +379 -0
  29. package/dist/performance.bench.js.map +1 -0
  30. package/dist/primitive/index.d.ts +27 -35
  31. package/dist/primitive/index.d.ts.map +1 -0
  32. package/dist/primitive/index.js +22 -17
  33. package/dist/primitive/index.js.map +1 -0
  34. package/dist/runtime/eval.d.ts +157 -0
  35. package/dist/runtime/eval.d.ts.map +1 -0
  36. package/dist/runtime/eval.js +206 -0
  37. package/dist/runtime/eval.js.map +1 -0
  38. package/dist/runtime/infer.d.ts +2 -1
  39. package/dist/runtime/infer.d.ts.map +1 -0
  40. package/dist/runtime/infer.js +3 -2
  41. package/dist/runtime/infer.js.map +1 -0
  42. package/dist/runtime/parser.d.ts +92 -11
  43. package/dist/runtime/parser.d.ts.map +1 -0
  44. package/dist/runtime/parser.js +522 -47
  45. package/dist/runtime/parser.js.map +1 -0
  46. package/dist/schema/index.d.ts +230 -27
  47. package/dist/schema/index.d.ts.map +1 -0
  48. package/dist/schema/index.js +54 -28
  49. package/dist/schema/index.js.map +1 -0
  50. package/dist/static/infer.d.ts +4 -3
  51. package/dist/static/infer.d.ts.map +1 -0
  52. package/dist/static/infer.js +1 -0
  53. package/dist/static/infer.js.map +1 -0
  54. package/package.json +35 -4
  55. package/dist/combinators/index.d.ts +0 -57
  56. package/dist/combinators/index.js +0 -104
  57. package/dist/static/parser.d.ts +0 -7
  58. package/dist/static/parser.js +0 -6
@@ -12,11 +12,11 @@
12
12
  * 2. Fall back to next level (index 1, higher precedence)
13
13
  * 3. Continue until atoms (last element)
14
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, ExprSchema } from "../schema/index.js";
19
- import type { NumberNode, StringNode, IdentNode, ConstNode } from "../primitive/index.js";
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
20
  /** Base parse error */
21
21
  export interface ParseError<TMessage extends string = string> {
22
22
  readonly __error: true;
@@ -25,7 +25,7 @@ export interface ParseError<TMessage extends string = string> {
25
25
  /** Type mismatch error (expression has wrong type) */
26
26
  export type TypeMismatchError<TExpected extends string, TActual extends string> = ParseError<`Type mismatch: expected ${TExpected}, got ${TActual}`>;
27
27
  /** No match error (no grammar rule matched) */
28
- export type NoMatchError = ParseError<"No grammar rule matched">;
28
+ export type NoMatchError = ParseError<'No grammar rule matched'>;
29
29
  /** Binary operator node */
30
30
  export interface BinaryNode<TName extends string = string, TLeft = unknown, TRight = unknown, TOutputSchema extends string = string> {
31
31
  readonly node: TName;
@@ -34,23 +34,27 @@ export interface BinaryNode<TName extends string = string, TLeft = unknown, TRig
34
34
  readonly right: TRight;
35
35
  }
36
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 [
38
- infer V extends string,
39
- infer R extends string
40
- ] ? [StringNode<V>, R] : [];
41
- type ParseIdentPrimitive<TInput extends string, TContext extends Context> = Token.TIdent<TInput> extends [
42
- infer V extends string,
43
- infer R extends string
44
- ] ? V extends keyof TContext["data"] ? [IdentNode<V, TContext["data"][V] & string>, R] : [IdentNode<V, "unknown">, R] : [];
45
- type ParseConstPrimitive<TValue extends string, TInput extends string> = Token.TConst<TValue, TInput> extends [
46
- infer _V extends string,
47
- infer R extends string
48
- ] ? [ConstNode<TValue>, 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] : [];
49
53
  /**
50
54
  * Parse a single pattern element (non-Expr).
51
55
  * Works with both plain schemas and NamedSchema (intersection type).
52
56
  */
53
- 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> : never;
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;
54
58
  /**
55
59
  * Parse a tuple of pattern elements.
56
60
  *
@@ -65,6 +69,14 @@ type ParsePatternTuple<TPattern extends readonly PatternSchema[], TInput extends
65
69
  ...TAcc,
66
70
  R
67
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;
68
80
  /**
69
81
  * Parse an expression element based on its role.
70
82
  * Works with both plain schemas and NamedSchema (intersection type).
@@ -73,28 +85,83 @@ type ParsePatternTuple<TPattern extends readonly PatternSchema[], TInput extends
73
85
  * - "lhs": TNextLevels (avoids left-recursion)
74
86
  * - "rhs": TCurrentLevels (maintains precedence, enables right-associativity)
75
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.
76
91
  */
77
- type ParseElementWithLevel<TElement extends PatternSchema, TInput extends string, TContext extends Context, TCurrentLevels extends Grammar, TNextLevels extends Grammar, TFullGrammar extends Grammar> = TElement extends ExprSchema<infer C, infer Role> ? Role extends "lhs" ? ParseExprWithConstraint<TNextLevels, TInput, TContext, C, TFullGrammar> : Role extends "rhs" ? ParseExprWithConstraint<TCurrentLevels, TInput, TContext, C, TFullGrammar> : ParseExprWithConstraint<TFullGrammar, TInput, TContext, C, TFullGrammar> : ParseElement<TElement, TInput, TContext>;
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>;
78
96
  /**
79
97
  * Parse a node's pattern and build the result node.
80
98
  */
81
- 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] : [];
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
+ */
82
104
  type ExtractBindings<TPattern extends readonly PatternSchema[], TChildren extends unknown[], TAcc extends {} = {}> = TPattern extends readonly [
83
105
  infer First extends PatternSchema,
84
106
  ...infer RestPattern extends readonly PatternSchema[]
85
107
  ] ? TChildren extends [infer Child, ...infer RestChildren] ? First extends NamedSchema<PatternSchemaBase, infer Name> ? ExtractBindings<RestPattern, RestChildren, {
86
108
  [P in keyof TAcc | Name]: P extends Name ? Child : P extends keyof TAcc ? TAcc[P] : never;
87
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;
88
152
  /**
89
153
  * Build the result node from parsed children.
90
154
  *
91
155
  * Uses named bindings from .as() to determine node fields.
92
156
  * - Single unnamed child: passthrough (atom behavior)
93
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).
94
161
  */
95
- 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 : {
96
- readonly node: TNode["name"];
97
- readonly outputSchema: TNode["resultType"];
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>;
98
165
  } & Bindings : never;
99
166
  /**
100
167
  * Parse an expression with optional type constraint.
@@ -104,14 +171,17 @@ type ParseExprWithConstraint<TStartLevels extends Grammar, TInput extends string
104
171
  outputSchema: string;
105
172
  },
106
173
  infer Rest extends string
107
- ] ? TConstraint extends string ? Node["outputSchema"] extends TConstraint ? [Node, Rest] : [] : [Node, Rest] : [];
174
+ ] ? TConstraint extends string ? Node['outputSchema'] extends TConstraint ? [Node, Rest] : [] : [Node, Rest] : [];
108
175
  /**
109
176
  * Try parsing each node in a level.
110
177
  */
111
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 [
112
179
  infer First extends NodeSchema,
113
180
  ...infer Rest extends readonly NodeSchema[]
114
- ] ? ParseNodePattern<First, TInput, TContext, TCurrentLevels, TNextLevels, TFullGrammar> extends [infer R, infer Remaining extends string] ? [R, Remaining] : ParseNodes<Rest, TInput, TContext, TCurrentLevels, TNextLevels, TFullGrammar> : [];
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> : [];
115
185
  /**
116
186
  * Parse using grammar levels (flat tuple).
117
187
  *
@@ -123,7 +193,10 @@ type ParseNodes<TNodes extends readonly NodeSchema[], TInput extends string, TCo
123
193
  type ParseLevels<TLevels extends Grammar, TInput extends string, TContext extends Context, TFullGrammar extends Grammar> = TLevels extends readonly [
124
194
  infer CurrentNodes extends readonly NodeSchema[],
125
195
  ...infer NextNodes extends Grammar
126
- ] ? ParseNodes<CurrentNodes, TInput, TContext, TLevels, NextNodes, TFullGrammar> extends [infer R, infer Remaining extends string] ? [R, Remaining] : ParseLevels<NextNodes, TInput, TContext, TFullGrammar> : TLevels extends readonly [infer LastNodes extends readonly NodeSchema[]] ? ParseNodes<LastNodes, TInput, TContext, TLevels, TLevels, TFullGrammar> : [];
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> : [];
127
200
  /**
128
201
  * Parse<Grammar, Input, Context>
129
202
  *
@@ -135,3 +208,4 @@ type ParseLevels<TLevels extends Grammar, TInput extends string, TContext extend
135
208
  */
136
209
  export type Parse<TGrammar extends Grammar, TInput extends string, TContext extends Context> = ParseLevels<TGrammar, TInput, TContext, TGrammar>;
137
210
  export {};
211
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parse/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,aAAa,EACb,eAAe,EACf,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,QAAQ,EACR,WAAW,EACX,aAAa,EACd,MAAM,uBAAuB,CAAC;AAM/B,uBAAuB;AACvB,MAAM,WAAW,UAAU,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM;IAC1D,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;CAC5B;AAED,sDAAsD;AACtD,MAAM,MAAM,iBAAiB,CAC3B,SAAS,SAAS,MAAM,EACxB,OAAO,SAAS,MAAM,IACpB,UAAU,CAAC,2BAA2B,SAAS,SAAS,OAAO,EAAE,CAAC,CAAC;AAEvE,+CAA+C;AAC/C,MAAM,MAAM,YAAY,GAAG,UAAU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;CAC/B,GACC,CAAC,CAAC,EAAE,SAAS,CAAC,GACd,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,CAAC,GAC/E,EAAE,CAAC;AAEP;;;;;;;GAOG;AACH,KAAK,WAAW,CACd,OAAO,SAAS,OAAO,EACvB,MAAM,SAAS,MAAM,EACrB,QAAQ,SAAS,OAAO,EACxB,YAAY,SAAS,OAAO,IAC1B,OAAO,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"}
@@ -13,3 +13,4 @@
13
13
  * 3. Continue until atoms (last element)
14
14
  */
15
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"}
@@ -0,0 +1,379 @@
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
+ import { bench, describe } from 'vitest';
10
+ import { createParser, defineNode, constVal, lhs, rhs, expr } from './index.js';
11
+ // =============================================================================
12
+ // Test Grammar Setup
13
+ // =============================================================================
14
+ // Basic arithmetic grammar
15
+ const add = defineNode({
16
+ name: 'add',
17
+ pattern: [lhs('number').as('left'), constVal('+'), rhs('number').as('right')],
18
+ precedence: 1,
19
+ resultType: 'number',
20
+ });
21
+ const mul = defineNode({
22
+ name: 'mul',
23
+ pattern: [lhs('number').as('left'), constVal('*'), rhs('number').as('right')],
24
+ precedence: 2,
25
+ resultType: 'number',
26
+ });
27
+ const pow = defineNode({
28
+ name: 'pow',
29
+ pattern: [lhs('number').as('left'), constVal('**'), rhs('number').as('right')],
30
+ precedence: 3,
31
+ resultType: 'number',
32
+ });
33
+ const sub = defineNode({
34
+ name: 'sub',
35
+ pattern: [lhs('number').as('left'), constVal('-'), rhs('number').as('right')],
36
+ precedence: 1,
37
+ resultType: 'number',
38
+ });
39
+ const div = defineNode({
40
+ name: 'div',
41
+ pattern: [lhs('number').as('left'), constVal('/'), rhs('number').as('right')],
42
+ precedence: 2,
43
+ resultType: 'number',
44
+ });
45
+ // Comparison operators
46
+ const eq = defineNode({
47
+ name: 'eq',
48
+ pattern: [lhs().as('left'), constVal('=='), rhs().as('right')],
49
+ precedence: 0,
50
+ resultType: 'boolean',
51
+ });
52
+ // String operations
53
+ const concat = defineNode({
54
+ name: 'concat',
55
+ pattern: [lhs('string').as('left'), constVal('++'), rhs('string').as('right')],
56
+ precedence: 1,
57
+ resultType: 'string',
58
+ });
59
+ // Ternary
60
+ const ternary = defineNode({
61
+ name: 'ternary',
62
+ pattern: [
63
+ lhs('boolean').as('condition'),
64
+ constVal('?'),
65
+ expr().as('then'),
66
+ constVal(':'),
67
+ rhs().as('else'),
68
+ ],
69
+ precedence: 0,
70
+ resultType: 'unknown',
71
+ });
72
+ // Create parsers
73
+ const arithmeticParser = createParser([add, sub, mul, div, pow]);
74
+ const fullParser = createParser([add, sub, mul, div, pow, eq, concat, ternary]);
75
+ // =============================================================================
76
+ // Test Data Generation
77
+ // =============================================================================
78
+ /** Generate a simple number literal */
79
+ function simpleNumber() {
80
+ return String(Math.floor(Math.random() * 1000));
81
+ }
82
+ /** Generate a chained addition expression */
83
+ function chainedAddition(count) {
84
+ return Array.from({ length: count }, () => simpleNumber()).join(' + ');
85
+ }
86
+ /** Generate a chained multiplication expression */
87
+ function chainedMultiplication(count) {
88
+ return Array.from({ length: count }, () => simpleNumber()).join(' * ');
89
+ }
90
+ /** Generate a mixed precedence expression */
91
+ function mixedPrecedence(count) {
92
+ const ops = ['+', '-', '*', '/', '**'];
93
+ let expr = simpleNumber();
94
+ for (let i = 0; i < count - 1; i++) {
95
+ const op = ops[i % ops.length];
96
+ expr += ` ${op} ${simpleNumber()}`;
97
+ }
98
+ return expr;
99
+ }
100
+ /** Generate nested parentheses */
101
+ function nestedParens(depth) {
102
+ let expr = simpleNumber();
103
+ for (let i = 0; i < depth; i++) {
104
+ expr = `(${expr})`;
105
+ }
106
+ return expr;
107
+ }
108
+ /** Generate expression with nested parentheses and operations */
109
+ function nestedParensWithOps(depth) {
110
+ let expr = simpleNumber();
111
+ for (let i = 0; i < depth; i++) {
112
+ expr = `(${expr} + ${simpleNumber()})`;
113
+ }
114
+ return expr;
115
+ }
116
+ // =============================================================================
117
+ // Benchmarks: Simple Literals
118
+ // =============================================================================
119
+ describe('Simple Literals', () => {
120
+ bench('number literal', () => {
121
+ arithmeticParser.parse('42', {});
122
+ });
123
+ bench('decimal number', () => {
124
+ arithmeticParser.parse('3.14159', {});
125
+ });
126
+ bench('large number', () => {
127
+ arithmeticParser.parse('9007199254740991', {});
128
+ });
129
+ bench('string literal (double quotes)', () => {
130
+ fullParser.parse('"hello world"', {});
131
+ });
132
+ bench('string literal (single quotes)', () => {
133
+ fullParser.parse("'hello world'", {});
134
+ });
135
+ bench('identifier', () => {
136
+ arithmeticParser.parse('variableName', { variableName: 'number' });
137
+ });
138
+ });
139
+ // =============================================================================
140
+ // Benchmarks: Binary Operations
141
+ // =============================================================================
142
+ describe('Binary Operations', () => {
143
+ bench('simple addition: 1 + 2', () => {
144
+ arithmeticParser.parse('1 + 2', {});
145
+ });
146
+ bench('simple multiplication: 3 * 4', () => {
147
+ arithmeticParser.parse('3 * 4', {});
148
+ });
149
+ bench('simple exponentiation: 2 ** 8', () => {
150
+ arithmeticParser.parse('2 ** 8', {});
151
+ });
152
+ bench('mixed precedence: 1 + 2 * 3', () => {
153
+ arithmeticParser.parse('1 + 2 * 3', {});
154
+ });
155
+ bench('mixed precedence: 2 * 3 + 4 * 5', () => {
156
+ arithmeticParser.parse('2 * 3 + 4 * 5', {});
157
+ });
158
+ bench('three precedence levels: 1 + 2 * 3 ** 4', () => {
159
+ arithmeticParser.parse('1 + 2 * 3 ** 4', {});
160
+ });
161
+ });
162
+ // =============================================================================
163
+ // Benchmarks: Chained Operations
164
+ // =============================================================================
165
+ describe('Chained Operations', () => {
166
+ const chain5 = chainedAddition(5);
167
+ const chain10 = chainedAddition(10);
168
+ const chain20 = chainedAddition(20);
169
+ const chain50 = chainedAddition(50);
170
+ bench('5-element addition chain', () => {
171
+ arithmeticParser.parse(chain5, {});
172
+ });
173
+ bench('10-element addition chain', () => {
174
+ arithmeticParser.parse(chain10, {});
175
+ });
176
+ bench('20-element addition chain', () => {
177
+ arithmeticParser.parse(chain20, {});
178
+ });
179
+ bench('50-element addition chain', () => {
180
+ arithmeticParser.parse(chain50, {});
181
+ });
182
+ const mulChain10 = chainedMultiplication(10);
183
+ const mulChain20 = chainedMultiplication(20);
184
+ bench('10-element multiplication chain', () => {
185
+ arithmeticParser.parse(mulChain10, {});
186
+ });
187
+ bench('20-element multiplication chain', () => {
188
+ arithmeticParser.parse(mulChain20, {});
189
+ });
190
+ const mixed10 = mixedPrecedence(10);
191
+ const mixed20 = mixedPrecedence(20);
192
+ bench('10-element mixed precedence', () => {
193
+ arithmeticParser.parse(mixed10, {});
194
+ });
195
+ bench('20-element mixed precedence', () => {
196
+ arithmeticParser.parse(mixed20, {});
197
+ });
198
+ });
199
+ // =============================================================================
200
+ // Benchmarks: Nested Parentheses
201
+ // =============================================================================
202
+ describe('Nested Parentheses', () => {
203
+ const parens5 = nestedParens(5);
204
+ const parens10 = nestedParens(10);
205
+ const parens20 = nestedParens(20);
206
+ bench('5 levels of nesting', () => {
207
+ arithmeticParser.parse(parens5, {});
208
+ });
209
+ bench('10 levels of nesting', () => {
210
+ arithmeticParser.parse(parens10, {});
211
+ });
212
+ bench('20 levels of nesting', () => {
213
+ arithmeticParser.parse(parens20, {});
214
+ });
215
+ const parensOps5 = nestedParensWithOps(5);
216
+ const parensOps10 = nestedParensWithOps(10);
217
+ const parensOps20 = nestedParensWithOps(20);
218
+ bench('5 levels with operations', () => {
219
+ arithmeticParser.parse(parensOps5, {});
220
+ });
221
+ bench('10 levels with operations', () => {
222
+ arithmeticParser.parse(parensOps10, {});
223
+ });
224
+ bench('20 levels with operations', () => {
225
+ arithmeticParser.parse(parensOps20, {});
226
+ });
227
+ });
228
+ // =============================================================================
229
+ // Benchmarks: Complex Expressions
230
+ // =============================================================================
231
+ describe('Complex Expressions', () => {
232
+ bench('precedence override: (1 + 2) * 3', () => {
233
+ arithmeticParser.parse('(1 + 2) * 3', {});
234
+ });
235
+ bench('nested groups: ((1 + 2) * 3) + 4', () => {
236
+ arithmeticParser.parse('((1 + 2) * 3) + 4', {});
237
+ });
238
+ bench('complex: (1 + 2) * (3 + 4)', () => {
239
+ arithmeticParser.parse('(1 + 2) * (3 + 4)', {});
240
+ });
241
+ bench('very complex: ((1 + 2) * 3 + 4) ** 2 / (5 - 6)', () => {
242
+ arithmeticParser.parse('((1 + 2) * 3 + 4) ** 2 / (5 - 6)', {});
243
+ });
244
+ });
245
+ // =============================================================================
246
+ // Benchmarks: Parser Creation
247
+ // =============================================================================
248
+ describe('Parser Creation', () => {
249
+ bench('create simple parser (1 node)', () => {
250
+ createParser([add]);
251
+ });
252
+ bench('create medium parser (5 nodes)', () => {
253
+ createParser([add, sub, mul, div, pow]);
254
+ });
255
+ bench('create full parser (8 nodes)', () => {
256
+ createParser([add, sub, mul, div, pow, eq, concat, ternary]);
257
+ });
258
+ });
259
+ // =============================================================================
260
+ // Benchmarks: Grammar Complexity
261
+ // =============================================================================
262
+ describe('Grammar Complexity', () => {
263
+ // Create parsers with varying numbers of operators at the same precedence
264
+ const samePrec2 = createParser([
265
+ defineNode({
266
+ name: 'op1',
267
+ pattern: [lhs('number').as('l'), constVal('|1|'), rhs('number').as('r')],
268
+ precedence: 1,
269
+ resultType: 'number',
270
+ }),
271
+ defineNode({
272
+ name: 'op2',
273
+ pattern: [lhs('number').as('l'), constVal('|2|'), rhs('number').as('r')],
274
+ precedence: 1,
275
+ resultType: 'number',
276
+ }),
277
+ ]);
278
+ const samePrec5 = createParser([
279
+ defineNode({
280
+ name: 'op1',
281
+ pattern: [lhs('number').as('l'), constVal('|1|'), rhs('number').as('r')],
282
+ precedence: 1,
283
+ resultType: 'number',
284
+ }),
285
+ defineNode({
286
+ name: 'op2',
287
+ pattern: [lhs('number').as('l'), constVal('|2|'), rhs('number').as('r')],
288
+ precedence: 1,
289
+ resultType: 'number',
290
+ }),
291
+ defineNode({
292
+ name: 'op3',
293
+ pattern: [lhs('number').as('l'), constVal('|3|'), rhs('number').as('r')],
294
+ precedence: 1,
295
+ resultType: 'number',
296
+ }),
297
+ defineNode({
298
+ name: 'op4',
299
+ pattern: [lhs('number').as('l'), constVal('|4|'), rhs('number').as('r')],
300
+ precedence: 1,
301
+ resultType: 'number',
302
+ }),
303
+ defineNode({
304
+ name: 'op5',
305
+ pattern: [lhs('number').as('l'), constVal('|5|'), rhs('number').as('r')],
306
+ precedence: 1,
307
+ resultType: 'number',
308
+ }),
309
+ ]);
310
+ bench('2 ops at same precedence - first op', () => {
311
+ samePrec2.parse('1 |1| 2', {});
312
+ });
313
+ bench('2 ops at same precedence - second op', () => {
314
+ samePrec2.parse('1 |2| 2', {});
315
+ });
316
+ bench('5 ops at same precedence - first op', () => {
317
+ samePrec5.parse('1 |1| 2', {});
318
+ });
319
+ bench('5 ops at same precedence - fifth op', () => {
320
+ samePrec5.parse('1 |5| 2', {});
321
+ });
322
+ bench('5 ops at same precedence - number literal only', () => {
323
+ samePrec5.parse('42', {});
324
+ });
325
+ });
326
+ // =============================================================================
327
+ // Benchmarks: String Parsing
328
+ // =============================================================================
329
+ describe('String Parsing', () => {
330
+ const stringParser = createParser([concat]);
331
+ const shortStr = '"hello"';
332
+ const mediumStr = '"' + 'a'.repeat(100) + '"';
333
+ const longStr = '"' + 'a'.repeat(1000) + '"';
334
+ bench('short string (5 chars)', () => {
335
+ stringParser.parse(shortStr, {});
336
+ });
337
+ bench('medium string (100 chars)', () => {
338
+ stringParser.parse(mediumStr, {});
339
+ });
340
+ bench('long string (1000 chars)', () => {
341
+ stringParser.parse(longStr, {});
342
+ });
343
+ const escapedStr = '"hello\\nworld\\t\\u0041"';
344
+ bench('string with escapes', () => {
345
+ stringParser.parse(escapedStr, {});
346
+ });
347
+ bench('string concatenation', () => {
348
+ stringParser.parse('"hello" ++ "world"', {});
349
+ });
350
+ });
351
+ // =============================================================================
352
+ // Benchmarks: Context Resolution
353
+ // =============================================================================
354
+ describe('Context Resolution', () => {
355
+ const smallContext = { x: 'number' };
356
+ const mediumContext = {
357
+ a: 'number',
358
+ b: 'number',
359
+ c: 'number',
360
+ d: 'number',
361
+ e: 'number',
362
+ x: 'number',
363
+ };
364
+ const largeContext = Object.fromEntries(Array.from({ length: 100 }, (_, i) => [`var${i}`, 'number']));
365
+ largeContext['x'] = 'number';
366
+ bench('small context - identifier lookup', () => {
367
+ arithmeticParser.parse('x', smallContext);
368
+ });
369
+ bench('medium context - identifier lookup', () => {
370
+ arithmeticParser.parse('x', mediumContext);
371
+ });
372
+ bench('large context - identifier lookup', () => {
373
+ arithmeticParser.parse('x', largeContext);
374
+ });
375
+ bench('context - expression with identifiers', () => {
376
+ arithmeticParser.parse('x + x * x', smallContext);
377
+ });
378
+ });
379
+ //# sourceMappingURL=performance.bench.js.map