@optique/core 1.1.0-dev.2096 → 1.1.0-dev.2146
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 +26 -26
- package/dist/annotation-state.d.cts +133 -1
- package/dist/annotation-state.d.ts +133 -1
- package/dist/annotations.cjs +2 -2
- package/dist/constructs.cjs +141 -73
- package/dist/constructs.js +70 -2
- package/dist/dependency-metadata.cjs +12 -12
- package/dist/dependency-metadata.d.cts +34 -3
- package/dist/dependency-metadata.d.ts +34 -3
- package/dist/dependency-runtime.cjs +37 -13
- package/dist/dependency-runtime.d.cts +197 -2
- package/dist/dependency-runtime.d.ts +197 -2
- package/dist/dependency-runtime.js +22 -1
- package/dist/dependency.cjs +7 -7
- package/dist/displaywidth.d.cts +12 -0
- package/dist/displaywidth.d.ts +12 -0
- package/dist/execution-context.d.cts +23 -0
- package/dist/execution-context.d.ts +23 -0
- package/dist/extension.cjs +14 -14
- package/dist/facade.cjs +46 -36
- package/dist/facade.js +31 -21
- package/dist/index.cjs +22 -21
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/input-trace.d.cts +2 -1
- package/dist/input-trace.d.ts +2 -1
- package/dist/internal/annotations.cjs +3 -0
- package/dist/internal/annotations.d.cts +47 -5
- package/dist/internal/annotations.d.ts +47 -5
- package/dist/internal/annotations.js +1 -1
- package/dist/internal/command-alias.cjs +16 -0
- package/dist/internal/command-alias.js +14 -0
- package/dist/internal/dependency.cjs +131 -0
- package/dist/internal/dependency.d.cts +311 -2
- package/dist/internal/dependency.d.ts +311 -2
- package/dist/internal/dependency.js +119 -1
- package/dist/internal/parser.cjs +35 -13
- package/dist/internal/parser.d.cts +44 -3
- package/dist/internal/parser.d.ts +44 -3
- package/dist/internal/parser.js +28 -6
- package/dist/modifiers.cjs +41 -41
- package/dist/parser.cjs +11 -11
- package/dist/phase2-seed.cjs +2 -2
- package/dist/phase2-seed.d.cts +50 -0
- package/dist/phase2-seed.d.ts +50 -0
- package/dist/primitives.cjs +74 -33
- package/dist/primitives.d.cts +10 -0
- package/dist/primitives.d.ts +10 -0
- package/dist/primitives.js +54 -13
- package/dist/suggestion.cjs +72 -2
- package/dist/suggestion.d.cts +188 -0
- package/dist/suggestion.d.ts +188 -0
- package/dist/suggestion.js +71 -3
- package/dist/usage-internals.cjs +5 -1
- package/dist/usage-internals.js +5 -1
- package/dist/usage.cjs +9 -1
- package/dist/usage.d.cts +14 -0
- package/dist/usage.d.ts +14 -0
- package/dist/usage.js +9 -1
- package/dist/validate.cjs +1 -0
- package/dist/validate.d.cts +99 -0
- package/dist/validate.d.ts +99 -0
- package/dist/validate.js +1 -1
- package/dist/valueparser.cjs +333 -79
- package/dist/valueparser.d.cts +197 -1
- package/dist/valueparser.d.ts +197 -1
- package/dist/valueparser.js +334 -81
- package/package.json +19 -4
|
@@ -475,7 +475,15 @@ declare const unmatchedNonCliDependencySourceStateMarker: unique symbol;
|
|
|
475
475
|
*
|
|
476
476
|
* @internal
|
|
477
477
|
*/
|
|
478
|
-
|
|
478
|
+
declare const inheritParentAnnotationsKey: unique symbol;
|
|
479
|
+
/**
|
|
480
|
+
* Internal marker for wrapper parsers that should only treat annotation-only
|
|
481
|
+
* primitive wrapper states as completable when a nested source-binding wrapper
|
|
482
|
+
* produced them.
|
|
483
|
+
*
|
|
484
|
+
* @internal
|
|
485
|
+
*/
|
|
486
|
+
declare const annotationWrapperRequiresSourceBindingKey: unique symbol;
|
|
479
487
|
/**
|
|
480
488
|
* The context of the parser, which includes the input buffer and the state.
|
|
481
489
|
*
|
|
@@ -823,7 +831,40 @@ declare function suggestSync<T>(parser: Parser<"sync", T, unknown>, args: readon
|
|
|
823
831
|
* @returns The runtime nodes used to seed suggest-time dependency resolution.
|
|
824
832
|
* @internal
|
|
825
833
|
*/
|
|
826
|
-
|
|
834
|
+
declare function getParserSuggestRuntimeNodes<TState>(parser: Parser<Mode, unknown, TState>, state: TState, path: readonly PropertyKey[]): readonly RuntimeNode[];
|
|
835
|
+
/**
|
|
836
|
+
* Returns wrapper-aware suggest-time runtime nodes for parsers that delegate
|
|
837
|
+
* to an inner parser while also exposing their own source metadata.
|
|
838
|
+
*
|
|
839
|
+
* The inner parser's nodes are always preserved so nested wrappers and
|
|
840
|
+
* constructs can continue to seed the dependency runtime recursively. When
|
|
841
|
+
* the outer parser itself owns source metadata, its `(path, parser, state)`
|
|
842
|
+
* node is appended so outer precedence rules still apply.
|
|
843
|
+
*
|
|
844
|
+
* @internal
|
|
845
|
+
*/
|
|
846
|
+
declare function getDelegatingSuggestRuntimeNodes<TInnerState>(innerParser: Parser<Mode, unknown, TInnerState>, outerParser: Parser<Mode, unknown, unknown>, state: unknown, path: readonly PropertyKey[], innerState: TInnerState, outerPosition?: "append" | "prepend"): readonly RuntimeNode[];
|
|
847
|
+
/**
|
|
848
|
+
* Composes source metadata for a wrapper parser while preserving any derived
|
|
849
|
+
* or transform capabilities from the inner parser unchanged.
|
|
850
|
+
*
|
|
851
|
+
* @internal
|
|
852
|
+
*/
|
|
853
|
+
declare function composeWrappedSourceMetadata(dependencyMetadata: ParserDependencyMetadata | undefined, wrapSource: (source: NonNullable<ParserDependencyMetadata["source"]>) => NonNullable<ParserDependencyMetadata["source"]>): ParserDependencyMetadata | undefined;
|
|
854
|
+
/**
|
|
855
|
+
* Marks a parser as inheriting parent-state annotations through wrapper-state
|
|
856
|
+
* reconstruction.
|
|
857
|
+
*
|
|
858
|
+
* @internal
|
|
859
|
+
*/
|
|
860
|
+
declare function defineInheritedAnnotationParser(parser: object): void;
|
|
861
|
+
/**
|
|
862
|
+
* Marks a wrapper parser as requiring a real source-binding state before
|
|
863
|
+
* annotation-only primitive wrappers should trigger completion.
|
|
864
|
+
*
|
|
865
|
+
* @internal
|
|
866
|
+
*/
|
|
867
|
+
declare function defineSourceBindingOnlyAnnotationCompletionParser(parser: object): void;
|
|
827
868
|
/**
|
|
828
869
|
* Generates command-line suggestions based on current parsing state.
|
|
829
870
|
* This function processes the input arguments up to the last argument,
|
|
@@ -958,4 +999,4 @@ declare function getDocPage(parser: Parser<"sync", unknown, unknown>, argsOrOpti
|
|
|
958
999
|
declare function getDocPage(parser: Parser<"async", unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): Promise<DocPage | undefined>;
|
|
959
1000
|
declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): ModeValue<M, DocPage | undefined>;
|
|
960
1001
|
//#endregion
|
|
961
|
-
export { CombineModes, DocState, ExecutionContext, ExecutionPhase, InferMode, InferValue, Mode, ModeIterable, ModeValue, ParseFrame, Parser, ParserContext, ParserResult, Result, Suggestion, createParserContext, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync };
|
|
1002
|
+
export { CombineModes, DocState, ExecutionContext, ExecutionPhase, InferMode, InferValue, Mode, ModeIterable, ModeValue, ParseFrame, type ParseOptions, Parser, ParserContext, ParserResult, Result, Suggestion, annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, createParserContext, defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, getDelegatingSuggestRuntimeNodes, getDocPage, getDocPageAsync, getDocPageSync, getParserSuggestRuntimeNodes, inheritParentAnnotationsKey, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync, unmatchedNonCliDependencySourceStateMarker };
|
package/dist/internal/parser.js
CHANGED
|
@@ -123,6 +123,7 @@ function parseSync(parser, args, options) {
|
|
|
123
123
|
phase: "complete",
|
|
124
124
|
dependencyRuntime: runtime,
|
|
125
125
|
dependencyRegistry: runtime.registry,
|
|
126
|
+
commandPath: context.exec?.commandPath ?? exec.commandPath,
|
|
126
127
|
trace: context.exec?.trace ?? context.trace ?? exec.trace
|
|
127
128
|
};
|
|
128
129
|
const endResult = parser.complete(context.state, completeExec);
|
|
@@ -195,6 +196,7 @@ async function parseAsync(parser, args, options) {
|
|
|
195
196
|
phase: "complete",
|
|
196
197
|
dependencyRuntime: runtime,
|
|
197
198
|
dependencyRegistry: runtime.registry,
|
|
199
|
+
commandPath: context.exec?.commandPath ?? exec.commandPath,
|
|
198
200
|
trace: context.exec?.trace ?? context.trace ?? exec.trace
|
|
199
201
|
};
|
|
200
202
|
const endResult = await parser.complete(context.state, completeExec);
|
|
@@ -534,7 +536,7 @@ function findCommandInUsageSequence(usage, commandName) {
|
|
|
534
536
|
* @returns The contextual usage terms if found, null otherwise.
|
|
535
537
|
*/
|
|
536
538
|
function findCommandInCurrentUsageTerm(term, commandName, trailingUsage) {
|
|
537
|
-
if (term.type === "command" && term
|
|
539
|
+
if (term.type === "command" && commandTermMatches(term, commandName)) return [term, ...trailingUsage];
|
|
538
540
|
if (term.type === "exclusive") {
|
|
539
541
|
const found = findCommandInExclusive(term, commandName);
|
|
540
542
|
if (found) return [...found, ...trailingUsage];
|
|
@@ -544,7 +546,27 @@ function findCommandInCurrentUsageTerm(term, commandName, trailingUsage) {
|
|
|
544
546
|
}
|
|
545
547
|
return null;
|
|
546
548
|
}
|
|
547
|
-
function
|
|
549
|
+
function commandTermMatches(term, commandName) {
|
|
550
|
+
return term?.type === "command" && (term.name === commandName || term.aliases?.includes(commandName) === true || term.hiddenAliases?.includes(commandName) === true);
|
|
551
|
+
}
|
|
552
|
+
function collectCommandInputNames(usage, commandName, names) {
|
|
553
|
+
for (const term of usage) if (term.type === "command") {
|
|
554
|
+
if (commandTermMatches(term, commandName)) {
|
|
555
|
+
names.add(term.name);
|
|
556
|
+
for (const alias of term.aliases ?? []) names.add(alias);
|
|
557
|
+
for (const alias of term.hiddenAliases ?? []) names.add(alias);
|
|
558
|
+
}
|
|
559
|
+
} else if (term.type === "exclusive") for (const branch of term.terms) collectCommandInputNames(branch, commandName, names);
|
|
560
|
+
else if (term.type === "sequence") collectCommandInputNames(term.terms, commandName, names);
|
|
561
|
+
else if (term.type === "optional" || term.type === "multiple") collectCommandInputNames(term.terms, commandName, names);
|
|
562
|
+
}
|
|
563
|
+
function findLastCommandInputIndex(consumed, commandName, usage, searchEnd) {
|
|
564
|
+
const names = new Set([commandName]);
|
|
565
|
+
collectCommandInputNames(usage, commandName, names);
|
|
566
|
+
for (let index = searchEnd - 1; index >= 0; index--) if (names.has(consumed[index])) return index;
|
|
567
|
+
return -1;
|
|
568
|
+
}
|
|
569
|
+
function recordMatchedCommandArgIndices(usage, consumed, previousCommandPath, nextCommandPath, consumedOffset, indices) {
|
|
548
570
|
const previousLength = previousCommandPath?.length ?? 0;
|
|
549
571
|
const next = nextCommandPath ?? [];
|
|
550
572
|
if (next.length <= previousLength || consumed.length < 1) return;
|
|
@@ -552,7 +574,7 @@ function recordMatchedCommandArgIndices(consumed, previousCommandPath, nextComma
|
|
|
552
574
|
for (let index = next.length - 1; index >= previousLength; index--) {
|
|
553
575
|
if (searchEnd <= 0) break;
|
|
554
576
|
const commandName = next[index];
|
|
555
|
-
const localIndex = consumed
|
|
577
|
+
const localIndex = findLastCommandInputIndex(consumed, commandName, usage, searchEnd);
|
|
556
578
|
if (localIndex < 0) continue;
|
|
557
579
|
indices.add(consumedOffset + localIndex);
|
|
558
580
|
searchEnd = localIndex;
|
|
@@ -636,7 +658,7 @@ function getDocPageSyncImpl(parser, args, options) {
|
|
|
636
658
|
const previousBuffer = context.buffer;
|
|
637
659
|
context = result.next;
|
|
638
660
|
const consumedCount = previousBuffer.length - context.buffer.length;
|
|
639
|
-
recordMatchedCommandArgIndices(previousBuffer.slice(0, consumedCount), previousCommandPath, context.exec?.commandPath, args.length - previousBuffer.length, matchedCommandArgIndices);
|
|
661
|
+
recordMatchedCommandArgIndices(parser.usage, previousBuffer.slice(0, consumedCount), previousCommandPath, context.exec?.commandPath, args.length - previousBuffer.length, matchedCommandArgIndices);
|
|
640
662
|
if (isBufferUnchanged(previousBuffer, context.buffer)) break;
|
|
641
663
|
}
|
|
642
664
|
return buildDocPage(parser, context, args, matchedCommandArgIndices);
|
|
@@ -665,7 +687,7 @@ async function getDocPageAsyncImpl(parser, args, options) {
|
|
|
665
687
|
const previousBuffer = context.buffer;
|
|
666
688
|
context = result.next;
|
|
667
689
|
const consumedCount = previousBuffer.length - context.buffer.length;
|
|
668
|
-
recordMatchedCommandArgIndices(previousBuffer.slice(0, consumedCount), previousCommandPath, context.exec?.commandPath, args.length - previousBuffer.length, matchedCommandArgIndices);
|
|
690
|
+
recordMatchedCommandArgIndices(parser.usage, previousBuffer.slice(0, consumedCount), previousCommandPath, context.exec?.commandPath, args.length - previousBuffer.length, matchedCommandArgIndices);
|
|
669
691
|
if (isBufferUnchanged(previousBuffer, context.buffer)) break;
|
|
670
692
|
}
|
|
671
693
|
return buildDocPage(parser, context, args, matchedCommandArgIndices);
|
|
@@ -725,7 +747,7 @@ function buildDocPage(parser, context, args, matchedCommandArgIndices) {
|
|
|
725
747
|
const sections = buildingSections;
|
|
726
748
|
const usage = [...normalizeUsage(parser.usage)];
|
|
727
749
|
const maybeApplyCommandUsageLine = (term, arg, isLastArg, usageIndex) => {
|
|
728
|
-
if (term?.type !== "command" || term
|
|
750
|
+
if (term?.type !== "command" || !commandTermMatches(term, arg) || !isLastArg || term.usageLine == null) return;
|
|
729
751
|
const defaultUsageLine = cloneUsage(usage.slice(usageIndex + 1));
|
|
730
752
|
const customUsageLine = typeof term.usageLine === "function" ? term.usageLine(defaultUsageLine) : term.usageLine;
|
|
731
753
|
const normalizedCustomUsageLine = normalizeUsage(customUsageLine);
|
package/dist/modifiers.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_internal_annotations = require('./internal/annotations.cjs');
|
|
2
2
|
const require_message = require('./message.cjs');
|
|
3
3
|
const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
|
|
4
|
-
const
|
|
4
|
+
const require_internal_parser = require('./internal/parser.cjs');
|
|
5
5
|
const require_annotation_state = require('./annotation-state.cjs');
|
|
6
6
|
const require_execution_context = require('./execution-context.cjs');
|
|
7
7
|
const require_phase2_seed = require('./phase2-seed.cjs');
|
|
@@ -31,8 +31,8 @@ function unwrapMultipleItemState(state) {
|
|
|
31
31
|
let unwrapped = state;
|
|
32
32
|
let viaBoundCliWrapper = false;
|
|
33
33
|
while (true) {
|
|
34
|
-
if (
|
|
35
|
-
unwrapped =
|
|
34
|
+
if (require_internal_annotations.isInjectedAnnotationWrapper(unwrapped)) {
|
|
35
|
+
unwrapped = require_internal_annotations.unwrapInjectedAnnotationWrapper(unwrapped);
|
|
36
36
|
continue;
|
|
37
37
|
}
|
|
38
38
|
if (Array.isArray(unwrapped) && unwrapped.length === 1) {
|
|
@@ -60,7 +60,7 @@ function normalizeOptionalLikeCompleteResult(result, shouldNormalize) {
|
|
|
60
60
|
} : result;
|
|
61
61
|
}
|
|
62
62
|
function shouldRetryOptionalLikeCompatibilityError(error, state) {
|
|
63
|
-
return error instanceof TypeError && state != null && typeof state === "object" &&
|
|
63
|
+
return error instanceof TypeError && state != null && typeof state === "object" && require_internal_annotations.isInjectedAnnotationWrapper(state);
|
|
64
64
|
}
|
|
65
65
|
function completeOptionalLikeSync(parser, state, exec) {
|
|
66
66
|
const hasCarrier = require_annotation_state.hasDelegatedAnnotationCarrier(state);
|
|
@@ -161,12 +161,12 @@ function extractOptionalLikePhase2Seed(parser, state, exec) {
|
|
|
161
161
|
function deriveOptionalInnerParseState(outerState, parser) {
|
|
162
162
|
if (Array.isArray(outerState)) {
|
|
163
163
|
const innerState = outerState[0];
|
|
164
|
-
if (
|
|
164
|
+
if (require_internal_annotations.getAnnotations(outerState) != null && innerState != null && typeof innerState === "object") return require_annotation_state.getDelegatedAnnotationState(outerState, innerState);
|
|
165
165
|
return innerState;
|
|
166
166
|
}
|
|
167
167
|
const initial = parser.initialState;
|
|
168
168
|
if (initial != null && typeof initial !== "object") return initial;
|
|
169
|
-
return initial != null && typeof initial === "object" ? require_annotation_state.getDelegatedAnnotationState(outerState, initial) :
|
|
169
|
+
return initial != null && typeof initial === "object" ? require_annotation_state.getDelegatedAnnotationState(outerState, initial) : require_internal_annotations.inheritAnnotations(outerState, initial);
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
172
172
|
* Internal helper for optional-style parsing logic shared by optional()
|
|
@@ -262,9 +262,9 @@ function adaptShouldDeferCompletion(innerCheck, parser) {
|
|
|
262
262
|
};
|
|
263
263
|
}
|
|
264
264
|
function isAnnotationOnlyObjectState(state) {
|
|
265
|
-
if (state == null || typeof state !== "object" || Array.isArray(state) ||
|
|
265
|
+
if (state == null || typeof state !== "object" || Array.isArray(state) || require_internal_annotations.isInjectedAnnotationWrapper(state)) return false;
|
|
266
266
|
const keys = Reflect.ownKeys(state);
|
|
267
|
-
return
|
|
267
|
+
return require_internal_annotations.getAnnotations(state) != null && keys.length === 1 && keys[0] === require_internal_annotations.annotationKey;
|
|
268
268
|
}
|
|
269
269
|
function normalizeOptionalLikeInnerState(state, initialState, parser) {
|
|
270
270
|
if (Array.isArray(state)) return require_annotation_state.getDelegatedAnnotationState(state, state[0]);
|
|
@@ -315,7 +315,7 @@ function optional(parser) {
|
|
|
315
315
|
mode: parser.mode,
|
|
316
316
|
$valueType: [],
|
|
317
317
|
$stateType: [],
|
|
318
|
-
...parser[
|
|
318
|
+
...parser[require_internal_parser.unmatchedNonCliDependencySourceStateMarker] === true ? { [require_internal_parser.unmatchedNonCliDependencySourceStateMarker]: true } : {},
|
|
319
319
|
placeholder: void 0,
|
|
320
320
|
priority: parser.priority,
|
|
321
321
|
usage: [{
|
|
@@ -368,7 +368,7 @@ function optional(parser) {
|
|
|
368
368
|
const delegatedState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
369
369
|
return require_mode_dispatch.dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, delegatedState, exec), async () => await completeOptionalLikeAsync(parser, delegatedState, exec));
|
|
370
370
|
}
|
|
371
|
-
if (parser[
|
|
371
|
+
if (parser[require_internal_parser.unmatchedNonCliDependencySourceStateMarker] === true && state != null && typeof state === "object") {
|
|
372
372
|
const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
373
373
|
return delegateToInner(innerState);
|
|
374
374
|
}
|
|
@@ -420,8 +420,8 @@ function optional(parser) {
|
|
|
420
420
|
const composed = require_dependency_metadata.composeDependencyMetadata(parser.dependencyMetadata, "optional");
|
|
421
421
|
if (composed != null) optionalParser.dependencyMetadata = composed;
|
|
422
422
|
}
|
|
423
|
-
|
|
424
|
-
|
|
423
|
+
require_internal_parser.defineInheritedAnnotationParser(optionalParser);
|
|
424
|
+
require_internal_parser.defineSourceBindingOnlyAnnotationCompletionParser(optionalParser);
|
|
425
425
|
return optionalParser;
|
|
426
426
|
}
|
|
427
427
|
/**
|
|
@@ -489,7 +489,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
489
489
|
mode: parser.mode,
|
|
490
490
|
$valueType: [],
|
|
491
491
|
$stateType: [],
|
|
492
|
-
...parser[
|
|
492
|
+
...parser[require_internal_parser.unmatchedNonCliDependencySourceStateMarker] === true ? { [require_internal_parser.unmatchedNonCliDependencySourceStateMarker]: true } : {},
|
|
493
493
|
priority: parser.priority,
|
|
494
494
|
usage: [{
|
|
495
495
|
type: "optional",
|
|
@@ -537,7 +537,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
537
537
|
const innerResult = require_mode_dispatch.dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, innerState, exec), async () => await completeOptionalLikeAsync(parser, innerState, exec));
|
|
538
538
|
return innerResult;
|
|
539
539
|
}
|
|
540
|
-
if (parser[
|
|
540
|
+
if (parser[require_internal_parser.unmatchedNonCliDependencySourceStateMarker] === true && state != null && typeof state === "object") {
|
|
541
541
|
const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
542
542
|
const innerResult = require_mode_dispatch.dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, innerState, exec), async () => await completeOptionalLikeAsync(parser, innerState, exec));
|
|
543
543
|
const handleInnerResult = (result) => {
|
|
@@ -654,8 +654,8 @@ function withDefault(parser, defaultValue, options) {
|
|
|
654
654
|
} });
|
|
655
655
|
if (composed != null) withDefaultParser.dependencyMetadata = composed;
|
|
656
656
|
}
|
|
657
|
-
|
|
658
|
-
|
|
657
|
+
require_internal_parser.defineInheritedAnnotationParser(withDefaultParser);
|
|
658
|
+
require_internal_parser.defineSourceBindingOnlyAnnotationCompletionParser(withDefaultParser);
|
|
659
659
|
return withDefaultParser;
|
|
660
660
|
}
|
|
661
661
|
/**
|
|
@@ -863,27 +863,27 @@ function map(parser, transform) {
|
|
|
863
863
|
function multiple(parser, options = {}) {
|
|
864
864
|
const syncParser = parser;
|
|
865
865
|
const { min = 0, max = Infinity } = options;
|
|
866
|
-
const unwrapInjectedWrapper =
|
|
866
|
+
const unwrapInjectedWrapper = require_internal_annotations.unwrapInjectedAnnotationWrapper;
|
|
867
867
|
const completeSyncWithUnwrappedFallback = (state, exec) => {
|
|
868
868
|
try {
|
|
869
869
|
const result = syncParser.complete(state, exec);
|
|
870
|
-
if (!result.success &&
|
|
870
|
+
if (!result.success && require_internal_annotations.isInjectedAnnotationWrapper(state)) return syncParser.complete(unwrapInjectedWrapper(state), exec);
|
|
871
871
|
return result;
|
|
872
872
|
} catch (error) {
|
|
873
|
-
if (!
|
|
873
|
+
if (!require_internal_annotations.isInjectedAnnotationWrapper(state)) throw error;
|
|
874
874
|
return syncParser.complete(unwrapInjectedWrapper(state), exec);
|
|
875
875
|
}
|
|
876
876
|
};
|
|
877
877
|
const parseSyncWithUnwrappedFallback = (context) => {
|
|
878
878
|
try {
|
|
879
879
|
const result = syncParser.parse(context);
|
|
880
|
-
if (result.success || result.consumed !== 0 || !
|
|
880
|
+
if (result.success || result.consumed !== 0 || !require_internal_annotations.isInjectedAnnotationWrapper(context.state)) return result;
|
|
881
881
|
return syncParser.parse({
|
|
882
882
|
...context,
|
|
883
883
|
state: unwrapInjectedWrapper(context.state)
|
|
884
884
|
});
|
|
885
885
|
} catch (error) {
|
|
886
|
-
if (!
|
|
886
|
+
if (!require_internal_annotations.isInjectedAnnotationWrapper(context.state)) throw error;
|
|
887
887
|
return syncParser.parse({
|
|
888
888
|
...context,
|
|
889
889
|
state: unwrapInjectedWrapper(context.state)
|
|
@@ -893,23 +893,23 @@ function multiple(parser, options = {}) {
|
|
|
893
893
|
const completeAsyncWithUnwrappedFallback = async (state, exec) => {
|
|
894
894
|
try {
|
|
895
895
|
const result = await parser.complete(state, exec);
|
|
896
|
-
if (!result.success &&
|
|
896
|
+
if (!result.success && require_internal_annotations.isInjectedAnnotationWrapper(state)) return await parser.complete(unwrapInjectedWrapper(state), exec);
|
|
897
897
|
return result;
|
|
898
898
|
} catch (error) {
|
|
899
|
-
if (!
|
|
899
|
+
if (!require_internal_annotations.isInjectedAnnotationWrapper(state)) throw error;
|
|
900
900
|
return await parser.complete(unwrapInjectedWrapper(state), exec);
|
|
901
901
|
}
|
|
902
902
|
};
|
|
903
903
|
const parseAsyncWithUnwrappedFallback = async (context) => {
|
|
904
904
|
try {
|
|
905
905
|
const result = await parser.parse(context);
|
|
906
|
-
if (result.success || result.consumed !== 0 || !
|
|
906
|
+
if (result.success || result.consumed !== 0 || !require_internal_annotations.isInjectedAnnotationWrapper(context.state)) return result;
|
|
907
907
|
return await parser.parse({
|
|
908
908
|
...context,
|
|
909
909
|
state: unwrapInjectedWrapper(context.state)
|
|
910
910
|
});
|
|
911
911
|
} catch (error) {
|
|
912
|
-
if (!
|
|
912
|
+
if (!require_internal_annotations.isInjectedAnnotationWrapper(context.state)) throw error;
|
|
913
913
|
return await parser.parse({
|
|
914
914
|
...context,
|
|
915
915
|
state: unwrapInjectedWrapper(context.state)
|
|
@@ -919,20 +919,20 @@ function multiple(parser, options = {}) {
|
|
|
919
919
|
const extractPhase2SeedSyncWithUnwrappedFallback = (state, exec) => {
|
|
920
920
|
try {
|
|
921
921
|
const seed = require_phase2_seed.completeOrExtractPhase2Seed(syncParser, state, exec);
|
|
922
|
-
if (seed == null &&
|
|
922
|
+
if (seed == null && require_internal_annotations.isInjectedAnnotationWrapper(state)) return require_phase2_seed.completeOrExtractPhase2Seed(syncParser, unwrapInjectedWrapper(state), exec);
|
|
923
923
|
return seed;
|
|
924
924
|
} catch (error) {
|
|
925
|
-
if (!
|
|
925
|
+
if (!require_internal_annotations.isInjectedAnnotationWrapper(state)) throw error;
|
|
926
926
|
return require_phase2_seed.completeOrExtractPhase2Seed(syncParser, unwrapInjectedWrapper(state), exec);
|
|
927
927
|
}
|
|
928
928
|
};
|
|
929
929
|
const extractPhase2SeedAsyncWithUnwrappedFallback = async (state, exec) => {
|
|
930
930
|
try {
|
|
931
931
|
const seed = await require_phase2_seed.completeOrExtractPhase2Seed(parser, state, exec);
|
|
932
|
-
if (seed == null &&
|
|
932
|
+
if (seed == null && require_internal_annotations.isInjectedAnnotationWrapper(state)) return await require_phase2_seed.completeOrExtractPhase2Seed(parser, unwrapInjectedWrapper(state), exec);
|
|
933
933
|
return seed;
|
|
934
934
|
} catch (error) {
|
|
935
|
-
if (!
|
|
935
|
+
if (!require_internal_annotations.isInjectedAnnotationWrapper(state)) throw error;
|
|
936
936
|
return await require_phase2_seed.completeOrExtractPhase2Seed(parser, unwrapInjectedWrapper(state), exec);
|
|
937
937
|
}
|
|
938
938
|
};
|
|
@@ -954,12 +954,12 @@ function multiple(parser, options = {}) {
|
|
|
954
954
|
};
|
|
955
955
|
let added = !canExtendCurrent;
|
|
956
956
|
let itemIndex = canExtendCurrent ? context.state.length - 1 : context.state.length;
|
|
957
|
-
const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState :
|
|
957
|
+
const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState : require_internal_annotations.inheritAnnotations(context.state, syncParser.initialState);
|
|
958
958
|
let result = parseSyncWithUnwrappedFallback(require_execution_context.withChildContext(context, itemIndex, currentItemStateWithAnnotations));
|
|
959
959
|
if (!result.success) {
|
|
960
960
|
if (result.consumed !== 0) return result;
|
|
961
961
|
if (!added && canOpenFreshItem) {
|
|
962
|
-
const nextInitialState =
|
|
962
|
+
const nextInitialState = require_internal_annotations.inheritAnnotations(context.state, syncParser.initialState);
|
|
963
963
|
itemIndex = context.state.length;
|
|
964
964
|
result = parseSyncWithUnwrappedFallback(require_execution_context.withChildContext(context, itemIndex, nextInitialState));
|
|
965
965
|
if (!result.success) {
|
|
@@ -1007,13 +1007,13 @@ function multiple(parser, options = {}) {
|
|
|
1007
1007
|
},
|
|
1008
1008
|
consumed: result.consumed
|
|
1009
1009
|
};
|
|
1010
|
-
const nextItemState =
|
|
1010
|
+
const nextItemState = require_internal_annotations.inheritAnnotations(itemAnnotationSource, result.next.state);
|
|
1011
1011
|
return {
|
|
1012
1012
|
success: true,
|
|
1013
1013
|
...result.provisional ? { provisional: true } : {},
|
|
1014
1014
|
next: {
|
|
1015
1015
|
...result.next,
|
|
1016
|
-
state:
|
|
1016
|
+
state: require_internal_annotations.annotateFreshArray(context.state, [...added ? context.state : context.state.slice(0, -1), nextItemState]),
|
|
1017
1017
|
...mergedExec != null ? {
|
|
1018
1018
|
trace: mergedExec.trace,
|
|
1019
1019
|
exec: mergedExec,
|
|
@@ -1035,12 +1035,12 @@ function multiple(parser, options = {}) {
|
|
|
1035
1035
|
};
|
|
1036
1036
|
let added = !canExtendCurrent;
|
|
1037
1037
|
let itemIndex = canExtendCurrent ? context.state.length - 1 : context.state.length;
|
|
1038
|
-
const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState :
|
|
1038
|
+
const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState : require_internal_annotations.inheritAnnotations(context.state, parser.initialState);
|
|
1039
1039
|
let result = await parseAsyncWithUnwrappedFallback(require_execution_context.withChildContext(context, itemIndex, currentItemStateWithAnnotations));
|
|
1040
1040
|
if (!result.success) {
|
|
1041
1041
|
if (result.consumed !== 0) return result;
|
|
1042
1042
|
if (!added && canOpenFreshItem) {
|
|
1043
|
-
const nextInitialState =
|
|
1043
|
+
const nextInitialState = require_internal_annotations.inheritAnnotations(context.state, parser.initialState);
|
|
1044
1044
|
itemIndex = context.state.length;
|
|
1045
1045
|
result = await parseAsyncWithUnwrappedFallback(require_execution_context.withChildContext(context, itemIndex, nextInitialState));
|
|
1046
1046
|
if (!result.success) {
|
|
@@ -1088,13 +1088,13 @@ function multiple(parser, options = {}) {
|
|
|
1088
1088
|
},
|
|
1089
1089
|
consumed: result.consumed
|
|
1090
1090
|
};
|
|
1091
|
-
const nextItemState =
|
|
1091
|
+
const nextItemState = require_internal_annotations.inheritAnnotations(itemAnnotationSource, result.next.state);
|
|
1092
1092
|
return {
|
|
1093
1093
|
success: true,
|
|
1094
1094
|
...result.provisional ? { provisional: true } : {},
|
|
1095
1095
|
next: {
|
|
1096
1096
|
...result.next,
|
|
1097
|
-
state:
|
|
1097
|
+
state: require_internal_annotations.annotateFreshArray(context.state, [...added ? context.state : context.state.slice(0, -1), nextItemState]),
|
|
1098
1098
|
...mergedExec != null ? {
|
|
1099
1099
|
trace: mergedExec.trace,
|
|
1100
1100
|
exec: mergedExec,
|
|
@@ -1226,7 +1226,7 @@ function multiple(parser, options = {}) {
|
|
|
1226
1226
|
const canOpenNew = context.state.length < max;
|
|
1227
1227
|
if (!canExtendCurrent && !canOpenNew) return require_mode_dispatch.dispatchIterableByMode(parser.mode, function* () {}, async function* () {});
|
|
1228
1228
|
const itemIndex = canExtendCurrent ? context.state.length - 1 : context.state.length;
|
|
1229
|
-
const suggestInitialState = canExtendCurrent ? currentItemState :
|
|
1229
|
+
const suggestInitialState = canExtendCurrent ? currentItemState : require_internal_annotations.inheritAnnotations(context.state, parser.initialState);
|
|
1230
1230
|
const suggestFallbackState = unwrapInjectedWrapper(suggestInitialState);
|
|
1231
1231
|
const hasSuggestFallbackState = suggestFallbackState !== suggestInitialState;
|
|
1232
1232
|
const collectSelectedValuesSync = () => {
|
|
@@ -1311,7 +1311,7 @@ function multiple(parser, options = {}) {
|
|
|
1311
1311
|
},
|
|
1312
1312
|
getDocFragments(state, defaultValue) {
|
|
1313
1313
|
const latestState = state.kind === "available" && state.state.length > 0 ? state.state.at(-1) : void 0;
|
|
1314
|
-
const latestInnerState = latestState != null &&
|
|
1314
|
+
const latestInnerState = latestState != null && require_internal_annotations.isInjectedAnnotationWrapper(latestState) ? unwrapInjectedWrapper(latestState) : latestState;
|
|
1315
1315
|
const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : latestInnerState !== void 0 ? {
|
|
1316
1316
|
kind: "available",
|
|
1317
1317
|
state: latestInnerState
|
|
@@ -1536,7 +1536,7 @@ function nonEmpty(parser) {
|
|
|
1536
1536
|
acceptingAnyToken: parser.acceptingAnyToken,
|
|
1537
1537
|
initialState,
|
|
1538
1538
|
...typeof parser.canSkip === "function" ? { canSkip(state, exec) {
|
|
1539
|
-
const unwrappedState =
|
|
1539
|
+
const unwrappedState = require_internal_annotations.unwrapInjectedAnnotationWrapper(state);
|
|
1540
1540
|
if (unwrappedState === initialState) return false;
|
|
1541
1541
|
return parser.canSkip?.(unwrappedState, exec) === true;
|
|
1542
1542
|
} } : {},
|
package/dist/parser.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_internal_parser = require('./internal/parser.cjs');
|
|
2
2
|
|
|
3
|
-
exports.createParserContext =
|
|
4
|
-
exports.getDocPage =
|
|
5
|
-
exports.getDocPageAsync =
|
|
6
|
-
exports.getDocPageSync =
|
|
7
|
-
exports.parse =
|
|
8
|
-
exports.parseAsync =
|
|
9
|
-
exports.parseSync =
|
|
10
|
-
exports.suggest =
|
|
11
|
-
exports.suggestAsync =
|
|
12
|
-
exports.suggestSync =
|
|
3
|
+
exports.createParserContext = require_internal_parser.createParserContext;
|
|
4
|
+
exports.getDocPage = require_internal_parser.getDocPage;
|
|
5
|
+
exports.getDocPageAsync = require_internal_parser.getDocPageAsync;
|
|
6
|
+
exports.getDocPageSync = require_internal_parser.getDocPageSync;
|
|
7
|
+
exports.parse = require_internal_parser.parse;
|
|
8
|
+
exports.parseAsync = require_internal_parser.parseAsync;
|
|
9
|
+
exports.parseSync = require_internal_parser.parseSync;
|
|
10
|
+
exports.suggest = require_internal_parser.suggest;
|
|
11
|
+
exports.suggestAsync = require_internal_parser.suggestAsync;
|
|
12
|
+
exports.suggestSync = require_internal_parser.suggestSync;
|
package/dist/phase2-seed.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_internal_annotations = require('./internal/annotations.cjs');
|
|
2
2
|
const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
|
|
3
3
|
|
|
4
4
|
//#region src/phase2-seed.ts
|
|
@@ -15,7 +15,7 @@ const extractPhase2SeedKey = Symbol("@optique/core/extractPhase2Seed");
|
|
|
15
15
|
*/
|
|
16
16
|
function phase2SeedFromValueResult(result) {
|
|
17
17
|
return {
|
|
18
|
-
value:
|
|
18
|
+
value: require_internal_annotations.unwrapInjectedAnnotationWrapper(result.value),
|
|
19
19
|
...result.deferred ? { deferred: true } : {},
|
|
20
20
|
...result.deferredKeys != null ? { deferredKeys: result.deferredKeys } : {}
|
|
21
21
|
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { DeferredMap, ValueParserResult } from "./valueparser.cjs";
|
|
2
|
+
import { ExecutionContext, Mode, ModeValue, Parser } from "./internal/parser.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/phase2-seed.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Best-effort parser value used for phase-two context collection.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
interface Phase2Seed<T = unknown> {
|
|
12
|
+
readonly value: T;
|
|
13
|
+
readonly deferred?: true;
|
|
14
|
+
readonly deferredKeys?: DeferredMap;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Internal hook for extracting a best-effort phase-two seed from parser state.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
type Phase2SeedExtractor<M extends Mode = Mode, TState = unknown, TValue = unknown> = (state: TState, exec?: ExecutionContext) => ModeValue<M, Phase2Seed<TValue> | null>;
|
|
22
|
+
/**
|
|
23
|
+
* Internal parser hook key for phase-two seed extraction.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
declare const extractPhase2SeedKey: unique symbol;
|
|
28
|
+
/**
|
|
29
|
+
* Converts a successful complete() result into a phase-two seed.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
declare function phase2SeedFromValueResult<T>(result: Extract<ValueParserResult<T>, {
|
|
34
|
+
readonly success: true;
|
|
35
|
+
}>): Phase2Seed<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Invokes a parser's internal phase-two seed hook when present.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
declare function extractPhase2Seed<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, state: TState, exec?: ExecutionContext): ModeValue<M, Phase2Seed<TValue> | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Attempts to complete a parser and falls back to the internal phase-two
|
|
44
|
+
* seed hook when completion returns an unsuccessful result.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
declare function completeOrExtractPhase2Seed<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, state: TState, exec?: ExecutionContext): ModeValue<M, Phase2Seed<TValue> | null>;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { Phase2Seed, Phase2SeedExtractor, completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { DeferredMap, ValueParserResult } from "./valueparser.js";
|
|
2
|
+
import { ExecutionContext, Mode, ModeValue, Parser } from "./internal/parser.js";
|
|
3
|
+
|
|
4
|
+
//#region src/phase2-seed.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Best-effort parser value used for phase-two context collection.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
interface Phase2Seed<T = unknown> {
|
|
12
|
+
readonly value: T;
|
|
13
|
+
readonly deferred?: true;
|
|
14
|
+
readonly deferredKeys?: DeferredMap;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Internal hook for extracting a best-effort phase-two seed from parser state.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
type Phase2SeedExtractor<M extends Mode = Mode, TState = unknown, TValue = unknown> = (state: TState, exec?: ExecutionContext) => ModeValue<M, Phase2Seed<TValue> | null>;
|
|
22
|
+
/**
|
|
23
|
+
* Internal parser hook key for phase-two seed extraction.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
declare const extractPhase2SeedKey: unique symbol;
|
|
28
|
+
/**
|
|
29
|
+
* Converts a successful complete() result into a phase-two seed.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
declare function phase2SeedFromValueResult<T>(result: Extract<ValueParserResult<T>, {
|
|
34
|
+
readonly success: true;
|
|
35
|
+
}>): Phase2Seed<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Invokes a parser's internal phase-two seed hook when present.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
declare function extractPhase2Seed<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, state: TState, exec?: ExecutionContext): ModeValue<M, Phase2Seed<TValue> | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Attempts to complete a parser and falls back to the internal phase-two
|
|
44
|
+
* seed hook when completion returns an unsuccessful result.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
declare function completeOrExtractPhase2Seed<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, state: TState, exec?: ExecutionContext): ModeValue<M, Phase2Seed<TValue> | null>;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { Phase2Seed, Phase2SeedExtractor, completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult };
|