@optique/core 1.0.0-dev.1903 → 1.0.0-dev.1972
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/dist/annotation-state.cjs +66 -31
- package/dist/annotation-state.d.cts +24 -0
- package/dist/annotation-state.d.ts +24 -0
- package/dist/annotation-state.js +65 -31
- package/dist/annotations.cjs +2 -267
- package/dist/annotations.d.cts +2 -152
- package/dist/annotations.d.ts +2 -152
- package/dist/annotations.js +2 -256
- package/dist/completion.cjs +1 -1
- package/dist/completion.d.cts +1 -1
- package/dist/completion.d.ts +1 -1
- package/dist/completion.js +1 -1
- package/dist/constructs.cjs +206 -238
- package/dist/constructs.d.cts +1 -1
- package/dist/constructs.d.ts +1 -1
- package/dist/constructs.js +96 -128
- package/dist/context.d.cts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/dependency-metadata.cjs +1 -1
- package/dist/dependency-metadata.d.cts +1 -1
- package/dist/dependency-metadata.d.ts +1 -1
- package/dist/dependency-metadata.js +1 -1
- package/dist/dependency-runtime.cjs +2 -2
- package/dist/dependency-runtime.js +2 -2
- package/dist/dependency.cjs +7 -1111
- package/dist/dependency.d.cts +2 -838
- package/dist/dependency.d.ts +2 -838
- package/dist/dependency.js +2 -1078
- package/dist/execution-context.cjs +56 -0
- package/dist/execution-context.js +53 -0
- package/dist/extension.cjs +87 -0
- package/dist/extension.d.cts +97 -0
- package/dist/extension.d.ts +97 -0
- package/dist/extension.js +76 -0
- package/dist/facade.cjs +19 -19
- package/dist/facade.d.cts +1 -1
- package/dist/facade.d.ts +1 -1
- package/dist/facade.js +19 -19
- package/dist/index.cjs +4 -41
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +5 -5
- package/dist/internal/annotations.cjs +316 -0
- package/dist/internal/annotations.d.cts +140 -0
- package/dist/internal/annotations.d.ts +140 -0
- package/dist/internal/annotations.js +306 -0
- package/dist/internal/dependency.cjs +984 -0
- package/dist/internal/dependency.d.cts +539 -0
- package/dist/internal/dependency.d.ts +539 -0
- package/dist/internal/dependency.js +964 -0
- package/dist/{mode-dispatch.cjs → internal/mode-dispatch.cjs} +1 -3
- package/dist/{mode-dispatch.d.cts → internal/mode-dispatch.d.cts} +3 -7
- package/dist/{mode-dispatch.d.ts → internal/mode-dispatch.d.ts} +3 -7
- package/dist/{mode-dispatch.js → internal/mode-dispatch.js} +1 -3
- package/dist/internal/parser.cjs +728 -0
- package/dist/internal/parser.d.cts +947 -0
- package/dist/internal/parser.d.ts +947 -0
- package/dist/internal/parser.js +711 -0
- package/dist/modifiers.cjs +67 -95
- package/dist/modifiers.d.cts +1 -1
- package/dist/modifiers.d.ts +1 -1
- package/dist/modifiers.js +51 -79
- package/dist/parser.cjs +11 -743
- package/dist/parser.d.cts +3 -991
- package/dist/parser.d.ts +3 -991
- package/dist/parser.js +2 -704
- package/dist/phase2-seed.cjs +4 -4
- package/dist/phase2-seed.js +4 -4
- package/dist/primitives.cjs +40 -75
- package/dist/primitives.d.cts +1 -1
- package/dist/primitives.d.ts +1 -1
- package/dist/primitives.js +27 -62
- package/dist/program.d.cts +1 -1
- package/dist/program.d.ts +1 -1
- package/dist/valueparser.cjs +23 -23
- package/dist/valueparser.d.cts +3 -3
- package/dist/valueparser.d.ts +3 -3
- package/dist/valueparser.js +23 -23
- package/package.json +9 -9
package/dist/modifiers.cjs
CHANGED
|
@@ -1,47 +1,13 @@
|
|
|
1
|
-
const require_annotations = require('./annotations.cjs');
|
|
1
|
+
const require_annotations = require('./internal/annotations.cjs');
|
|
2
2
|
const require_message = require('./message.cjs');
|
|
3
|
-
const require_mode_dispatch = require('./mode-dispatch.cjs');
|
|
4
|
-
const
|
|
5
|
-
const require_phase2_seed = require('./phase2-seed.cjs');
|
|
6
|
-
const require_parser = require('./parser.cjs');
|
|
3
|
+
const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
|
|
4
|
+
const require_parser = require('./internal/parser.cjs');
|
|
7
5
|
const require_annotation_state = require('./annotation-state.cjs');
|
|
6
|
+
const require_execution_context = require('./execution-context.cjs');
|
|
7
|
+
const require_phase2_seed = require('./phase2-seed.cjs');
|
|
8
|
+
const require_dependency_metadata = require('./dependency-metadata.cjs');
|
|
8
9
|
|
|
9
10
|
//#region src/modifiers.ts
|
|
10
|
-
function withChildExecPath(exec, segment) {
|
|
11
|
-
if (exec == null) return void 0;
|
|
12
|
-
return {
|
|
13
|
-
...exec,
|
|
14
|
-
path: [...exec.path ?? [], segment]
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function mergeChildExec(parent, child) {
|
|
18
|
-
if (parent == null) return child;
|
|
19
|
-
if (child == null) return parent;
|
|
20
|
-
return {
|
|
21
|
-
...parent,
|
|
22
|
-
trace: child.trace ?? parent.trace,
|
|
23
|
-
dependencyRuntime: child.dependencyRuntime ?? parent.dependencyRuntime,
|
|
24
|
-
dependencyRegistry: child.dependencyRegistry ?? parent.dependencyRegistry,
|
|
25
|
-
commandPath: child.commandPath ?? parent.commandPath,
|
|
26
|
-
preCompletedByParser: child.preCompletedByParser ?? parent.preCompletedByParser,
|
|
27
|
-
excludedSourceFields: child.excludedSourceFields ?? parent.excludedSourceFields
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function withChildContext(context, segment, state) {
|
|
31
|
-
const exec = withChildExecPath(context.exec, segment);
|
|
32
|
-
const dependencyRegistry = context.dependencyRegistry ?? exec?.dependencyRegistry;
|
|
33
|
-
return {
|
|
34
|
-
...context,
|
|
35
|
-
state,
|
|
36
|
-
...exec != null ? {
|
|
37
|
-
exec: dependencyRegistry === exec.dependencyRegistry ? exec : {
|
|
38
|
-
...exec,
|
|
39
|
-
dependencyRegistry
|
|
40
|
-
},
|
|
41
|
-
dependencyRegistry
|
|
42
|
-
} : {}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
11
|
function isTerminalMultipleItemState(state) {
|
|
46
12
|
const unwrapped = unwrapMultipleItemState(state).value;
|
|
47
13
|
return unwrapped != null && typeof unwrapped === "object" && Object.hasOwn(unwrapped, "success") && typeof unwrapped.success === "boolean";
|
|
@@ -88,6 +54,9 @@ function normalizeOptionalLikeCompleteResult(result, shouldNormalize) {
|
|
|
88
54
|
value: require_annotation_state.normalizeNestedDelegatedAnnotationState(result.value)
|
|
89
55
|
} : result;
|
|
90
56
|
}
|
|
57
|
+
function shouldRetryOptionalLikeCompatibilityError(error, state) {
|
|
58
|
+
return error instanceof TypeError && state != null && typeof state === "object" && require_annotations.isInjectedAnnotationWrapper(state);
|
|
59
|
+
}
|
|
91
60
|
function completeOptionalLikeSync(parser, state, exec) {
|
|
92
61
|
const hasCarrier = require_annotation_state.hasDelegatedAnnotationCarrier(state);
|
|
93
62
|
const shouldRetryFalseResult = hasCarrier && require_annotation_state.isAnnotationWrappedInitialState(state);
|
|
@@ -97,7 +66,7 @@ function completeOptionalLikeSync(parser, state, exec) {
|
|
|
97
66
|
if (!result.success && shouldRetryFalseResult) return run(require_annotation_state.normalizeDelegatedAnnotationState(state), false);
|
|
98
67
|
return result;
|
|
99
68
|
} catch (error) {
|
|
100
|
-
if (!
|
|
69
|
+
if (!shouldRetryOptionalLikeCompatibilityError(error, state)) throw error;
|
|
101
70
|
return run(require_annotation_state.normalizeDelegatedAnnotationState(state), false);
|
|
102
71
|
}
|
|
103
72
|
}
|
|
@@ -110,7 +79,7 @@ async function completeOptionalLikeAsync(parser, state, exec) {
|
|
|
110
79
|
if (!result.success && shouldRetryFalseResult) return await run(require_annotation_state.normalizeDelegatedAnnotationState(state), false);
|
|
111
80
|
return result;
|
|
112
81
|
} catch (error) {
|
|
113
|
-
if (!
|
|
82
|
+
if (!shouldRetryOptionalLikeCompatibilityError(error, state)) throw error;
|
|
114
83
|
return await run(require_annotation_state.normalizeDelegatedAnnotationState(state), false);
|
|
115
84
|
}
|
|
116
85
|
}
|
|
@@ -121,11 +90,11 @@ function normalizeOptionalLikePhase2Seed(seed, shouldNormalize) {
|
|
|
121
90
|
} : seed;
|
|
122
91
|
}
|
|
123
92
|
function extractOptionalLikePhase2Seed(parser, state, exec) {
|
|
124
|
-
if (!Array.isArray(state) && !(state != null && typeof state === "object")) return require_mode_dispatch.wrapForMode(parser
|
|
93
|
+
if (!Array.isArray(state) && !(state != null && typeof state === "object")) return require_mode_dispatch.wrapForMode(parser.mode, null);
|
|
125
94
|
const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
126
95
|
const hasCarrier = require_annotation_state.hasDelegatedAnnotationCarrier(innerState);
|
|
127
96
|
const shouldRetryFalseResult = hasCarrier && require_annotation_state.isAnnotationWrappedInitialState(innerState);
|
|
128
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
97
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => {
|
|
129
98
|
try {
|
|
130
99
|
const result = parser.complete(innerState, exec);
|
|
131
100
|
if (result.success) return normalizeOptionalLikePhase2Seed(require_phase2_seed.phase2SeedFromValueResult(result), hasCarrier);
|
|
@@ -141,7 +110,7 @@ function extractOptionalLikePhase2Seed(parser, state, exec) {
|
|
|
141
110
|
}
|
|
142
111
|
return normalizeOptionalLikePhase2Seed(seed, hasCarrier);
|
|
143
112
|
} catch (error) {
|
|
144
|
-
if (!
|
|
113
|
+
if (!shouldRetryOptionalLikeCompatibilityError(error, innerState)) throw error;
|
|
145
114
|
const fallbackState = require_annotation_state.normalizeDelegatedAnnotationState(innerState);
|
|
146
115
|
const result = parser.complete(fallbackState, exec);
|
|
147
116
|
if (result.success) return normalizeOptionalLikePhase2Seed(require_phase2_seed.phase2SeedFromValueResult(result), false);
|
|
@@ -163,7 +132,7 @@ function extractOptionalLikePhase2Seed(parser, state, exec) {
|
|
|
163
132
|
}
|
|
164
133
|
return normalizeOptionalLikePhase2Seed(seed, hasCarrier);
|
|
165
134
|
} catch (error) {
|
|
166
|
-
if (!
|
|
135
|
+
if (!shouldRetryOptionalLikeCompatibilityError(error, innerState)) throw error;
|
|
167
136
|
const fallbackState = require_annotation_state.normalizeDelegatedAnnotationState(innerState);
|
|
168
137
|
const result = await parser.complete(fallbackState, exec);
|
|
169
138
|
if (result.success) return normalizeOptionalLikePhase2Seed(require_phase2_seed.phase2SeedFromValueResult(result), false);
|
|
@@ -187,12 +156,12 @@ function extractOptionalLikePhase2Seed(parser, state, exec) {
|
|
|
187
156
|
function deriveOptionalInnerParseState(outerState, parser) {
|
|
188
157
|
if (Array.isArray(outerState)) {
|
|
189
158
|
const innerState = outerState[0];
|
|
190
|
-
if (require_annotations.getAnnotations(outerState) != null && innerState != null && typeof innerState === "object") return
|
|
159
|
+
if (require_annotations.getAnnotations(outerState) != null && innerState != null && typeof innerState === "object") return require_annotation_state.getDelegatedAnnotationState(outerState, innerState);
|
|
191
160
|
return innerState;
|
|
192
161
|
}
|
|
193
162
|
const initial = parser.initialState;
|
|
194
163
|
if (initial != null && typeof initial !== "object") return initial;
|
|
195
|
-
return require_annotations.inheritAnnotations(outerState, initial);
|
|
164
|
+
return initial != null && typeof initial === "object" ? require_annotation_state.getDelegatedAnnotationState(outerState, initial) : require_annotations.inheritAnnotations(outerState, initial);
|
|
196
165
|
}
|
|
197
166
|
/**
|
|
198
167
|
* Internal helper for optional-style parsing logic shared by optional()
|
|
@@ -226,9 +195,12 @@ async function parseOptionalStyleAsync(context, parser) {
|
|
|
226
195
|
* Internal helper to process optional-style parse results.
|
|
227
196
|
* @internal
|
|
228
197
|
*/
|
|
198
|
+
function hasOptionalLikeParseStateChanged(previousState, nextState) {
|
|
199
|
+
return previousState !== nextState && require_annotation_state.normalizeDelegatedAnnotationState(previousState) !== require_annotation_state.normalizeDelegatedAnnotationState(nextState);
|
|
200
|
+
}
|
|
229
201
|
function processOptionalStyleResult(result, innerState, context) {
|
|
230
202
|
if (result.success) {
|
|
231
|
-
if (result.next.state
|
|
203
|
+
if (hasOptionalLikeParseStateChanged(innerState, result.next.state) || result.consumed.length === 0) return {
|
|
232
204
|
success: true,
|
|
233
205
|
...result.provisional ? { provisional: true } : {},
|
|
234
206
|
next: {
|
|
@@ -277,7 +249,7 @@ function adaptShouldDeferCompletion(innerCheck, parser) {
|
|
|
277
249
|
if (!result && shouldRetryFalseResult) return innerCheck(require_annotation_state.normalizeDelegatedAnnotationState(innerState), exec);
|
|
278
250
|
return result;
|
|
279
251
|
} catch (error) {
|
|
280
|
-
if (!
|
|
252
|
+
if (!shouldRetryOptionalLikeCompatibilityError(error, innerState)) throw error;
|
|
281
253
|
return innerCheck(require_annotation_state.normalizeDelegatedAnnotationState(innerState), exec);
|
|
282
254
|
}
|
|
283
255
|
}
|
|
@@ -335,7 +307,7 @@ function optional(parser) {
|
|
|
335
307
|
for await (const s of suggestions) yield s;
|
|
336
308
|
}
|
|
337
309
|
const optionalParser = {
|
|
338
|
-
|
|
310
|
+
mode: parser.mode,
|
|
339
311
|
$valueType: [],
|
|
340
312
|
$stateType: [],
|
|
341
313
|
...parser[require_parser.unmatchedNonCliDependencySourceStateMarker] === true ? { [require_parser.unmatchedNonCliDependencySourceStateMarker]: true } : {},
|
|
@@ -366,13 +338,13 @@ function optional(parser) {
|
|
|
366
338
|
return extractOptionalLikePhase2Seed(parser, state, exec);
|
|
367
339
|
},
|
|
368
340
|
parse(context) {
|
|
369
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
341
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
|
|
370
342
|
},
|
|
371
343
|
complete(state, exec) {
|
|
372
344
|
if (!Array.isArray(state)) {
|
|
373
345
|
const delegateToInner = (resolvedInnerState) => {
|
|
374
|
-
const innerResult = require_mode_dispatch.dispatchByMode(parser
|
|
375
|
-
return require_mode_dispatch.mapModeValue(parser
|
|
346
|
+
const innerResult = require_mode_dispatch.dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, resolvedInnerState, exec), async () => await completeOptionalLikeAsync(parser, resolvedInnerState, exec));
|
|
347
|
+
return require_mode_dispatch.mapModeValue(parser.mode, innerResult, (result) => result.success ? result : {
|
|
376
348
|
success: true,
|
|
377
349
|
value: void 0
|
|
378
350
|
});
|
|
@@ -384,7 +356,7 @@ function optional(parser) {
|
|
|
384
356
|
const sourceMetadata = parser.dependencyMetadata?.source;
|
|
385
357
|
if (sourceMetadata?.preservesSourceValue !== false && sourceMetadata?.getMissingSourceValue != null) {
|
|
386
358
|
const delegatedState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
387
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
359
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, delegatedState, exec), async () => await completeOptionalLikeAsync(parser, delegatedState, exec));
|
|
388
360
|
}
|
|
389
361
|
if (parser[require_parser.unmatchedNonCliDependencySourceStateMarker] === true && state != null && typeof state === "object") {
|
|
390
362
|
const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
@@ -396,10 +368,10 @@ function optional(parser) {
|
|
|
396
368
|
};
|
|
397
369
|
}
|
|
398
370
|
const innerElement = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
399
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
371
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, innerElement, exec), async () => await completeOptionalLikeAsync(parser, innerElement, exec));
|
|
400
372
|
},
|
|
401
373
|
suggest(context, prefix) {
|
|
402
|
-
return require_mode_dispatch.dispatchIterableByMode(parser
|
|
374
|
+
return require_mode_dispatch.dispatchIterableByMode(parser.mode, () => suggestSync(context, prefix), () => suggestAsync(context, prefix));
|
|
403
375
|
},
|
|
404
376
|
getDocFragments(state, defaultValue) {
|
|
405
377
|
const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state === void 0 ? { kind: "unavailable" } : {
|
|
@@ -424,7 +396,7 @@ function optional(parser) {
|
|
|
424
396
|
const innerValidate = parser.validateValue.bind(parser);
|
|
425
397
|
Object.defineProperty(optionalParser, "validateValue", {
|
|
426
398
|
value(v) {
|
|
427
|
-
if (v === void 0) return require_mode_dispatch.wrapForMode(parser
|
|
399
|
+
if (v === void 0) return require_mode_dispatch.wrapForMode(parser.mode, {
|
|
428
400
|
success: true,
|
|
429
401
|
value: v
|
|
430
402
|
});
|
|
@@ -504,7 +476,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
504
476
|
for await (const s of suggestions) yield s;
|
|
505
477
|
}
|
|
506
478
|
const withDefaultParser = {
|
|
507
|
-
|
|
479
|
+
mode: parser.mode,
|
|
508
480
|
$valueType: [],
|
|
509
481
|
$stateType: [],
|
|
510
482
|
...parser[require_parser.unmatchedNonCliDependencySourceStateMarker] === true ? { [require_parser.unmatchedNonCliDependencySourceStateMarker]: true } : {},
|
|
@@ -534,7 +506,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
534
506
|
return extractOptionalLikePhase2Seed(parser, state, exec);
|
|
535
507
|
},
|
|
536
508
|
parse(context) {
|
|
537
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
509
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
|
|
538
510
|
},
|
|
539
511
|
complete(state, exec) {
|
|
540
512
|
function evaluateDefault() {
|
|
@@ -547,12 +519,12 @@ function withDefault(parser, defaultValue, options) {
|
|
|
547
519
|
if (!Array.isArray(state)) {
|
|
548
520
|
if (typeof parser.shouldDeferCompletion === "function" && state != null && typeof state === "object") {
|
|
549
521
|
const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
550
|
-
const innerResult = require_mode_dispatch.dispatchByMode(parser
|
|
522
|
+
const innerResult = require_mode_dispatch.dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, innerState, exec), async () => await completeOptionalLikeAsync(parser, innerState, exec));
|
|
551
523
|
return innerResult;
|
|
552
524
|
}
|
|
553
525
|
if (parser[require_parser.unmatchedNonCliDependencySourceStateMarker] === true && state != null && typeof state === "object") {
|
|
554
526
|
const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
555
|
-
const innerResult = require_mode_dispatch.dispatchByMode(parser
|
|
527
|
+
const innerResult = require_mode_dispatch.dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, innerState, exec), async () => await completeOptionalLikeAsync(parser, innerState, exec));
|
|
556
528
|
const handleInnerResult = (result) => {
|
|
557
529
|
if (result.success && result.value !== void 0) return result;
|
|
558
530
|
try {
|
|
@@ -567,7 +539,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
567
539
|
};
|
|
568
540
|
}
|
|
569
541
|
};
|
|
570
|
-
return require_mode_dispatch.mapModeValue(parser
|
|
542
|
+
return require_mode_dispatch.mapModeValue(parser.mode, innerResult, handleInnerResult);
|
|
571
543
|
}
|
|
572
544
|
try {
|
|
573
545
|
const value = evaluateDefault();
|
|
@@ -583,10 +555,10 @@ function withDefault(parser, defaultValue, options) {
|
|
|
583
555
|
}
|
|
584
556
|
}
|
|
585
557
|
const innerElement = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
586
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
558
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, innerElement, exec), async () => await completeOptionalLikeAsync(parser, innerElement, exec));
|
|
587
559
|
},
|
|
588
560
|
suggest(context, prefix) {
|
|
589
|
-
return require_mode_dispatch.dispatchIterableByMode(parser
|
|
561
|
+
return require_mode_dispatch.dispatchIterableByMode(parser.mode, () => suggestSync(context, prefix), () => suggestAsync(context, prefix));
|
|
590
562
|
},
|
|
591
563
|
getDocFragments(state, upperDefaultValue) {
|
|
592
564
|
const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state === void 0 ? { kind: "unavailable" } : {
|
|
@@ -748,7 +720,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
748
720
|
*/
|
|
749
721
|
function map(parser, transform) {
|
|
750
722
|
const complete = (state, exec) => {
|
|
751
|
-
return require_mode_dispatch.mapModeValue(parser
|
|
723
|
+
return require_mode_dispatch.mapModeValue(parser.mode, parser.complete(state, exec), (result) => {
|
|
752
724
|
if (!result.success) return result;
|
|
753
725
|
if (result.deferred) try {
|
|
754
726
|
return {
|
|
@@ -774,7 +746,7 @@ function map(parser, transform) {
|
|
|
774
746
|
$valueType: [],
|
|
775
747
|
complete,
|
|
776
748
|
[require_phase2_seed.extractPhase2SeedKey](state, exec) {
|
|
777
|
-
return require_mode_dispatch.mapModeValue(parser
|
|
749
|
+
return require_mode_dispatch.mapModeValue(parser.mode, require_phase2_seed.completeOrExtractPhase2Seed(parser, state, exec), (seed) => {
|
|
778
750
|
if (seed == null) return null;
|
|
779
751
|
if (seed.deferred) try {
|
|
780
752
|
return {
|
|
@@ -966,13 +938,13 @@ function multiple(parser, options = {}) {
|
|
|
966
938
|
let added = !canExtendCurrent;
|
|
967
939
|
let itemIndex = canExtendCurrent ? context.state.length - 1 : context.state.length;
|
|
968
940
|
const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState : require_annotations.inheritAnnotations(context.state, syncParser.initialState);
|
|
969
|
-
let result = parseSyncWithUnwrappedFallback(withChildContext(context, itemIndex, currentItemStateWithAnnotations));
|
|
941
|
+
let result = parseSyncWithUnwrappedFallback(require_execution_context.withChildContext(context, itemIndex, currentItemStateWithAnnotations));
|
|
970
942
|
if (!result.success) {
|
|
971
943
|
if (result.consumed !== 0) return result;
|
|
972
944
|
if (!added && canOpenFreshItem) {
|
|
973
945
|
const nextInitialState = require_annotations.inheritAnnotations(context.state, syncParser.initialState);
|
|
974
946
|
itemIndex = context.state.length;
|
|
975
|
-
result = parseSyncWithUnwrappedFallback(withChildContext(context, itemIndex, nextInitialState));
|
|
947
|
+
result = parseSyncWithUnwrappedFallback(require_execution_context.withChildContext(context, itemIndex, nextInitialState));
|
|
976
948
|
if (!result.success) {
|
|
977
949
|
if (min === 0 && context.buffer.length === 0 && result.consumed === 0) return {
|
|
978
950
|
success: true,
|
|
@@ -989,7 +961,7 @@ function multiple(parser, options = {}) {
|
|
|
989
961
|
};
|
|
990
962
|
else return result;
|
|
991
963
|
}
|
|
992
|
-
const mergedExec = mergeChildExec(context.exec, result.next.exec);
|
|
964
|
+
const mergedExec = require_execution_context.mergeChildExec(context.exec, result.next.exec);
|
|
993
965
|
if (added && result.consumed.length === 0 && result.next.optionsTerminated === context.optionsTerminated && isUnstartedMultipleItemState(result.next.state, currentItemStateWithAnnotations)) return {
|
|
994
966
|
success: true,
|
|
995
967
|
next: {
|
|
@@ -1046,13 +1018,13 @@ function multiple(parser, options = {}) {
|
|
|
1046
1018
|
let added = !canExtendCurrent;
|
|
1047
1019
|
let itemIndex = canExtendCurrent ? context.state.length - 1 : context.state.length;
|
|
1048
1020
|
const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState : require_annotations.inheritAnnotations(context.state, parser.initialState);
|
|
1049
|
-
let result = await parseAsyncWithUnwrappedFallback(withChildContext(context, itemIndex, currentItemStateWithAnnotations));
|
|
1021
|
+
let result = await parseAsyncWithUnwrappedFallback(require_execution_context.withChildContext(context, itemIndex, currentItemStateWithAnnotations));
|
|
1050
1022
|
if (!result.success) {
|
|
1051
1023
|
if (result.consumed !== 0) return result;
|
|
1052
1024
|
if (!added && canOpenFreshItem) {
|
|
1053
1025
|
const nextInitialState = require_annotations.inheritAnnotations(context.state, parser.initialState);
|
|
1054
1026
|
itemIndex = context.state.length;
|
|
1055
|
-
result = await parseAsyncWithUnwrappedFallback(withChildContext(context, itemIndex, nextInitialState));
|
|
1027
|
+
result = await parseAsyncWithUnwrappedFallback(require_execution_context.withChildContext(context, itemIndex, nextInitialState));
|
|
1056
1028
|
if (!result.success) {
|
|
1057
1029
|
if (min === 0 && context.buffer.length === 0 && result.consumed === 0) return {
|
|
1058
1030
|
success: true,
|
|
@@ -1069,7 +1041,7 @@ function multiple(parser, options = {}) {
|
|
|
1069
1041
|
};
|
|
1070
1042
|
else return result;
|
|
1071
1043
|
}
|
|
1072
|
-
const mergedExec = mergeChildExec(context.exec, result.next.exec);
|
|
1044
|
+
const mergedExec = require_execution_context.mergeChildExec(context.exec, result.next.exec);
|
|
1073
1045
|
if (added && result.consumed.length === 0 && result.next.optionsTerminated === context.optionsTerminated && isUnstartedMultipleItemState(result.next.state, currentItemStateWithAnnotations)) return {
|
|
1074
1046
|
success: true,
|
|
1075
1047
|
next: {
|
|
@@ -1115,7 +1087,7 @@ function multiple(parser, options = {}) {
|
|
|
1115
1087
|
};
|
|
1116
1088
|
};
|
|
1117
1089
|
const resultParser = {
|
|
1118
|
-
|
|
1090
|
+
mode: parser.mode,
|
|
1119
1091
|
$valueType: [],
|
|
1120
1092
|
$stateType: [],
|
|
1121
1093
|
priority: parser.priority,
|
|
@@ -1136,15 +1108,15 @@ function multiple(parser, options = {}) {
|
|
|
1136
1108
|
}, ...innerNodes] : innerNodes;
|
|
1137
1109
|
},
|
|
1138
1110
|
parse(context) {
|
|
1139
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
1111
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => parseSync(context), () => parseAsync(context));
|
|
1140
1112
|
},
|
|
1141
1113
|
complete(state, exec) {
|
|
1142
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
1114
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => {
|
|
1143
1115
|
const result = [];
|
|
1144
1116
|
const deferredIndices = /* @__PURE__ */ new Map();
|
|
1145
1117
|
let hasDeferred = false;
|
|
1146
1118
|
for (let i = 0; i < state.length; i++) {
|
|
1147
|
-
const valueResult = completeSyncWithUnwrappedFallback(state[i], withChildExecPath(exec, i));
|
|
1119
|
+
const valueResult = completeSyncWithUnwrappedFallback(state[i], require_execution_context.withChildExecPath(exec, i));
|
|
1148
1120
|
if (valueResult.success) {
|
|
1149
1121
|
const unwrappedValue = unwrapInjectedWrapper(valueResult.value);
|
|
1150
1122
|
result.push(unwrappedValue);
|
|
@@ -1162,7 +1134,7 @@ function multiple(parser, options = {}) {
|
|
|
1162
1134
|
const deferredIndices = /* @__PURE__ */ new Map();
|
|
1163
1135
|
let hasDeferred = false;
|
|
1164
1136
|
for (let i = 0; i < state.length; i++) {
|
|
1165
|
-
const valueResult = await completeAsyncWithUnwrappedFallback(state[i], withChildExecPath(exec, i));
|
|
1137
|
+
const valueResult = await completeAsyncWithUnwrappedFallback(state[i], require_execution_context.withChildExecPath(exec, i));
|
|
1166
1138
|
if (valueResult.success) {
|
|
1167
1139
|
const unwrappedValue = unwrapInjectedWrapper(valueResult.value);
|
|
1168
1140
|
values.push(unwrappedValue);
|
|
@@ -1178,13 +1150,13 @@ function multiple(parser, options = {}) {
|
|
|
1178
1150
|
});
|
|
1179
1151
|
},
|
|
1180
1152
|
[require_phase2_seed.extractPhase2SeedKey](state, exec) {
|
|
1181
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
1153
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => {
|
|
1182
1154
|
const values = [];
|
|
1183
1155
|
const deferredIndices = /* @__PURE__ */ new Map();
|
|
1184
1156
|
let hasDeferred = false;
|
|
1185
1157
|
let hasAnySeed = false;
|
|
1186
1158
|
for (let i = 0; i < state.length; i++) {
|
|
1187
|
-
const seed = extractPhase2SeedSyncWithUnwrappedFallback(state[i], withChildExecPath(exec, i));
|
|
1159
|
+
const seed = extractPhase2SeedSyncWithUnwrappedFallback(state[i], require_execution_context.withChildExecPath(exec, i));
|
|
1188
1160
|
if (seed == null) continue;
|
|
1189
1161
|
hasAnySeed = true;
|
|
1190
1162
|
values[i] = seed.value;
|
|
@@ -1206,7 +1178,7 @@ function multiple(parser, options = {}) {
|
|
|
1206
1178
|
let hasDeferred = false;
|
|
1207
1179
|
let hasAnySeed = false;
|
|
1208
1180
|
for (let i = 0; i < state.length; i++) {
|
|
1209
|
-
const seed = await extractPhase2SeedAsyncWithUnwrappedFallback(state[i], withChildExecPath(exec, i));
|
|
1181
|
+
const seed = await extractPhase2SeedAsyncWithUnwrappedFallback(state[i], require_execution_context.withChildExecPath(exec, i));
|
|
1210
1182
|
if (seed == null) continue;
|
|
1211
1183
|
hasAnySeed = true;
|
|
1212
1184
|
values[i] = seed.value;
|
|
@@ -1228,7 +1200,7 @@ function multiple(parser, options = {}) {
|
|
|
1228
1200
|
const currentItemState = context.state.at(-1);
|
|
1229
1201
|
const canExtendCurrent = currentItemState != null && !isTerminalMultipleItemState(currentItemState);
|
|
1230
1202
|
const canOpenNew = context.state.length < max;
|
|
1231
|
-
if (!canExtendCurrent && !canOpenNew) return require_mode_dispatch.dispatchIterableByMode(parser
|
|
1203
|
+
if (!canExtendCurrent && !canOpenNew) return require_mode_dispatch.dispatchIterableByMode(parser.mode, function* () {}, async function* () {});
|
|
1232
1204
|
const itemIndex = canExtendCurrent ? context.state.length - 1 : context.state.length;
|
|
1233
1205
|
const suggestInitialState = canExtendCurrent ? currentItemState : require_annotations.inheritAnnotations(context.state, parser.initialState);
|
|
1234
1206
|
const suggestFallbackState = unwrapInjectedWrapper(suggestInitialState);
|
|
@@ -1236,7 +1208,7 @@ function multiple(parser, options = {}) {
|
|
|
1236
1208
|
const collectSelectedValuesSync = () => {
|
|
1237
1209
|
const selectedValues = /* @__PURE__ */ new Set();
|
|
1238
1210
|
for (let i = 0; i < context.state.length; i++) {
|
|
1239
|
-
const childContext = withChildContext(context, i, context.state[i]);
|
|
1211
|
+
const childContext = require_execution_context.withChildContext(context, i, context.state[i]);
|
|
1240
1212
|
const completed = completeSyncWithUnwrappedFallback(childContext.state, childContext.exec);
|
|
1241
1213
|
if (completed.success) selectedValues.add(String(unwrapInjectedWrapper(completed.value)));
|
|
1242
1214
|
}
|
|
@@ -1245,7 +1217,7 @@ function multiple(parser, options = {}) {
|
|
|
1245
1217
|
const collectSelectedValuesAsync = async () => {
|
|
1246
1218
|
const selectedValues = /* @__PURE__ */ new Set();
|
|
1247
1219
|
for (let i = 0; i < context.state.length; i++) {
|
|
1248
|
-
const childContext = withChildContext(context, i, context.state[i]);
|
|
1220
|
+
const childContext = require_execution_context.withChildContext(context, i, context.state[i]);
|
|
1249
1221
|
const completed = await completeAsyncWithUnwrappedFallback(childContext.state, childContext.exec);
|
|
1250
1222
|
if (completed.success) selectedValues.add(String(unwrapInjectedWrapper(completed.value)));
|
|
1251
1223
|
}
|
|
@@ -1271,7 +1243,7 @@ function multiple(parser, options = {}) {
|
|
|
1271
1243
|
description
|
|
1272
1244
|
]);
|
|
1273
1245
|
};
|
|
1274
|
-
return require_mode_dispatch.dispatchIterableByMode(parser
|
|
1246
|
+
return require_mode_dispatch.dispatchIterableByMode(parser.mode, function* () {
|
|
1275
1247
|
const selectedValues = collectSelectedValuesSync();
|
|
1276
1248
|
const emitted = /* @__PURE__ */ new Set();
|
|
1277
1249
|
const yieldUnique = function* (suggestions) {
|
|
@@ -1285,12 +1257,12 @@ function multiple(parser, options = {}) {
|
|
|
1285
1257
|
};
|
|
1286
1258
|
let shouldTryFallback = false;
|
|
1287
1259
|
try {
|
|
1288
|
-
yield* yieldUnique(syncParser.suggest(withChildContext(context, itemIndex, suggestInitialState), prefix));
|
|
1260
|
+
yield* yieldUnique(syncParser.suggest(require_execution_context.withChildContext(context, itemIndex, suggestInitialState), prefix));
|
|
1289
1261
|
} catch (error) {
|
|
1290
1262
|
if (!hasSuggestFallbackState) throw error;
|
|
1291
1263
|
shouldTryFallback = true;
|
|
1292
1264
|
}
|
|
1293
|
-
if (shouldTryFallback) yield* yieldUnique(syncParser.suggest(withChildContext(context, itemIndex, suggestFallbackState), prefix));
|
|
1265
|
+
if (shouldTryFallback) yield* yieldUnique(syncParser.suggest(require_execution_context.withChildContext(context, itemIndex, suggestFallbackState), prefix));
|
|
1294
1266
|
}, async function* () {
|
|
1295
1267
|
const selectedValues = await collectSelectedValuesAsync();
|
|
1296
1268
|
const emitted = /* @__PURE__ */ new Set();
|
|
@@ -1305,12 +1277,12 @@ function multiple(parser, options = {}) {
|
|
|
1305
1277
|
};
|
|
1306
1278
|
let shouldTryFallback = false;
|
|
1307
1279
|
try {
|
|
1308
|
-
yield* yieldUnique(parser.suggest(withChildContext(context, itemIndex, suggestInitialState), prefix));
|
|
1280
|
+
yield* yieldUnique(parser.suggest(require_execution_context.withChildContext(context, itemIndex, suggestInitialState), prefix));
|
|
1309
1281
|
} catch (error) {
|
|
1310
1282
|
if (!hasSuggestFallbackState) throw error;
|
|
1311
1283
|
shouldTryFallback = true;
|
|
1312
1284
|
}
|
|
1313
|
-
if (shouldTryFallback) yield* yieldUnique(parser.suggest(withChildContext(context, itemIndex, suggestFallbackState), prefix));
|
|
1285
|
+
if (shouldTryFallback) yield* yieldUnique(parser.suggest(require_execution_context.withChildContext(context, itemIndex, suggestFallbackState), prefix));
|
|
1314
1286
|
});
|
|
1315
1287
|
},
|
|
1316
1288
|
getDocFragments(state, defaultValue) {
|
|
@@ -1404,15 +1376,15 @@ function multiple(parser, options = {}) {
|
|
|
1404
1376
|
value(values) {
|
|
1405
1377
|
if (!Array.isArray(values)) {
|
|
1406
1378
|
const actualType = values === null ? "null" : typeof values;
|
|
1407
|
-
return require_mode_dispatch.wrapForMode(parser
|
|
1379
|
+
return require_mode_dispatch.wrapForMode(parser.mode, {
|
|
1408
1380
|
success: false,
|
|
1409
1381
|
error: require_message.message`Expected an array of values, but received ${actualType}.`
|
|
1410
1382
|
});
|
|
1411
1383
|
}
|
|
1412
1384
|
const arity = validateArity(values);
|
|
1413
|
-
if (!arity.success) return require_mode_dispatch.wrapForMode(parser
|
|
1414
|
-
if (innerValidate == null) return require_mode_dispatch.wrapForMode(parser
|
|
1415
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
1385
|
+
if (!arity.success) return require_mode_dispatch.wrapForMode(parser.mode, arity);
|
|
1386
|
+
if (innerValidate == null) return require_mode_dispatch.wrapForMode(parser.mode, arity);
|
|
1387
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => {
|
|
1416
1388
|
let changed = false;
|
|
1417
1389
|
const normalized = [];
|
|
1418
1390
|
for (const v of values) {
|
|
@@ -1530,7 +1502,7 @@ function nonEmpty(parser) {
|
|
|
1530
1502
|
return processNonEmptyResult(result);
|
|
1531
1503
|
};
|
|
1532
1504
|
const nonEmptyParser = {
|
|
1533
|
-
|
|
1505
|
+
mode: parser.mode,
|
|
1534
1506
|
$valueType: parser.$valueType,
|
|
1535
1507
|
$stateType: parser.$stateType,
|
|
1536
1508
|
priority: parser.priority,
|
|
@@ -1547,7 +1519,7 @@ function nonEmpty(parser) {
|
|
|
1547
1519
|
}] : []);
|
|
1548
1520
|
},
|
|
1549
1521
|
parse(context) {
|
|
1550
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
1522
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => parseSync(context), () => parseAsync(context));
|
|
1551
1523
|
},
|
|
1552
1524
|
complete(state, exec) {
|
|
1553
1525
|
return parser.complete(state, exec);
|
package/dist/modifiers.d.cts
CHANGED
package/dist/modifiers.d.ts
CHANGED