@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.js
CHANGED
|
@@ -1,47 +1,13 @@
|
|
|
1
|
-
import { annotateFreshArray, annotationKey, getAnnotations, inheritAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./annotations.js";
|
|
1
|
+
import { annotateFreshArray, annotationKey, getAnnotations, inheritAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./internal/annotations.js";
|
|
2
2
|
import { formatMessage, message, text } from "./message.js";
|
|
3
|
-
import { dispatchByMode, dispatchIterableByMode, mapModeValue, wrapForMode } from "./mode-dispatch.js";
|
|
4
|
-
import {
|
|
5
|
-
import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
|
|
6
|
-
import { defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, unmatchedNonCliDependencySourceStateMarker } from "./parser.js";
|
|
3
|
+
import { dispatchByMode, dispatchIterableByMode, mapModeValue, wrapForMode } from "./internal/mode-dispatch.js";
|
|
4
|
+
import { defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
|
|
7
5
|
import { getDelegatedAnnotationState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeNestedDelegatedAnnotationState } from "./annotation-state.js";
|
|
6
|
+
import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
|
|
7
|
+
import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
|
|
8
|
+
import { composeDependencyMetadata } from "./dependency-metadata.js";
|
|
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: normalizeNestedDelegatedAnnotationState(result.value)
|
|
89
55
|
} : result;
|
|
90
56
|
}
|
|
57
|
+
function shouldRetryOptionalLikeCompatibilityError(error, state) {
|
|
58
|
+
return error instanceof TypeError && state != null && typeof state === "object" && isInjectedAnnotationWrapper(state);
|
|
59
|
+
}
|
|
91
60
|
function completeOptionalLikeSync(parser, state, exec) {
|
|
92
61
|
const hasCarrier = hasDelegatedAnnotationCarrier(state);
|
|
93
62
|
const shouldRetryFalseResult = hasCarrier && isAnnotationWrappedInitialState(state);
|
|
@@ -97,7 +66,7 @@ function completeOptionalLikeSync(parser, state, exec) {
|
|
|
97
66
|
if (!result.success && shouldRetryFalseResult) return run(normalizeDelegatedAnnotationState(state), false);
|
|
98
67
|
return result;
|
|
99
68
|
} catch (error) {
|
|
100
|
-
if (!
|
|
69
|
+
if (!shouldRetryOptionalLikeCompatibilityError(error, state)) throw error;
|
|
101
70
|
return run(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(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(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 wrapForMode(parser
|
|
93
|
+
if (!Array.isArray(state) && !(state != null && typeof state === "object")) return wrapForMode(parser.mode, null);
|
|
125
94
|
const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
126
95
|
const hasCarrier = hasDelegatedAnnotationCarrier(innerState);
|
|
127
96
|
const shouldRetryFalseResult = hasCarrier && isAnnotationWrappedInitialState(innerState);
|
|
128
|
-
return dispatchByMode(parser
|
|
97
|
+
return dispatchByMode(parser.mode, () => {
|
|
129
98
|
try {
|
|
130
99
|
const result = parser.complete(innerState, exec);
|
|
131
100
|
if (result.success) return normalizeOptionalLikePhase2Seed(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 = normalizeDelegatedAnnotationState(innerState);
|
|
146
115
|
const result = parser.complete(fallbackState, exec);
|
|
147
116
|
if (result.success) return normalizeOptionalLikePhase2Seed(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 = normalizeDelegatedAnnotationState(innerState);
|
|
168
137
|
const result = await parser.complete(fallbackState, exec);
|
|
169
138
|
if (result.success) return normalizeOptionalLikePhase2Seed(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 (getAnnotations(outerState) != null && innerState != null && typeof innerState === "object") return
|
|
159
|
+
if (getAnnotations(outerState) != null && innerState != null && typeof innerState === "object") return 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 inheritAnnotations(outerState, initial);
|
|
164
|
+
return initial != null && typeof initial === "object" ? getDelegatedAnnotationState(outerState, initial) : 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 && normalizeDelegatedAnnotationState(previousState) !== 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(normalizeDelegatedAnnotationState(innerState), exec);
|
|
278
250
|
return result;
|
|
279
251
|
} catch (error) {
|
|
280
|
-
if (!
|
|
252
|
+
if (!shouldRetryOptionalLikeCompatibilityError(error, innerState)) throw error;
|
|
281
253
|
return innerCheck(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[unmatchedNonCliDependencySourceStateMarker] === true ? { [unmatchedNonCliDependencySourceStateMarker]: true } : {},
|
|
@@ -366,13 +338,13 @@ function optional(parser) {
|
|
|
366
338
|
return extractOptionalLikePhase2Seed(parser, state, exec);
|
|
367
339
|
},
|
|
368
340
|
parse(context) {
|
|
369
|
-
return dispatchByMode(parser
|
|
341
|
+
return 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 = dispatchByMode(parser
|
|
375
|
-
return mapModeValue(parser
|
|
346
|
+
const innerResult = dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, resolvedInnerState, exec), async () => await completeOptionalLikeAsync(parser, resolvedInnerState, exec));
|
|
347
|
+
return 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 dispatchByMode(parser
|
|
359
|
+
return dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, delegatedState, exec), async () => await completeOptionalLikeAsync(parser, delegatedState, exec));
|
|
388
360
|
}
|
|
389
361
|
if (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 dispatchByMode(parser
|
|
371
|
+
return dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, innerElement, exec), async () => await completeOptionalLikeAsync(parser, innerElement, exec));
|
|
400
372
|
},
|
|
401
373
|
suggest(context, prefix) {
|
|
402
|
-
return dispatchIterableByMode(parser
|
|
374
|
+
return 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 wrapForMode(parser
|
|
399
|
+
if (v === void 0) return 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[unmatchedNonCliDependencySourceStateMarker] === true ? { [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 dispatchByMode(parser
|
|
509
|
+
return 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 = dispatchByMode(parser
|
|
522
|
+
const innerResult = dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, innerState, exec), async () => await completeOptionalLikeAsync(parser, innerState, exec));
|
|
551
523
|
return innerResult;
|
|
552
524
|
}
|
|
553
525
|
if (parser[unmatchedNonCliDependencySourceStateMarker] === true && state != null && typeof state === "object") {
|
|
554
526
|
const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
555
|
-
const innerResult = dispatchByMode(parser
|
|
527
|
+
const innerResult = 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 mapModeValue(parser
|
|
542
|
+
return 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 dispatchByMode(parser
|
|
558
|
+
return dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, innerElement, exec), async () => await completeOptionalLikeAsync(parser, innerElement, exec));
|
|
587
559
|
},
|
|
588
560
|
suggest(context, prefix) {
|
|
589
|
-
return dispatchIterableByMode(parser
|
|
561
|
+
return 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 mapModeValue(parser
|
|
723
|
+
return 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
|
[extractPhase2SeedKey](state, exec) {
|
|
777
|
-
return mapModeValue(parser
|
|
749
|
+
return mapModeValue(parser.mode, completeOrExtractPhase2Seed(parser, state, exec), (seed) => {
|
|
778
750
|
if (seed == null) return null;
|
|
779
751
|
if (seed.deferred) try {
|
|
780
752
|
return {
|
|
@@ -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,10 +1108,10 @@ function multiple(parser, options = {}) {
|
|
|
1136
1108
|
}, ...innerNodes] : innerNodes;
|
|
1137
1109
|
},
|
|
1138
1110
|
parse(context) {
|
|
1139
|
-
return dispatchByMode(parser
|
|
1111
|
+
return dispatchByMode(parser.mode, () => parseSync(context), () => parseAsync(context));
|
|
1140
1112
|
},
|
|
1141
1113
|
complete(state, exec) {
|
|
1142
|
-
return dispatchByMode(parser
|
|
1114
|
+
return dispatchByMode(parser.mode, () => {
|
|
1143
1115
|
const result = [];
|
|
1144
1116
|
const deferredIndices = /* @__PURE__ */ new Map();
|
|
1145
1117
|
let hasDeferred = false;
|
|
@@ -1178,7 +1150,7 @@ function multiple(parser, options = {}) {
|
|
|
1178
1150
|
});
|
|
1179
1151
|
},
|
|
1180
1152
|
[extractPhase2SeedKey](state, exec) {
|
|
1181
|
-
return dispatchByMode(parser
|
|
1153
|
+
return dispatchByMode(parser.mode, () => {
|
|
1182
1154
|
const values = [];
|
|
1183
1155
|
const deferredIndices = /* @__PURE__ */ new Map();
|
|
1184
1156
|
let hasDeferred = false;
|
|
@@ -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 dispatchIterableByMode(parser
|
|
1203
|
+
if (!canExtendCurrent && !canOpenNew) return dispatchIterableByMode(parser.mode, function* () {}, async function* () {});
|
|
1232
1204
|
const itemIndex = canExtendCurrent ? context.state.length - 1 : context.state.length;
|
|
1233
1205
|
const suggestInitialState = canExtendCurrent ? currentItemState : inheritAnnotations(context.state, parser.initialState);
|
|
1234
1206
|
const suggestFallbackState = unwrapInjectedWrapper(suggestInitialState);
|
|
@@ -1271,7 +1243,7 @@ function multiple(parser, options = {}) {
|
|
|
1271
1243
|
description
|
|
1272
1244
|
]);
|
|
1273
1245
|
};
|
|
1274
|
-
return dispatchIterableByMode(parser
|
|
1246
|
+
return dispatchIterableByMode(parser.mode, function* () {
|
|
1275
1247
|
const selectedValues = collectSelectedValuesSync();
|
|
1276
1248
|
const emitted = /* @__PURE__ */ new Set();
|
|
1277
1249
|
const yieldUnique = function* (suggestions) {
|
|
@@ -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 wrapForMode(parser
|
|
1379
|
+
return wrapForMode(parser.mode, {
|
|
1408
1380
|
success: false,
|
|
1409
1381
|
error: message`Expected an array of values, but received ${actualType}.`
|
|
1410
1382
|
});
|
|
1411
1383
|
}
|
|
1412
1384
|
const arity = validateArity(values);
|
|
1413
|
-
if (!arity.success) return wrapForMode(parser
|
|
1414
|
-
if (innerValidate == null) return wrapForMode(parser
|
|
1415
|
-
return dispatchByMode(parser
|
|
1385
|
+
if (!arity.success) return wrapForMode(parser.mode, arity);
|
|
1386
|
+
if (innerValidate == null) return wrapForMode(parser.mode, arity);
|
|
1387
|
+
return 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 dispatchByMode(parser
|
|
1522
|
+
return dispatchByMode(parser.mode, () => parseSync(context), () => parseAsync(context));
|
|
1551
1523
|
},
|
|
1552
1524
|
complete(state, exec) {
|
|
1553
1525
|
return parser.complete(state, exec);
|