@optique/core 1.0.0-dev.1658 → 1.0.0-dev.1661
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/constructs.cjs +485 -112
- package/dist/constructs.js +487 -114
- package/dist/dependency-runtime.cjs +17 -6
- package/dist/dependency-runtime.js +17 -6
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/modifiers.cjs +30 -17
- package/dist/modifiers.js +31 -18
- package/dist/parser.cjs +86 -0
- package/dist/parser.d.cts +54 -1
- package/dist/parser.d.ts +54 -1
- package/dist/parser.js +81 -1
- package/dist/primitives.cjs +18 -14
- package/dist/primitives.js +18 -14
- package/package.json +1 -1
package/dist/constructs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAnnotations, inheritAnnotations, injectAnnotations } from "./annotations.js";
|
|
1
|
+
import { annotateFreshArray, annotationKey, getAnnotations, inheritAnnotations, injectAnnotations } from "./annotations.js";
|
|
2
2
|
import { message, optionName, text, values } from "./message.js";
|
|
3
3
|
import { createDependencySourceState, dependencyId, isDependencySourceState, isPendingDependencySourceState, isWrappedDependencySource, wrappedDependencySourceMarker } from "./dependency.js";
|
|
4
4
|
import { validateLabel } from "./validate.js";
|
|
@@ -7,7 +7,7 @@ import { deduplicateDocFragments } from "./doc.js";
|
|
|
7
7
|
import { dispatchByMode, dispatchIterableByMode } from "./mode-dispatch.js";
|
|
8
8
|
import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, deduplicateSuggestions, findSimilar } from "./suggestion.js";
|
|
9
9
|
import { collectLeadingCandidates } from "./usage-internals.js";
|
|
10
|
-
import { getParserSuggestRuntimeNodes, unmatchedNonCliDependencySourceStateMarker } from "./parser.js";
|
|
10
|
+
import { defineInheritedAnnotationParser, getParserSuggestRuntimeNodes, inheritParentAnnotationsKey, unmatchedNonCliDependencySourceStateMarker } from "./parser.js";
|
|
11
11
|
import { buildRuntimeNodesFromArray, buildRuntimeNodesFromPairs, collectExplicitSourceValues, collectExplicitSourceValuesAsync, collectSourcesFromState, createDependencyRuntimeContext, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync } from "./dependency-runtime.js";
|
|
12
12
|
|
|
13
13
|
//#region src/constructs.ts
|
|
@@ -38,12 +38,13 @@ function mergeChildExec(parent, child) {
|
|
|
38
38
|
excludedSourceFields: child.excludedSourceFields ?? parent.excludedSourceFields
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
function withChildContext(context, segment, state, usage) {
|
|
41
|
+
function withChildContext(context, segment, state, parser, usage) {
|
|
42
42
|
const exec = withChildExecPath(context.exec, segment);
|
|
43
43
|
const dependencyRegistry = context.dependencyRegistry ?? exec?.dependencyRegistry;
|
|
44
|
+
const childState = parser == null ? state : getParseChildState(context.state, state, parser);
|
|
44
45
|
return {
|
|
45
46
|
...context,
|
|
46
|
-
state,
|
|
47
|
+
state: childState,
|
|
47
48
|
...usage != null ? { usage } : {},
|
|
48
49
|
...exec != null ? {
|
|
49
50
|
exec: dependencyRegistry === exec.dependencyRegistry ? exec : {
|
|
@@ -69,6 +70,13 @@ function filterPreCompletedRuntimeNodes(nodes, preCompletedKeys) {
|
|
|
69
70
|
return segment == null || !preCompletedKeys.has(segment);
|
|
70
71
|
});
|
|
71
72
|
}
|
|
73
|
+
function buildIndexedParserPairs(parsers) {
|
|
74
|
+
return parsers.map((parser, index) => [String(index), parser]);
|
|
75
|
+
}
|
|
76
|
+
function createAnnotatedArrayStateRecord(stateArray) {
|
|
77
|
+
const stateRecord = Object.fromEntries(stateArray.map((state, index) => [String(index), state]));
|
|
78
|
+
return inheritAnnotations(stateArray, stateRecord);
|
|
79
|
+
}
|
|
72
80
|
/**
|
|
73
81
|
* Computes the union of `leadingNames` from all given parsers.
|
|
74
82
|
* Used for alternative combinators (`or()`, `longestMatch()`) where all
|
|
@@ -101,7 +109,6 @@ function sharedBufferLeadingNames(parsers) {
|
|
|
101
109
|
}
|
|
102
110
|
return names.size === 0 ? EMPTY_LEADING_NAMES : names;
|
|
103
111
|
}
|
|
104
|
-
const inheritParentAnnotationsKey = Symbol.for("@optique/core/inheritParentAnnotations");
|
|
105
112
|
/**
|
|
106
113
|
* Internal symbol for exposing field-level parser pairs from `object()`
|
|
107
114
|
* and `merge()` parsers. This allows `merge()` to pre-complete dependency
|
|
@@ -116,9 +123,77 @@ const fieldParsersKey = Symbol("fieldParsers");
|
|
|
116
123
|
* to consume results from parsers that still return `DependencySourceState`.
|
|
117
124
|
* @internal
|
|
118
125
|
*/
|
|
126
|
+
function unwrapAnnotationView(value) {
|
|
127
|
+
if (value == null || typeof value !== "object") return value;
|
|
128
|
+
return annotationViewTargets.get(value) ?? value;
|
|
129
|
+
}
|
|
130
|
+
function containsAnnotationView(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
131
|
+
if (value == null || typeof value !== "object") return false;
|
|
132
|
+
const candidate = value;
|
|
133
|
+
if (annotationViewTargets.has(candidate)) return true;
|
|
134
|
+
const source = unwrapAnnotationView(candidate);
|
|
135
|
+
if (seen.has(source)) return false;
|
|
136
|
+
seen.add(source);
|
|
137
|
+
if (Array.isArray(source)) return source.some((item) => containsAnnotationView(item, seen));
|
|
138
|
+
const proto = Object.getPrototypeOf(source);
|
|
139
|
+
if (proto !== Object.prototype && proto !== null) return false;
|
|
140
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
141
|
+
return Reflect.ownKeys(descriptors).some((key) => {
|
|
142
|
+
const descriptor = descriptors[key];
|
|
143
|
+
return descriptor != null && "value" in descriptor ? containsAnnotationView(descriptor.value, seen) : false;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function unwrapNestedAnnotationViews(value, seen = /* @__PURE__ */ new WeakMap()) {
|
|
147
|
+
if (value == null || typeof value !== "object") return value;
|
|
148
|
+
const source = unwrapAnnotationView(value);
|
|
149
|
+
if (seen.has(source)) return seen.get(source);
|
|
150
|
+
if (Array.isArray(source)) {
|
|
151
|
+
let changed$1 = false;
|
|
152
|
+
const clone$1 = [...source];
|
|
153
|
+
seen.set(source, clone$1);
|
|
154
|
+
for (let i = 0; i < source.length; i++) {
|
|
155
|
+
const nextValue = unwrapNestedAnnotationViews(source[i], seen);
|
|
156
|
+
if (nextValue !== source[i]) {
|
|
157
|
+
clone$1[i] = nextValue;
|
|
158
|
+
changed$1 = true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return changed$1 ? clone$1 : source;
|
|
162
|
+
}
|
|
163
|
+
const proto = Object.getPrototypeOf(source);
|
|
164
|
+
if (proto !== Object.prototype && proto !== null) return source;
|
|
165
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
166
|
+
let changed = false;
|
|
167
|
+
const clone = Object.create(proto);
|
|
168
|
+
seen.set(source, clone);
|
|
169
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
170
|
+
const descriptor = descriptors[key];
|
|
171
|
+
if (descriptor != null && "value" in descriptor) {
|
|
172
|
+
const nextValue = unwrapNestedAnnotationViews(descriptor.value, seen);
|
|
173
|
+
if (nextValue !== descriptor.value) {
|
|
174
|
+
descriptors[key] = {
|
|
175
|
+
...descriptor,
|
|
176
|
+
value: nextValue
|
|
177
|
+
};
|
|
178
|
+
changed = true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (!changed) {
|
|
183
|
+
seen.set(source, source);
|
|
184
|
+
return source;
|
|
185
|
+
}
|
|
186
|
+
Object.defineProperties(clone, descriptors);
|
|
187
|
+
return clone;
|
|
188
|
+
}
|
|
119
189
|
function unwrapCompleteResult(result) {
|
|
120
|
-
|
|
121
|
-
return
|
|
190
|
+
const unwrappedResult = isDependencySourceState(result) ? result.result : result;
|
|
191
|
+
if (!unwrappedResult.success || !containsAnnotationView(unwrappedResult.value)) return unwrappedResult;
|
|
192
|
+
const value = unwrapNestedAnnotationViews(unwrappedResult.value);
|
|
193
|
+
return value === unwrappedResult.value ? unwrappedResult : {
|
|
194
|
+
...unwrappedResult,
|
|
195
|
+
value
|
|
196
|
+
};
|
|
122
197
|
}
|
|
123
198
|
/**
|
|
124
199
|
* Prepares a field state for completion by wrapping `undefined` state
|
|
@@ -139,22 +214,81 @@ function prepareStateForCompletion(fieldState, parser) {
|
|
|
139
214
|
}
|
|
140
215
|
/**
|
|
141
216
|
* Returns the field state with parent annotations inherited, respecting
|
|
142
|
-
* the parser's
|
|
143
|
-
*
|
|
144
|
-
*
|
|
217
|
+
* the parser's annotation-inheritance contract. This is the same logic as
|
|
218
|
+
* {@link createFieldStateGetter} inside `object()` but without the per-state
|
|
219
|
+
* cache, for use in module-level helpers like
|
|
145
220
|
* {@link pendingDependencyDefaults}.
|
|
146
221
|
* @internal
|
|
147
222
|
*/
|
|
148
223
|
function getAnnotatedFieldState(parentState, field, parser) {
|
|
149
224
|
const sourceState = parentState != null && typeof parentState === "object" && field in parentState ? parentState[field] : parser.initialState;
|
|
225
|
+
return getAnnotatedChildState(parentState, sourceState, parser);
|
|
226
|
+
}
|
|
227
|
+
const annotationViewTargets = /* @__PURE__ */ new WeakMap();
|
|
228
|
+
function withAnnotationView(state, annotations) {
|
|
229
|
+
const target = unwrapAnnotationView(state);
|
|
230
|
+
const view = new Proxy(target, {
|
|
231
|
+
get(target$1, key) {
|
|
232
|
+
if (key === annotationKey) return annotations;
|
|
233
|
+
const value = Reflect.get(target$1, key, target$1);
|
|
234
|
+
return typeof value === "function" ? value.bind(target$1) : value;
|
|
235
|
+
},
|
|
236
|
+
has(target$1, key) {
|
|
237
|
+
return key === annotationKey || Reflect.has(target$1, key);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
annotationViewTargets.set(view, target);
|
|
241
|
+
return view;
|
|
242
|
+
}
|
|
243
|
+
function getParseChildState(parentState, childState, parser) {
|
|
150
244
|
const annotations = getAnnotations(parentState);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return
|
|
245
|
+
const shouldInheritAnnotations = Reflect.get(parser, inheritParentAnnotationsKey) === true;
|
|
246
|
+
if (childState == null) {
|
|
247
|
+
if (annotations !== void 0 && shouldInheritAnnotations) return injectAnnotations({}, annotations);
|
|
248
|
+
return childState;
|
|
249
|
+
}
|
|
250
|
+
if (annotations === void 0 || typeof childState !== "object" || getAnnotations(childState) === annotations || !shouldInheritAnnotations) return childState;
|
|
251
|
+
const injectedState = injectAnnotations(childState, annotations);
|
|
252
|
+
return getAnnotations(injectedState) === annotations ? injectedState : childState;
|
|
253
|
+
}
|
|
254
|
+
function getObjectParseChildState(parentState, childState, _parser) {
|
|
255
|
+
const annotations = getAnnotations(parentState);
|
|
256
|
+
if (annotations === void 0 || childState == null || typeof childState !== "object" || getAnnotations(childState) === annotations) return childState;
|
|
257
|
+
return inheritAnnotations(parentState, childState);
|
|
258
|
+
}
|
|
259
|
+
function getAnnotatedChildState(parentState, childState, parser) {
|
|
260
|
+
const annotations = getAnnotations(parentState);
|
|
261
|
+
const shouldInheritAnnotations = Reflect.get(parser, inheritParentAnnotationsKey) === true;
|
|
262
|
+
if (childState == null) {
|
|
263
|
+
if (annotations !== void 0 && shouldInheritAnnotations) return injectAnnotations({}, annotations);
|
|
264
|
+
return childState;
|
|
265
|
+
}
|
|
266
|
+
if (typeof childState !== "object") return childState;
|
|
267
|
+
if (annotations === void 0 || getAnnotations(childState) === annotations) return childState;
|
|
268
|
+
if (shouldInheritAnnotations) {
|
|
269
|
+
const injectedState = injectAnnotations(childState, annotations);
|
|
270
|
+
if (getAnnotations(injectedState) === annotations) return injectedState;
|
|
154
271
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
272
|
+
return withAnnotationView(childState, annotations);
|
|
273
|
+
}
|
|
274
|
+
function buildSuggestRuntimeNodesFromPairs(pairs, state, parentPath) {
|
|
275
|
+
const prefix = parentPath ?? [];
|
|
276
|
+
const nodes = [];
|
|
277
|
+
for (const [field, parser] of pairs) {
|
|
278
|
+
const fieldState = Object.hasOwn(state, field) ? state[field] : parser.initialState;
|
|
279
|
+
nodes.push(...getParserSuggestRuntimeNodes(parser, getAnnotatedChildState(state, fieldState, parser), [...prefix, field]));
|
|
280
|
+
}
|
|
281
|
+
return nodes;
|
|
282
|
+
}
|
|
283
|
+
function buildSuggestRuntimeNodesFromArray(parsers, stateArray, parentPath) {
|
|
284
|
+
const prefix = parentPath ?? [];
|
|
285
|
+
const nodes = [];
|
|
286
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
287
|
+
const parser = parsers[i];
|
|
288
|
+
const elementState = i < stateArray.length ? stateArray[i] : void 0;
|
|
289
|
+
nodes.push(...getParserSuggestRuntimeNodes(parser, getAnnotatedChildState(stateArray, elementState, parser), [...prefix, i]));
|
|
290
|
+
}
|
|
291
|
+
return nodes;
|
|
158
292
|
}
|
|
159
293
|
function createUnexpectedInputErrorWithScopedSuggestions(baseError, invalidInput, parsers, customFormatter) {
|
|
160
294
|
const options = /* @__PURE__ */ new Set();
|
|
@@ -918,8 +1052,10 @@ function registerCompletedDependency(completed, registry) {
|
|
|
918
1052
|
* @see https://github.com/dahlia/optique/issues/186
|
|
919
1053
|
* @internal
|
|
920
1054
|
*/
|
|
921
|
-
function* pendingDependencyDefaults(context, parserPairs) {
|
|
1055
|
+
function* pendingDependencyDefaults(context, parserPairs, registry) {
|
|
922
1056
|
for (const [field, fieldParser] of parserPairs) {
|
|
1057
|
+
const sourceId = fieldParser.dependencyMetadata?.source?.sourceId ?? (isWrappedDependencySource(fieldParser) ? fieldParser[wrappedDependencySourceMarker][dependencyId] : isPendingDependencySourceState(fieldParser.initialState) ? fieldParser.initialState[dependencyId] : void 0);
|
|
1058
|
+
if (sourceId != null && registry?.has(sourceId)) continue;
|
|
923
1059
|
const fieldState = context.state != null && typeof context.state === "object" && field in context.state ? context.state[field] : void 0;
|
|
924
1060
|
const annotatedFieldState = getAnnotatedFieldState(context.state, field, fieldParser);
|
|
925
1061
|
if (fieldParser.dependencyMetadata?.source?.getMissingSourceValue != null && isUnmatchedDependencyState(fieldState, fieldParser)) {
|
|
@@ -963,7 +1099,7 @@ function* pendingDependencyDefaults(context, parserPairs) {
|
|
|
963
1099
|
* @internal
|
|
964
1100
|
*/
|
|
965
1101
|
function completeDependencySourceDefaults(context, parserPairs, registry, exec) {
|
|
966
|
-
for (const { parser, state } of pendingDependencyDefaults(context, parserPairs)) {
|
|
1102
|
+
for (const { parser, state } of pendingDependencyDefaults(context, parserPairs, registry)) {
|
|
967
1103
|
const completed = parser.complete(state, exec);
|
|
968
1104
|
const depState = wrapAsDependencySourceState(completed, parser);
|
|
969
1105
|
if (depState) registerCompletedDependency(depState, registry);
|
|
@@ -1000,7 +1136,7 @@ function wrapAsDependencySourceState(completed, parser) {
|
|
|
1000
1136
|
* @internal
|
|
1001
1137
|
*/
|
|
1002
1138
|
async function completeDependencySourceDefaultsAsync(context, parserPairs, registry, exec) {
|
|
1003
|
-
for (const { parser, state } of pendingDependencyDefaults(context, parserPairs)) {
|
|
1139
|
+
for (const { parser, state } of pendingDependencyDefaults(context, parserPairs, registry)) {
|
|
1004
1140
|
const completed = await parser.complete(state, exec);
|
|
1005
1141
|
const depState = wrapAsDependencySourceState(completed, parser);
|
|
1006
1142
|
if (depState) registerCompletedDependency(depState, registry);
|
|
@@ -1194,7 +1330,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1194
1330
|
return state;
|
|
1195
1331
|
};
|
|
1196
1332
|
const inheritedFieldStateCache = /* @__PURE__ */ new WeakMap();
|
|
1197
|
-
const createFieldStateGetter = (parentState) => {
|
|
1333
|
+
const createFieldStateGetter = (parentState, annotateChildState = getAnnotatedChildState) => {
|
|
1198
1334
|
return (field, parser) => {
|
|
1199
1335
|
const fieldKey = field;
|
|
1200
1336
|
const cache = parentState != null && typeof parentState === "object" ? inheritedFieldStateCache.get(parentState) ?? (() => {
|
|
@@ -1204,25 +1340,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1204
1340
|
})() : void 0;
|
|
1205
1341
|
if (cache?.has(fieldKey)) return cache.get(fieldKey);
|
|
1206
1342
|
const sourceState = parentState != null && typeof parentState === "object" && fieldKey in parentState ? parentState[fieldKey] : parser.initialState;
|
|
1207
|
-
const
|
|
1208
|
-
if (sourceState == null) {
|
|
1209
|
-
if (annotations !== void 0 && Reflect.get(parser, inheritParentAnnotationsKey) === true) {
|
|
1210
|
-
const inheritedState$1 = injectAnnotations({}, annotations);
|
|
1211
|
-
cache?.set(fieldKey, inheritedState$1);
|
|
1212
|
-
return inheritedState$1;
|
|
1213
|
-
}
|
|
1214
|
-
cache?.set(fieldKey, sourceState);
|
|
1215
|
-
return sourceState;
|
|
1216
|
-
}
|
|
1217
|
-
if (typeof sourceState !== "object") {
|
|
1218
|
-
cache?.set(fieldKey, sourceState);
|
|
1219
|
-
return sourceState;
|
|
1220
|
-
}
|
|
1221
|
-
if (annotations === void 0 || getAnnotations(sourceState) === annotations) {
|
|
1222
|
-
cache?.set(fieldKey, sourceState);
|
|
1223
|
-
return sourceState;
|
|
1224
|
-
}
|
|
1225
|
-
const inheritedState = Reflect.get(parser, inheritParentAnnotationsKey) === true ? injectAnnotations(sourceState, annotations) : inheritAnnotations(parentState, sourceState);
|
|
1343
|
+
const inheritedState = annotateChildState(parentState, sourceState, parser);
|
|
1226
1344
|
cache?.set(fieldKey, inheritedState);
|
|
1227
1345
|
return inheritedState;
|
|
1228
1346
|
};
|
|
@@ -1251,7 +1369,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1251
1369
|
let madeProgress = true;
|
|
1252
1370
|
while (madeProgress && currentContext.buffer.length > 0) {
|
|
1253
1371
|
madeProgress = false;
|
|
1254
|
-
const getFieldState = createFieldStateGetter(currentContext.state);
|
|
1372
|
+
const getFieldState = createFieldStateGetter(currentContext.state, getObjectParseChildState);
|
|
1255
1373
|
for (const [field, parser] of parserPairs) {
|
|
1256
1374
|
const result = parser.parse(withChildContext(currentContext, field, getFieldState(field, parser)));
|
|
1257
1375
|
if (result.success && result.consumed.length > 0) {
|
|
@@ -1262,7 +1380,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1262
1380
|
optionsTerminated: result.next.optionsTerminated,
|
|
1263
1381
|
state: {
|
|
1264
1382
|
...currentContext.state,
|
|
1265
|
-
[field]: result.next.state
|
|
1383
|
+
[field]: getAnnotatedChildState(currentContext.state, result.next.state, parser)
|
|
1266
1384
|
},
|
|
1267
1385
|
...mergedExec != null ? {
|
|
1268
1386
|
trace: mergedExec.trace,
|
|
@@ -1312,7 +1430,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1312
1430
|
let madeProgress = true;
|
|
1313
1431
|
while (madeProgress && currentContext.buffer.length > 0) {
|
|
1314
1432
|
madeProgress = false;
|
|
1315
|
-
const getFieldState = createFieldStateGetter(currentContext.state);
|
|
1433
|
+
const getFieldState = createFieldStateGetter(currentContext.state, getObjectParseChildState);
|
|
1316
1434
|
for (const [field, parser] of parserPairs) {
|
|
1317
1435
|
const resultOrPromise = parser.parse(withChildContext(currentContext, field, getFieldState(field, parser)));
|
|
1318
1436
|
const result = await resultOrPromise;
|
|
@@ -1324,7 +1442,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1324
1442
|
optionsTerminated: result.next.optionsTerminated,
|
|
1325
1443
|
state: {
|
|
1326
1444
|
...currentContext.state,
|
|
1327
|
-
[field]: result.next.state
|
|
1445
|
+
[field]: getAnnotatedChildState(currentContext.state, result.next.state, parser)
|
|
1328
1446
|
},
|
|
1329
1447
|
...mergedExec != null ? {
|
|
1330
1448
|
trace: mergedExec.trace,
|
|
@@ -1571,49 +1689,226 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1571
1689
|
configurable: true,
|
|
1572
1690
|
enumerable: false
|
|
1573
1691
|
});
|
|
1692
|
+
defineInheritedAnnotationParser(objectParser);
|
|
1574
1693
|
return objectParser;
|
|
1575
1694
|
}
|
|
1576
1695
|
function suggestTupleSync(context, prefix, parsers) {
|
|
1577
1696
|
const suggestions = [];
|
|
1578
|
-
const
|
|
1579
|
-
const
|
|
1697
|
+
const advanced = advanceTupleSuggestContextSync(context, parsers);
|
|
1698
|
+
const advancedContext = advanced.context;
|
|
1699
|
+
const stateArray = advancedContext.state;
|
|
1700
|
+
const runtime = createDependencyRuntimeContext(advancedContext.dependencyRegistry?.clone());
|
|
1580
1701
|
if (stateArray && Array.isArray(stateArray)) {
|
|
1581
|
-
|
|
1702
|
+
const nodes = buildSuggestRuntimeNodesFromArray(parsers, stateArray, advancedContext.exec?.path);
|
|
1703
|
+
collectExplicitSourceValues(nodes, runtime);
|
|
1704
|
+
fillMissingSourceDefaults(nodes, runtime);
|
|
1582
1705
|
collectSourcesFromState(stateArray, runtime);
|
|
1706
|
+
completeDependencySourceDefaults({
|
|
1707
|
+
...advancedContext,
|
|
1708
|
+
state: createAnnotatedArrayStateRecord(stateArray)
|
|
1709
|
+
}, buildIndexedParserPairs(parsers), runtime.registry, advancedContext.exec);
|
|
1583
1710
|
}
|
|
1711
|
+
markFailedTupleSuggestSources(parsers, stateArray, advanced.failedParserIndexes, runtime, advancedContext.exec?.path);
|
|
1584
1712
|
const contextWithRegistry = {
|
|
1585
|
-
...
|
|
1586
|
-
dependencyRegistry: runtime.registry
|
|
1713
|
+
...advancedContext,
|
|
1714
|
+
dependencyRegistry: runtime.registry,
|
|
1715
|
+
...advancedContext.exec != null ? { exec: {
|
|
1716
|
+
...advancedContext.exec,
|
|
1717
|
+
dependencyRuntime: runtime,
|
|
1718
|
+
dependencyRegistry: runtime.registry
|
|
1719
|
+
} } : {}
|
|
1587
1720
|
};
|
|
1588
1721
|
for (let i = 0; i < parsers.length; i++) {
|
|
1589
1722
|
const parser = parsers[i];
|
|
1590
1723
|
const parserState = stateArray && Array.isArray(stateArray) ? stateArray[i] : parser.initialState;
|
|
1591
|
-
const parserSuggestions = parser.suggest(withChildContext(contextWithRegistry, i, parserState), prefix);
|
|
1724
|
+
const parserSuggestions = parser.suggest(withChildContext(contextWithRegistry, i, parserState, parser), prefix);
|
|
1592
1725
|
suggestions.push(...parserSuggestions);
|
|
1593
1726
|
}
|
|
1594
1727
|
return deduplicateSuggestions(suggestions);
|
|
1595
1728
|
}
|
|
1596
1729
|
async function* suggestTupleAsync(context, prefix, parsers) {
|
|
1597
1730
|
const suggestions = [];
|
|
1598
|
-
const
|
|
1599
|
-
const
|
|
1731
|
+
const advanced = await advanceTupleSuggestContextAsync(context, parsers);
|
|
1732
|
+
const advancedContext = advanced.context;
|
|
1733
|
+
const stateArray = advancedContext.state;
|
|
1734
|
+
const runtime = createDependencyRuntimeContext(advancedContext.dependencyRegistry?.clone());
|
|
1600
1735
|
if (stateArray && Array.isArray(stateArray)) {
|
|
1601
|
-
|
|
1736
|
+
const nodes = buildSuggestRuntimeNodesFromArray(parsers, stateArray, advancedContext.exec?.path);
|
|
1737
|
+
await collectExplicitSourceValuesAsync(nodes, runtime);
|
|
1738
|
+
await fillMissingSourceDefaultsAsync(nodes, runtime);
|
|
1602
1739
|
collectSourcesFromState(stateArray, runtime);
|
|
1740
|
+
await completeDependencySourceDefaultsAsync({
|
|
1741
|
+
...advancedContext,
|
|
1742
|
+
state: createAnnotatedArrayStateRecord(stateArray)
|
|
1743
|
+
}, buildIndexedParserPairs(parsers), runtime.registry, advancedContext.exec);
|
|
1603
1744
|
}
|
|
1745
|
+
markFailedTupleSuggestSources(parsers, stateArray, advanced.failedParserIndexes, runtime, advancedContext.exec?.path);
|
|
1604
1746
|
const contextWithRegistry = {
|
|
1605
|
-
...
|
|
1606
|
-
dependencyRegistry: runtime.registry
|
|
1747
|
+
...advancedContext,
|
|
1748
|
+
dependencyRegistry: runtime.registry,
|
|
1749
|
+
...advancedContext.exec != null ? { exec: {
|
|
1750
|
+
...advancedContext.exec,
|
|
1751
|
+
dependencyRuntime: runtime,
|
|
1752
|
+
dependencyRegistry: runtime.registry
|
|
1753
|
+
} } : {}
|
|
1607
1754
|
};
|
|
1608
1755
|
for (let i = 0; i < parsers.length; i++) {
|
|
1609
1756
|
const parser = parsers[i];
|
|
1610
1757
|
const parserState = stateArray && Array.isArray(stateArray) ? stateArray[i] : parser.initialState;
|
|
1611
|
-
const parserSuggestions = parser.suggest(withChildContext(contextWithRegistry, i, parserState), prefix);
|
|
1758
|
+
const parserSuggestions = parser.suggest(withChildContext(contextWithRegistry, i, parserState, parser), prefix);
|
|
1612
1759
|
if (parser.$mode === "async") for await (const s of parserSuggestions) suggestions.push(s);
|
|
1613
1760
|
else suggestions.push(...parserSuggestions);
|
|
1614
1761
|
}
|
|
1615
1762
|
yield* deduplicateSuggestions(suggestions);
|
|
1616
1763
|
}
|
|
1764
|
+
function advanceTupleSuggestContextSync(context, parsers) {
|
|
1765
|
+
let currentContext = context;
|
|
1766
|
+
const matchedParsers = /* @__PURE__ */ new Set();
|
|
1767
|
+
while (currentContext.buffer.length > 0 && matchedParsers.size < parsers.length) {
|
|
1768
|
+
let foundMatch = false;
|
|
1769
|
+
let failedParserIndexes = [];
|
|
1770
|
+
let deepestFailure = 0;
|
|
1771
|
+
const stateArray = Array.isArray(currentContext.state) ? [...currentContext.state] : parsers.map((parser) => parser.initialState);
|
|
1772
|
+
const remainingParsers = parsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
|
|
1773
|
+
for (const [parser, index] of remainingParsers) {
|
|
1774
|
+
const result = parser.parse(withChildContext(currentContext, index, stateArray[index], parser));
|
|
1775
|
+
if (result.success && result.consumed.length > 0) {
|
|
1776
|
+
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((state, idx) => idx === index ? getAnnotatedChildState(currentContext.state, result.next.state, parser) : state));
|
|
1777
|
+
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
1778
|
+
currentContext = {
|
|
1779
|
+
...currentContext,
|
|
1780
|
+
buffer: result.next.buffer,
|
|
1781
|
+
optionsTerminated: result.next.optionsTerminated,
|
|
1782
|
+
state: newStateArray,
|
|
1783
|
+
...mergedExec != null ? {
|
|
1784
|
+
exec: mergedExec,
|
|
1785
|
+
dependencyRegistry: mergedExec.dependencyRegistry
|
|
1786
|
+
} : {}
|
|
1787
|
+
};
|
|
1788
|
+
matchedParsers.add(index);
|
|
1789
|
+
foundMatch = true;
|
|
1790
|
+
break;
|
|
1791
|
+
} else if (!result.success && result.consumed > 0) {
|
|
1792
|
+
if (result.consumed > deepestFailure) {
|
|
1793
|
+
deepestFailure = result.consumed;
|
|
1794
|
+
failedParserIndexes = [index];
|
|
1795
|
+
} else if (result.consumed === deepestFailure) failedParserIndexes.push(index);
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
1799
|
+
const result = parser.parse(withChildContext(currentContext, index, stateArray[index], parser));
|
|
1800
|
+
if (result.success && result.consumed.length < 1) {
|
|
1801
|
+
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((state, idx) => idx === index ? getAnnotatedChildState(currentContext.state, result.next.state, parser) : state));
|
|
1802
|
+
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
1803
|
+
currentContext = {
|
|
1804
|
+
...currentContext,
|
|
1805
|
+
state: newStateArray,
|
|
1806
|
+
...mergedExec != null ? {
|
|
1807
|
+
exec: mergedExec,
|
|
1808
|
+
dependencyRegistry: mergedExec.dependencyRegistry
|
|
1809
|
+
} : {}
|
|
1810
|
+
};
|
|
1811
|
+
matchedParsers.add(index);
|
|
1812
|
+
foundMatch = true;
|
|
1813
|
+
break;
|
|
1814
|
+
} else if (!result.success && result.consumed < 1) {
|
|
1815
|
+
matchedParsers.add(index);
|
|
1816
|
+
foundMatch = true;
|
|
1817
|
+
break;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
if (!foundMatch) return {
|
|
1821
|
+
context: currentContext,
|
|
1822
|
+
failedParserIndexes
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
return {
|
|
1826
|
+
context: currentContext,
|
|
1827
|
+
failedParserIndexes: []
|
|
1828
|
+
};
|
|
1829
|
+
}
|
|
1830
|
+
async function advanceTupleSuggestContextAsync(context, parsers) {
|
|
1831
|
+
let currentContext = context;
|
|
1832
|
+
const matchedParsers = /* @__PURE__ */ new Set();
|
|
1833
|
+
while (currentContext.buffer.length > 0 && matchedParsers.size < parsers.length) {
|
|
1834
|
+
let foundMatch = false;
|
|
1835
|
+
let failedParserIndexes = [];
|
|
1836
|
+
let deepestFailure = 0;
|
|
1837
|
+
const stateArray = Array.isArray(currentContext.state) ? [...currentContext.state] : parsers.map((parser) => parser.initialState);
|
|
1838
|
+
const remainingParsers = parsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
|
|
1839
|
+
for (const [parser, index] of remainingParsers) {
|
|
1840
|
+
const result = await parser.parse(withChildContext(currentContext, index, stateArray[index], parser));
|
|
1841
|
+
if (result.success && result.consumed.length > 0) {
|
|
1842
|
+
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((state, idx) => idx === index ? getAnnotatedChildState(currentContext.state, result.next.state, parser) : state));
|
|
1843
|
+
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
1844
|
+
currentContext = {
|
|
1845
|
+
...currentContext,
|
|
1846
|
+
buffer: result.next.buffer,
|
|
1847
|
+
optionsTerminated: result.next.optionsTerminated,
|
|
1848
|
+
state: newStateArray,
|
|
1849
|
+
...mergedExec != null ? {
|
|
1850
|
+
exec: mergedExec,
|
|
1851
|
+
dependencyRegistry: mergedExec.dependencyRegistry
|
|
1852
|
+
} : {}
|
|
1853
|
+
};
|
|
1854
|
+
matchedParsers.add(index);
|
|
1855
|
+
foundMatch = true;
|
|
1856
|
+
break;
|
|
1857
|
+
} else if (!result.success && result.consumed > 0) {
|
|
1858
|
+
if (result.consumed > deepestFailure) {
|
|
1859
|
+
deepestFailure = result.consumed;
|
|
1860
|
+
failedParserIndexes = [index];
|
|
1861
|
+
} else if (result.consumed === deepestFailure) failedParserIndexes.push(index);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
1865
|
+
const result = await parser.parse(withChildContext(currentContext, index, stateArray[index], parser));
|
|
1866
|
+
if (result.success && result.consumed.length < 1) {
|
|
1867
|
+
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((state, idx) => idx === index ? getAnnotatedChildState(currentContext.state, result.next.state, parser) : state));
|
|
1868
|
+
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
1869
|
+
currentContext = {
|
|
1870
|
+
...currentContext,
|
|
1871
|
+
state: newStateArray,
|
|
1872
|
+
...mergedExec != null ? {
|
|
1873
|
+
exec: mergedExec,
|
|
1874
|
+
dependencyRegistry: mergedExec.dependencyRegistry
|
|
1875
|
+
} : {}
|
|
1876
|
+
};
|
|
1877
|
+
matchedParsers.add(index);
|
|
1878
|
+
foundMatch = true;
|
|
1879
|
+
break;
|
|
1880
|
+
} else if (!result.success && result.consumed < 1) {
|
|
1881
|
+
matchedParsers.add(index);
|
|
1882
|
+
foundMatch = true;
|
|
1883
|
+
break;
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
if (!foundMatch) return {
|
|
1887
|
+
context: currentContext,
|
|
1888
|
+
failedParserIndexes
|
|
1889
|
+
};
|
|
1890
|
+
}
|
|
1891
|
+
return {
|
|
1892
|
+
context: currentContext,
|
|
1893
|
+
failedParserIndexes: []
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
function markFailedTupleSuggestSources(parsers, stateArray, failedParserIndexes, runtime, parentPath) {
|
|
1897
|
+
if (failedParserIndexes.length < 1) return;
|
|
1898
|
+
const prefix = parentPath ?? [];
|
|
1899
|
+
const failedSourceIds = /* @__PURE__ */ new Set();
|
|
1900
|
+
for (const index of failedParserIndexes) {
|
|
1901
|
+
const parser = parsers[index];
|
|
1902
|
+
if (parser == null) continue;
|
|
1903
|
+
const parserState = stateArray && Array.isArray(stateArray) ? stateArray[index] : parser.initialState;
|
|
1904
|
+
const nodes = getParserSuggestRuntimeNodes(parser, getAnnotatedChildState(stateArray, parserState, parser), [...prefix, index]);
|
|
1905
|
+
for (const node of nodes) {
|
|
1906
|
+
const sourceId = node.parser.dependencyMetadata?.source?.sourceId;
|
|
1907
|
+
if (sourceId != null) failedSourceIds.add(sourceId);
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
for (const sourceId of failedSourceIds) runtime.markSourceFailed(sourceId);
|
|
1911
|
+
}
|
|
1617
1912
|
function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
1618
1913
|
const label = typeof labelOrParsers === "string" ? labelOrParsers : void 0;
|
|
1619
1914
|
if (label != null) validateLabel(label);
|
|
@@ -1642,9 +1937,9 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1642
1937
|
const stateArray = currentContext.state;
|
|
1643
1938
|
const remainingParsers = syncParsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
|
|
1644
1939
|
for (const [parser, index] of remainingParsers) {
|
|
1645
|
-
const result = parser.parse(withChildContext(currentContext, index, stateArray[index]));
|
|
1940
|
+
const result = parser.parse(withChildContext(currentContext, index, stateArray[index], parser));
|
|
1646
1941
|
if (result.success && result.consumed.length > 0) {
|
|
1647
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
1942
|
+
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getAnnotatedChildState(currentContext.state, result.next.state, parser) : s));
|
|
1648
1943
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
1649
1944
|
currentContext = {
|
|
1650
1945
|
...currentContext,
|
|
@@ -1663,9 +1958,9 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1663
1958
|
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
1664
1959
|
}
|
|
1665
1960
|
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
1666
|
-
const result = parser.parse(withChildContext(currentContext, index, stateArray[index]));
|
|
1961
|
+
const result = parser.parse(withChildContext(currentContext, index, stateArray[index], parser));
|
|
1667
1962
|
if (result.success && result.consumed.length < 1) {
|
|
1668
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
1963
|
+
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getAnnotatedChildState(currentContext.state, result.next.state, parser) : s));
|
|
1669
1964
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
1670
1965
|
currentContext = {
|
|
1671
1966
|
...currentContext,
|
|
@@ -1708,10 +2003,10 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1708
2003
|
const stateArray = currentContext.state;
|
|
1709
2004
|
const remainingParsers = parsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
|
|
1710
2005
|
for (const [parser, index] of remainingParsers) {
|
|
1711
|
-
const resultOrPromise = parser.parse(withChildContext(currentContext, index, stateArray[index]));
|
|
2006
|
+
const resultOrPromise = parser.parse(withChildContext(currentContext, index, stateArray[index], parser));
|
|
1712
2007
|
const result = await resultOrPromise;
|
|
1713
2008
|
if (result.success && result.consumed.length > 0) {
|
|
1714
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
2009
|
+
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getAnnotatedChildState(currentContext.state, result.next.state, parser) : s));
|
|
1715
2010
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
1716
2011
|
currentContext = {
|
|
1717
2012
|
...currentContext,
|
|
@@ -1730,10 +2025,10 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1730
2025
|
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
1731
2026
|
}
|
|
1732
2027
|
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
1733
|
-
const resultOrPromise = parser.parse(withChildContext(currentContext, index, stateArray[index]));
|
|
2028
|
+
const resultOrPromise = parser.parse(withChildContext(currentContext, index, stateArray[index], parser));
|
|
1734
2029
|
const result = await resultOrPromise;
|
|
1735
2030
|
if (result.success && result.consumed.length < 1) {
|
|
1736
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
2031
|
+
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getAnnotatedChildState(currentContext.state, result.next.state, parser) : s));
|
|
1737
2032
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
1738
2033
|
currentContext = {
|
|
1739
2034
|
...currentContext,
|
|
@@ -1784,8 +2079,8 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1784
2079
|
...exec,
|
|
1785
2080
|
dependencyRuntime: runtime
|
|
1786
2081
|
};
|
|
1787
|
-
const tuplePairs = syncParsers
|
|
1788
|
-
const tupleState =
|
|
2082
|
+
const tuplePairs = buildIndexedParserPairs(syncParsers);
|
|
2083
|
+
const tupleState = createAnnotatedArrayStateRecord(stateArray);
|
|
1789
2084
|
const preCompleted = preCompleteAndRegisterDependencies(tupleState, tuplePairs, runtime.registry, childExec);
|
|
1790
2085
|
collectExplicitSourceValues(filterPreCompletedRuntimeNodes(buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys())), runtime);
|
|
1791
2086
|
const phase3Exec = {
|
|
@@ -1831,8 +2126,8 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1831
2126
|
...exec,
|
|
1832
2127
|
dependencyRuntime: runtime
|
|
1833
2128
|
};
|
|
1834
|
-
const tuplePairs = parsers
|
|
1835
|
-
const tupleState =
|
|
2129
|
+
const tuplePairs = buildIndexedParserPairs(parsers);
|
|
2130
|
+
const tupleState = createAnnotatedArrayStateRecord(stateArray);
|
|
1836
2131
|
const preCompleted = await preCompleteAndRegisterDependenciesAsync(tupleState, tuplePairs, runtime.registry, childExec);
|
|
1837
2132
|
await collectExplicitSourceValuesAsync(filterPreCompletedRuntimeNodes(buildRuntimeNodesFromArray(parsers, stateArray, exec?.path), new Set(preCompleted.keys())), runtime);
|
|
1838
2133
|
const phase3Exec = {
|
|
@@ -1930,6 +2225,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1930
2225
|
configurable: true,
|
|
1931
2226
|
enumerable: false
|
|
1932
2227
|
});
|
|
2228
|
+
defineInheritedAnnotationParser(tupleParser);
|
|
1933
2229
|
return tupleParser;
|
|
1934
2230
|
}
|
|
1935
2231
|
function merge(...args) {
|
|
@@ -2425,6 +2721,7 @@ function merge(...args) {
|
|
|
2425
2721
|
};
|
|
2426
2722
|
}
|
|
2427
2723
|
};
|
|
2724
|
+
defineInheritedAnnotationParser(mergeParser);
|
|
2428
2725
|
return mergeParser;
|
|
2429
2726
|
}
|
|
2430
2727
|
/**
|
|
@@ -2437,17 +2734,26 @@ function buildSuggestRegistry(preParsedContext, parsers) {
|
|
|
2437
2734
|
const stateArray = preParsedContext.state;
|
|
2438
2735
|
const runtime = createDependencyRuntimeContext(preParsedContext.dependencyRegistry?.clone());
|
|
2439
2736
|
if (stateArray && Array.isArray(stateArray)) {
|
|
2440
|
-
const nodes =
|
|
2737
|
+
const nodes = buildSuggestRuntimeNodesFromArray(parsers, stateArray, preParsedContext.exec?.path);
|
|
2441
2738
|
collectExplicitSourceValues(nodes, runtime);
|
|
2442
|
-
collectSourcesFromState(stateArray, runtime);
|
|
2443
2739
|
fillMissingSourceDefaults(nodes, runtime);
|
|
2740
|
+
collectSourcesFromState(stateArray, runtime);
|
|
2741
|
+
completeDependencySourceDefaults({
|
|
2742
|
+
...preParsedContext,
|
|
2743
|
+
state: createAnnotatedArrayStateRecord(stateArray)
|
|
2744
|
+
}, buildIndexedParserPairs(parsers), runtime.registry, preParsedContext.exec);
|
|
2444
2745
|
const prefix = preParsedContext.exec?.path ?? [];
|
|
2445
|
-
for (let i = 0; i < parsers.length; i++) seedSuggestRuntimeFromFieldParsers(parsers[i], stateArray[i], runtime, [...prefix, i]);
|
|
2746
|
+
for (let i = 0; i < parsers.length; i++) seedSuggestRuntimeFromFieldParsers(parsers[i], getAnnotatedChildState(stateArray, stateArray[i], parsers[i]), runtime, [...prefix, i]);
|
|
2446
2747
|
}
|
|
2447
2748
|
return {
|
|
2448
2749
|
context: {
|
|
2449
2750
|
...preParsedContext,
|
|
2450
|
-
dependencyRegistry: runtime.registry
|
|
2751
|
+
dependencyRegistry: runtime.registry,
|
|
2752
|
+
...preParsedContext.exec != null ? { exec: {
|
|
2753
|
+
...preParsedContext.exec,
|
|
2754
|
+
dependencyRuntime: runtime,
|
|
2755
|
+
dependencyRegistry: runtime.registry
|
|
2756
|
+
} } : {}
|
|
2451
2757
|
},
|
|
2452
2758
|
stateArray
|
|
2453
2759
|
};
|
|
@@ -2456,17 +2762,26 @@ async function buildSuggestRegistryAsync(preParsedContext, parsers) {
|
|
|
2456
2762
|
const stateArray = preParsedContext.state;
|
|
2457
2763
|
const runtime = createDependencyRuntimeContext(preParsedContext.dependencyRegistry?.clone());
|
|
2458
2764
|
if (stateArray && Array.isArray(stateArray)) {
|
|
2459
|
-
const nodes =
|
|
2765
|
+
const nodes = buildSuggestRuntimeNodesFromArray(parsers, stateArray, preParsedContext.exec?.path);
|
|
2460
2766
|
await collectExplicitSourceValuesAsync(nodes, runtime);
|
|
2461
|
-
collectSourcesFromState(stateArray, runtime);
|
|
2462
2767
|
await fillMissingSourceDefaultsAsync(nodes, runtime);
|
|
2768
|
+
collectSourcesFromState(stateArray, runtime);
|
|
2769
|
+
await completeDependencySourceDefaultsAsync({
|
|
2770
|
+
...preParsedContext,
|
|
2771
|
+
state: createAnnotatedArrayStateRecord(stateArray)
|
|
2772
|
+
}, buildIndexedParserPairs(parsers), runtime.registry, preParsedContext.exec);
|
|
2463
2773
|
const prefix = preParsedContext.exec?.path ?? [];
|
|
2464
|
-
for (let i = 0; i < parsers.length; i++) await seedSuggestRuntimeFromFieldParsersAsync(parsers[i], stateArray[i], runtime, [...prefix, i]);
|
|
2774
|
+
for (let i = 0; i < parsers.length; i++) await seedSuggestRuntimeFromFieldParsersAsync(parsers[i], getAnnotatedChildState(stateArray, stateArray[i], parsers[i]), runtime, [...prefix, i]);
|
|
2465
2775
|
}
|
|
2466
2776
|
return {
|
|
2467
2777
|
context: {
|
|
2468
2778
|
...preParsedContext,
|
|
2469
|
-
dependencyRegistry: runtime.registry
|
|
2779
|
+
dependencyRegistry: runtime.registry,
|
|
2780
|
+
...preParsedContext.exec != null ? { exec: {
|
|
2781
|
+
...preParsedContext.exec,
|
|
2782
|
+
dependencyRuntime: runtime,
|
|
2783
|
+
dependencyRegistry: runtime.registry
|
|
2784
|
+
} } : {}
|
|
2470
2785
|
},
|
|
2471
2786
|
stateArray
|
|
2472
2787
|
};
|
|
@@ -2477,11 +2792,31 @@ function seedSuggestRuntimeFromFieldParsers(parser, state, runtime, parentPath)
|
|
|
2477
2792
|
const duplicateFieldNames = collectDuplicateFieldNames(rawPairs);
|
|
2478
2793
|
const pairs = filterDuplicateFieldParsers(rawPairs);
|
|
2479
2794
|
const stateRecord = state != null && typeof state === "object" ? state : {};
|
|
2480
|
-
const nodes =
|
|
2795
|
+
const nodes = buildSuggestRuntimeNodesFromPairs(pairs, stateRecord, parentPath);
|
|
2481
2796
|
collectExplicitSourceValues(nodes, runtime);
|
|
2482
|
-
collectSourcesFromState(state, runtime, /* @__PURE__ */ new WeakSet(), duplicateFieldNames);
|
|
2483
2797
|
fillMissingSourceDefaults(nodes, runtime);
|
|
2484
|
-
|
|
2798
|
+
collectSourcesFromState(state, runtime, /* @__PURE__ */ new WeakSet(), duplicateFieldNames);
|
|
2799
|
+
completeDependencySourceDefaults({
|
|
2800
|
+
buffer: [],
|
|
2801
|
+
optionsTerminated: false,
|
|
2802
|
+
state: stateRecord,
|
|
2803
|
+
usage: parser.usage,
|
|
2804
|
+
dependencyRegistry: runtime.registry,
|
|
2805
|
+
exec: {
|
|
2806
|
+
usage: parser.usage,
|
|
2807
|
+
phase: "suggest",
|
|
2808
|
+
path: parentPath,
|
|
2809
|
+
dependencyRuntime: runtime,
|
|
2810
|
+
dependencyRegistry: runtime.registry
|
|
2811
|
+
}
|
|
2812
|
+
}, pairs, runtime.registry, {
|
|
2813
|
+
usage: parser.usage,
|
|
2814
|
+
phase: "suggest",
|
|
2815
|
+
path: parentPath,
|
|
2816
|
+
dependencyRuntime: runtime,
|
|
2817
|
+
dependencyRegistry: runtime.registry
|
|
2818
|
+
});
|
|
2819
|
+
for (const [field, childParser] of pairs) seedSuggestRuntimeFromFieldParsers(childParser, getAnnotatedFieldState(stateRecord, field, childParser), runtime, [...parentPath, field]);
|
|
2485
2820
|
}
|
|
2486
2821
|
async function seedSuggestRuntimeFromFieldParsersAsync(parser, state, runtime, parentPath) {
|
|
2487
2822
|
if (!(fieldParsersKey in parser)) return;
|
|
@@ -2489,11 +2824,31 @@ async function seedSuggestRuntimeFromFieldParsersAsync(parser, state, runtime, p
|
|
|
2489
2824
|
const duplicateFieldNames = collectDuplicateFieldNames(rawPairs);
|
|
2490
2825
|
const pairs = filterDuplicateFieldParsers(rawPairs);
|
|
2491
2826
|
const stateRecord = state != null && typeof state === "object" ? state : {};
|
|
2492
|
-
const nodes =
|
|
2827
|
+
const nodes = buildSuggestRuntimeNodesFromPairs(pairs, stateRecord, parentPath);
|
|
2493
2828
|
await collectExplicitSourceValuesAsync(nodes, runtime);
|
|
2494
|
-
collectSourcesFromState(state, runtime, /* @__PURE__ */ new WeakSet(), duplicateFieldNames);
|
|
2495
2829
|
await fillMissingSourceDefaultsAsync(nodes, runtime);
|
|
2496
|
-
|
|
2830
|
+
collectSourcesFromState(state, runtime, /* @__PURE__ */ new WeakSet(), duplicateFieldNames);
|
|
2831
|
+
await completeDependencySourceDefaultsAsync({
|
|
2832
|
+
buffer: [],
|
|
2833
|
+
optionsTerminated: false,
|
|
2834
|
+
state: stateRecord,
|
|
2835
|
+
usage: parser.usage,
|
|
2836
|
+
dependencyRegistry: runtime.registry,
|
|
2837
|
+
exec: {
|
|
2838
|
+
usage: parser.usage,
|
|
2839
|
+
phase: "suggest",
|
|
2840
|
+
path: parentPath,
|
|
2841
|
+
dependencyRuntime: runtime,
|
|
2842
|
+
dependencyRegistry: runtime.registry
|
|
2843
|
+
}
|
|
2844
|
+
}, pairs, runtime.registry, {
|
|
2845
|
+
usage: parser.usage,
|
|
2846
|
+
phase: "suggest",
|
|
2847
|
+
path: parentPath,
|
|
2848
|
+
dependencyRuntime: runtime,
|
|
2849
|
+
dependencyRegistry: runtime.registry
|
|
2850
|
+
});
|
|
2851
|
+
for (const [field, childParser] of pairs) await seedSuggestRuntimeFromFieldParsersAsync(childParser, getAnnotatedFieldState(stateRecord, field, childParser), runtime, [...parentPath, field]);
|
|
2497
2852
|
}
|
|
2498
2853
|
/**
|
|
2499
2854
|
* This helper replays child parsers in priority order (mirroring
|
|
@@ -2502,7 +2857,7 @@ async function seedSuggestRuntimeFromFieldParsersAsync(parser, state, runtime, p
|
|
|
2502
2857
|
*/
|
|
2503
2858
|
function preParseSuggestContext(context, parsers) {
|
|
2504
2859
|
if (context.buffer.length < 1 || !Array.isArray(context.state)) return context;
|
|
2505
|
-
return preParseSuggestLoop(context, context.state.slice(), parsers);
|
|
2860
|
+
return preParseSuggestLoop(context, annotateFreshArray(context.state, context.state.slice()), parsers);
|
|
2506
2861
|
}
|
|
2507
2862
|
/**
|
|
2508
2863
|
* Async variant of {@link preParseSuggestContext} that awaits async child
|
|
@@ -2511,7 +2866,7 @@ function preParseSuggestContext(context, parsers) {
|
|
|
2511
2866
|
*/
|
|
2512
2867
|
async function preParseSuggestContextAsync(context, parsers) {
|
|
2513
2868
|
if (context.buffer.length < 1 || !Array.isArray(context.state)) return context;
|
|
2514
|
-
return await preParseSuggestLoop(context, context.state.slice(), parsers);
|
|
2869
|
+
return await preParseSuggestLoop(context, annotateFreshArray(context.state, context.state.slice()), parsers);
|
|
2515
2870
|
}
|
|
2516
2871
|
/**
|
|
2517
2872
|
* Shared loop for sync and async concat suggest pre-parse. When a child
|
|
@@ -2547,12 +2902,12 @@ function tryParseSuggestList(context, stateArray, parsers, matchedParsers, remai
|
|
|
2547
2902
|
for (let ri = 0; ri < remaining.length; ri++) {
|
|
2548
2903
|
const [parser, index] = remaining[ri];
|
|
2549
2904
|
const parserState = index < stateArray.length ? stateArray[index] : parser.initialState;
|
|
2550
|
-
const resultOrPromise = parser.parse(withChildContext(context, index, parserState));
|
|
2905
|
+
const resultOrPromise = parser.parse(withChildContext(context, index, parserState, parser));
|
|
2551
2906
|
if (resultOrPromise != null && typeof resultOrPromise === "object" && "then" in resultOrPromise && typeof resultOrPromise.then === "function") {
|
|
2552
2907
|
const tail = remaining.slice(ri + 1);
|
|
2553
2908
|
return resultOrPromise.then((result$1) => {
|
|
2554
2909
|
if (result$1.success && result$1.consumed.length > 0) {
|
|
2555
|
-
stateArray[index] = result$1.next.state;
|
|
2910
|
+
stateArray[index] = getAnnotatedChildState(context.state, result$1.next.state, parser);
|
|
2556
2911
|
matchedParsers.add(index);
|
|
2557
2912
|
const mergedExec = mergeChildExec(context.exec, result$1.next.exec);
|
|
2558
2913
|
return preParseSuggestLoop({
|
|
@@ -2579,7 +2934,7 @@ function tryParseSuggestList(context, stateArray, parsers, matchedParsers, remai
|
|
|
2579
2934
|
}
|
|
2580
2935
|
const result = resultOrPromise;
|
|
2581
2936
|
if (result.success && result.consumed.length > 0) {
|
|
2582
|
-
stateArray[index] = result.next.state;
|
|
2937
|
+
stateArray[index] = getAnnotatedChildState(context.state, result.next.state, parser);
|
|
2583
2938
|
matchedParsers.add(index);
|
|
2584
2939
|
const mergedExec = mergeChildExec(context.exec, result.next.exec);
|
|
2585
2940
|
return {
|
|
@@ -2616,9 +2971,9 @@ function concat(...parsers) {
|
|
|
2616
2971
|
const stateArray = currentContext.state;
|
|
2617
2972
|
const remainingParsers = syncParsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
|
|
2618
2973
|
for (const [parser, index] of remainingParsers) {
|
|
2619
|
-
const result = parser.parse(withChildContext(currentContext, index, stateArray[index]));
|
|
2974
|
+
const result = parser.parse(withChildContext(currentContext, index, stateArray[index], parser));
|
|
2620
2975
|
if (result.success && result.consumed.length > 0) {
|
|
2621
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
2976
|
+
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getAnnotatedChildState(currentContext.state, result.next.state, parser) : s));
|
|
2622
2977
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
2623
2978
|
currentContext = {
|
|
2624
2979
|
...currentContext,
|
|
@@ -2637,9 +2992,9 @@ function concat(...parsers) {
|
|
|
2637
2992
|
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
2638
2993
|
}
|
|
2639
2994
|
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
2640
|
-
const result = parser.parse(withChildContext(currentContext, index, stateArray[index]));
|
|
2995
|
+
const result = parser.parse(withChildContext(currentContext, index, stateArray[index], parser));
|
|
2641
2996
|
if (result.success && result.consumed.length < 1) {
|
|
2642
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
2997
|
+
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getAnnotatedChildState(currentContext.state, result.next.state, parser) : s));
|
|
2643
2998
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
2644
2999
|
currentContext = {
|
|
2645
3000
|
...currentContext,
|
|
@@ -2682,9 +3037,9 @@ function concat(...parsers) {
|
|
|
2682
3037
|
const stateArray = currentContext.state;
|
|
2683
3038
|
const remainingParsers = parsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
|
|
2684
3039
|
for (const [parser, index] of remainingParsers) {
|
|
2685
|
-
const result = await parser.parse(withChildContext(currentContext, index, stateArray[index]));
|
|
3040
|
+
const result = await parser.parse(withChildContext(currentContext, index, stateArray[index], parser));
|
|
2686
3041
|
if (result.success && result.consumed.length > 0) {
|
|
2687
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
3042
|
+
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getAnnotatedChildState(currentContext.state, result.next.state, parser) : s));
|
|
2688
3043
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
2689
3044
|
currentContext = {
|
|
2690
3045
|
...currentContext,
|
|
@@ -2703,9 +3058,9 @@ function concat(...parsers) {
|
|
|
2703
3058
|
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
2704
3059
|
}
|
|
2705
3060
|
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
2706
|
-
const result = await parser.parse(withChildContext(currentContext, index, stateArray[index]));
|
|
3061
|
+
const result = await parser.parse(withChildContext(currentContext, index, stateArray[index], parser));
|
|
2707
3062
|
if (result.success && result.consumed.length < 1) {
|
|
2708
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
3063
|
+
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getAnnotatedChildState(currentContext.state, result.next.state, parser) : s));
|
|
2709
3064
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
2710
3065
|
currentContext = {
|
|
2711
3066
|
...currentContext,
|
|
@@ -2740,7 +3095,14 @@ function concat(...parsers) {
|
|
|
2740
3095
|
const runtime = exec?.dependencyRuntime ?? createDependencyRuntimeContext(exec?.dependencyRegistry);
|
|
2741
3096
|
const childExec = {
|
|
2742
3097
|
...exec,
|
|
2743
|
-
dependencyRuntime: runtime
|
|
3098
|
+
dependencyRuntime: runtime
|
|
3099
|
+
};
|
|
3100
|
+
const concatPairs = buildIndexedParserPairs(syncParsers);
|
|
3101
|
+
const concatState = createAnnotatedArrayStateRecord(stateArray);
|
|
3102
|
+
const preCompleted = preCompleteAndRegisterDependencies(concatState, concatPairs, runtime.registry, childExec);
|
|
3103
|
+
collectExplicitSourceValues(filterPreCompletedRuntimeNodes(buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys())), runtime);
|
|
3104
|
+
const phase3Exec = {
|
|
3105
|
+
...childExec,
|
|
2744
3106
|
preCompletedByParser: void 0
|
|
2745
3107
|
};
|
|
2746
3108
|
const resolvedArray = resolveStateWithRuntime(stateArray, runtime);
|
|
@@ -2749,8 +3111,8 @@ function concat(...parsers) {
|
|
|
2749
3111
|
let hasDeferred = false;
|
|
2750
3112
|
for (let i = 0; i < syncParsers.length; i++) {
|
|
2751
3113
|
const parser = syncParsers[i];
|
|
2752
|
-
const
|
|
2753
|
-
const result = unwrapCompleteResult(parser.complete(
|
|
3114
|
+
const preCompletedResult = preCompleted.get(String(i));
|
|
3115
|
+
const result = preCompletedResult !== void 0 ? unwrapCompleteResult(preCompletedResult) : unwrapCompleteResult(parser.complete(prepareStateForCompletion(resolvedArray[i], parser), withChildExecPath(phase3Exec, i)));
|
|
2754
3116
|
if (!result.success) return result;
|
|
2755
3117
|
const baseIndex = results.length;
|
|
2756
3118
|
if (Array.isArray(result.value)) {
|
|
@@ -2783,7 +3145,14 @@ function concat(...parsers) {
|
|
|
2783
3145
|
const runtime = exec?.dependencyRuntime ?? createDependencyRuntimeContext(exec?.dependencyRegistry);
|
|
2784
3146
|
const childExec = {
|
|
2785
3147
|
...exec,
|
|
2786
|
-
dependencyRuntime: runtime
|
|
3148
|
+
dependencyRuntime: runtime
|
|
3149
|
+
};
|
|
3150
|
+
const concatPairs = buildIndexedParserPairs(parsers);
|
|
3151
|
+
const concatState = createAnnotatedArrayStateRecord(stateArray);
|
|
3152
|
+
const preCompleted = await preCompleteAndRegisterDependenciesAsync(concatState, concatPairs, runtime.registry, childExec);
|
|
3153
|
+
await collectExplicitSourceValuesAsync(filterPreCompletedRuntimeNodes(buildRuntimeNodesFromArray(parsers, stateArray, exec?.path), new Set(preCompleted.keys())), runtime);
|
|
3154
|
+
const phase3Exec = {
|
|
3155
|
+
...childExec,
|
|
2787
3156
|
preCompletedByParser: void 0
|
|
2788
3157
|
};
|
|
2789
3158
|
const resolvedArray = await resolveStateWithRuntimeAsync(stateArray, runtime);
|
|
@@ -2792,8 +3161,8 @@ function concat(...parsers) {
|
|
|
2792
3161
|
let hasDeferred = false;
|
|
2793
3162
|
for (let i = 0; i < parsers.length; i++) {
|
|
2794
3163
|
const parser = parsers[i];
|
|
2795
|
-
const
|
|
2796
|
-
const result = unwrapCompleteResult(await parser.complete(
|
|
3164
|
+
const preCompletedResult = preCompleted.get(String(i));
|
|
3165
|
+
const result = preCompletedResult !== void 0 ? unwrapCompleteResult(preCompletedResult) : unwrapCompleteResult(await parser.complete(prepareStateForCompletion(resolvedArray[i], parser), withChildExecPath(phase3Exec, i)));
|
|
2797
3166
|
if (!result.success) return result;
|
|
2798
3167
|
const baseIndex = results.length;
|
|
2799
3168
|
if (Array.isArray(result.value)) {
|
|
@@ -2821,7 +3190,7 @@ function concat(...parsers) {
|
|
|
2821
3190
|
} : {}
|
|
2822
3191
|
};
|
|
2823
3192
|
};
|
|
2824
|
-
|
|
3193
|
+
const concatParser = {
|
|
2825
3194
|
$mode: combinedMode,
|
|
2826
3195
|
$valueType: [],
|
|
2827
3196
|
$stateType: [],
|
|
@@ -2846,7 +3215,7 @@ function concat(...parsers) {
|
|
|
2846
3215
|
for (let i = 0; i < parsers.length; i++) {
|
|
2847
3216
|
const parser = parsers[i];
|
|
2848
3217
|
const parserState = stateArray$1 && Array.isArray(stateArray$1) ? stateArray$1[i] : parser.initialState;
|
|
2849
|
-
const parserSuggestions = parser.suggest(withChildContext(contextWithRegistry$1, i, parserState), prefix);
|
|
3218
|
+
const parserSuggestions = parser.suggest(withChildContext(contextWithRegistry$1, i, parserState, parser), prefix);
|
|
2850
3219
|
if (parser.$mode === "async") for await (const s of parserSuggestions) suggestions.push(s);
|
|
2851
3220
|
else suggestions.push(...parserSuggestions);
|
|
2852
3221
|
}
|
|
@@ -2859,7 +3228,7 @@ function concat(...parsers) {
|
|
|
2859
3228
|
for (let i = 0; i < syncParsers.length; i++) {
|
|
2860
3229
|
const parser = syncParsers[i];
|
|
2861
3230
|
const parserState = stateArray && Array.isArray(stateArray) ? stateArray[i] : parser.initialState;
|
|
2862
|
-
const parserSuggestions = parser.suggest(withChildContext(contextWithRegistry, i, parserState), prefix);
|
|
3231
|
+
const parserSuggestions = parser.suggest(withChildContext(contextWithRegistry, i, parserState, parser), prefix);
|
|
2863
3232
|
suggestions.push(...parserSuggestions);
|
|
2864
3233
|
}
|
|
2865
3234
|
yield* deduplicateSuggestions(suggestions);
|
|
@@ -2891,6 +3260,8 @@ function concat(...parsers) {
|
|
|
2891
3260
|
return { fragments: result };
|
|
2892
3261
|
}
|
|
2893
3262
|
};
|
|
3263
|
+
defineInheritedAnnotationParser(concatParser);
|
|
3264
|
+
return concatParser;
|
|
2894
3265
|
}
|
|
2895
3266
|
function group(label, parser, options = {}) {
|
|
2896
3267
|
validateLabel(label);
|
|
@@ -3054,7 +3425,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
3054
3425
|
const syncDefaultBranch = defaultBranch;
|
|
3055
3426
|
if (state.selectedBranch !== void 0) {
|
|
3056
3427
|
const branchParser = state.selectedBranch.kind === "default" ? syncDefaultBranch : syncBranches[state.selectedBranch.key];
|
|
3057
|
-
const branchResult = branchParser.parse(withChildContext(context, "_branch", state.branchState, branchParser.usage));
|
|
3428
|
+
const branchResult = branchParser.parse(withChildContext(context, "_branch", state.branchState, branchParser, branchParser.usage));
|
|
3058
3429
|
if (branchResult.success) {
|
|
3059
3430
|
const mergedExec = mergeChildExec(context.exec, branchResult.next.exec);
|
|
3060
3431
|
return {
|
|
@@ -3090,7 +3461,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
3090
3461
|
exec: discriminatorExec,
|
|
3091
3462
|
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
3092
3463
|
} : {}
|
|
3093
|
-
}, "_branch", branchParser.initialState, branchParser.usage),
|
|
3464
|
+
}, "_branch", branchParser.initialState, branchParser, branchParser.usage),
|
|
3094
3465
|
buffer: discriminatorResult.next.buffer,
|
|
3095
3466
|
optionsTerminated: discriminatorResult.next.optionsTerminated
|
|
3096
3467
|
});
|
|
@@ -3141,7 +3512,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
3141
3512
|
}
|
|
3142
3513
|
}
|
|
3143
3514
|
if (syncDefaultBranch !== void 0) {
|
|
3144
|
-
const defaultResult = syncDefaultBranch.parse(withChildContext(context, "_branch", state.branchState ?? syncDefaultBranch.initialState, syncDefaultBranch.usage));
|
|
3515
|
+
const defaultResult = syncDefaultBranch.parse(withChildContext(context, "_branch", state.branchState ?? syncDefaultBranch.initialState, syncDefaultBranch, syncDefaultBranch.usage));
|
|
3145
3516
|
if (defaultResult.success && defaultResult.consumed.length > 0) {
|
|
3146
3517
|
const mergedExec = mergeChildExec(context.exec, defaultResult.next.exec);
|
|
3147
3518
|
return {
|
|
@@ -3172,7 +3543,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
3172
3543
|
const state = context.state ?? initialState;
|
|
3173
3544
|
if (state.selectedBranch !== void 0) {
|
|
3174
3545
|
const branchParser = state.selectedBranch.kind === "default" ? defaultBranch : branches[state.selectedBranch.key];
|
|
3175
|
-
const branchResult = await branchParser.parse(withChildContext(context, "_branch", state.branchState, branchParser.usage));
|
|
3546
|
+
const branchResult = await branchParser.parse(withChildContext(context, "_branch", state.branchState, branchParser, branchParser.usage));
|
|
3176
3547
|
if (branchResult.success) {
|
|
3177
3548
|
const mergedExec = mergeChildExec(context.exec, branchResult.next.exec);
|
|
3178
3549
|
return {
|
|
@@ -3208,7 +3579,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
3208
3579
|
exec: discriminatorExec,
|
|
3209
3580
|
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
3210
3581
|
} : {}
|
|
3211
|
-
}, "_branch", branchParser.initialState, branchParser.usage),
|
|
3582
|
+
}, "_branch", branchParser.initialState, branchParser, branchParser.usage),
|
|
3212
3583
|
buffer: discriminatorResult.next.buffer,
|
|
3213
3584
|
optionsTerminated: discriminatorResult.next.optionsTerminated
|
|
3214
3585
|
});
|
|
@@ -3259,7 +3630,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
3259
3630
|
}
|
|
3260
3631
|
}
|
|
3261
3632
|
if (defaultBranch !== void 0) {
|
|
3262
|
-
const defaultResult = await defaultBranch.parse(withChildContext(context, "_branch", state.branchState ?? defaultBranch.initialState, defaultBranch.usage));
|
|
3633
|
+
const defaultResult = await defaultBranch.parse(withChildContext(context, "_branch", state.branchState ?? defaultBranch.initialState, defaultBranch, defaultBranch.usage));
|
|
3263
3634
|
if (defaultResult.success && defaultResult.consumed.length > 0) {
|
|
3264
3635
|
const mergedExec = mergeChildExec(context.exec, defaultResult.next.exec);
|
|
3265
3636
|
return {
|
|
@@ -3293,7 +3664,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
3293
3664
|
if (state.selectedBranch === void 0) {
|
|
3294
3665
|
if (syncDefaultBranch !== void 0) {
|
|
3295
3666
|
const branchState = state.branchState ?? syncDefaultBranch.initialState;
|
|
3296
|
-
const defaultResult = syncDefaultBranch.complete(branchState, withChildExecPath(exec, "_branch"));
|
|
3667
|
+
const defaultResult = unwrapCompleteResult(syncDefaultBranch.complete(branchState, withChildExecPath(exec, "_branch")));
|
|
3297
3668
|
if (!defaultResult.success) return defaultResult;
|
|
3298
3669
|
return {
|
|
3299
3670
|
success: true,
|
|
@@ -3329,7 +3700,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
3329
3700
|
dependencyRegistry: runtime.registry
|
|
3330
3701
|
};
|
|
3331
3702
|
const discriminatorCompleteResult = state.selectedBranch.kind === "default" ? void 0 : syncDiscriminator.complete(state.discriminatorState, withChildExecPath(completionExec, "_discriminator"));
|
|
3332
|
-
const branchResult = branchParser.complete(resolvedBranchState, withChildExecPath(completionExec, "_branch"));
|
|
3703
|
+
const branchResult = unwrapCompleteResult(branchParser.complete(resolvedBranchState, withChildExecPath(completionExec, "_branch")));
|
|
3333
3704
|
if (!branchResult.success) {
|
|
3334
3705
|
if (state.discriminatorValue !== void 0 && options?.errors?.branchError) return {
|
|
3335
3706
|
success: false,
|
|
@@ -3356,7 +3727,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
3356
3727
|
if (state.selectedBranch === void 0) {
|
|
3357
3728
|
if (defaultBranch !== void 0) {
|
|
3358
3729
|
const branchState = state.branchState ?? defaultBranch.initialState;
|
|
3359
|
-
const defaultResult = await defaultBranch.complete(branchState, withChildExecPath(exec, "_branch"));
|
|
3730
|
+
const defaultResult = unwrapCompleteResult(await defaultBranch.complete(branchState, withChildExecPath(exec, "_branch")));
|
|
3360
3731
|
if (!defaultResult.success) return defaultResult;
|
|
3361
3732
|
return {
|
|
3362
3733
|
success: true,
|
|
@@ -3392,7 +3763,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
3392
3763
|
dependencyRegistry: runtime.registry
|
|
3393
3764
|
};
|
|
3394
3765
|
const discriminatorCompleteResult = state.selectedBranch.kind === "default" ? void 0 : await discriminator.complete(state.discriminatorState, withChildExecPath(completionExec, "_discriminator"));
|
|
3395
|
-
const branchResult = await branchParser.complete(resolvedBranchState, withChildExecPath(completionExec, "_branch"));
|
|
3766
|
+
const branchResult = unwrapCompleteResult(await branchParser.complete(resolvedBranchState, withChildExecPath(completionExec, "_branch")));
|
|
3396
3767
|
if (!branchResult.success) {
|
|
3397
3768
|
if (state.discriminatorValue !== void 0 && options?.errors?.branchError) return {
|
|
3398
3769
|
success: false,
|
|
@@ -3506,7 +3877,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
3506
3877
|
yield* branchParser.suggest(withChildContext(suggestContext, "_branch", state.branchState), prefix);
|
|
3507
3878
|
}
|
|
3508
3879
|
}
|
|
3509
|
-
|
|
3880
|
+
const conditionalParser = {
|
|
3510
3881
|
$mode: combinedMode,
|
|
3511
3882
|
$valueType: [],
|
|
3512
3883
|
$stateType: [],
|
|
@@ -3554,6 +3925,8 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
3554
3925
|
return { fragments };
|
|
3555
3926
|
}
|
|
3556
3927
|
};
|
|
3928
|
+
defineInheritedAnnotationParser(conditionalParser);
|
|
3929
|
+
return conditionalParser;
|
|
3557
3930
|
}
|
|
3558
3931
|
|
|
3559
3932
|
//#endregion
|