@optique/core 1.0.0-dev.921 → 1.0.1
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 +425 -0
- package/dist/annotation-state.d.cts +24 -0
- package/dist/annotation-state.d.ts +24 -0
- package/dist/annotation-state.js +414 -0
- package/dist/annotations.cjs +2 -248
- package/dist/annotations.d.cts +2 -137
- package/dist/annotations.d.ts +2 -137
- package/dist/annotations.js +2 -238
- package/dist/completion.cjs +611 -100
- package/dist/completion.d.cts +1 -1
- package/dist/completion.d.ts +1 -1
- package/dist/completion.js +611 -100
- package/dist/constructs.cjs +3338 -827
- package/dist/constructs.d.cts +48 -7
- package/dist/constructs.d.ts +48 -7
- package/dist/constructs.js +3338 -827
- package/dist/context.cjs +0 -23
- package/dist/context.d.cts +119 -53
- package/dist/context.d.ts +119 -53
- package/dist/context.js +0 -22
- package/dist/dependency-metadata.cjs +139 -0
- package/dist/dependency-metadata.d.cts +112 -0
- package/dist/dependency-metadata.d.ts +112 -0
- package/dist/dependency-metadata.js +138 -0
- package/dist/dependency-runtime.cjs +698 -0
- package/dist/dependency-runtime.d.cts +149 -0
- package/dist/dependency-runtime.d.ts +149 -0
- package/dist/dependency-runtime.js +687 -0
- package/dist/dependency.cjs +7 -928
- package/dist/dependency.d.cts +2 -794
- package/dist/dependency.d.ts +2 -794
- package/dist/dependency.js +2 -899
- package/dist/displaywidth.cjs +44 -0
- package/dist/displaywidth.js +43 -0
- package/dist/doc.cjs +285 -23
- package/dist/doc.d.cts +57 -2
- package/dist/doc.d.ts +57 -2
- package/dist/doc.js +283 -25
- package/dist/execution-context.cjs +56 -0
- package/dist/execution-context.js +53 -0
- package/dist/extension.cjs +87 -0
- package/dist/extension.d.cts +97 -0
- package/dist/extension.d.ts +97 -0
- package/dist/extension.js +76 -0
- package/dist/facade.cjs +718 -525
- package/dist/facade.d.cts +59 -15
- package/dist/facade.d.ts +59 -15
- package/dist/facade.js +718 -525
- package/dist/index.cjs +14 -29
- package/dist/index.d.cts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +7 -7
- package/dist/input-trace.cjs +56 -0
- package/dist/input-trace.d.cts +77 -0
- package/dist/input-trace.d.ts +77 -0
- package/dist/input-trace.js +55 -0
- package/dist/internal/annotations.cjs +316 -0
- package/dist/internal/annotations.d.cts +140 -0
- package/dist/internal/annotations.d.ts +140 -0
- package/dist/internal/annotations.js +306 -0
- package/dist/internal/dependency.cjs +984 -0
- package/dist/internal/dependency.d.cts +539 -0
- package/dist/internal/dependency.d.ts +539 -0
- package/dist/internal/dependency.js +964 -0
- package/dist/{mode-dispatch.cjs → internal/mode-dispatch.cjs} +1 -3
- package/dist/{mode-dispatch.d.cts → internal/mode-dispatch.d.cts} +3 -7
- package/dist/{mode-dispatch.d.ts → internal/mode-dispatch.d.ts} +3 -7
- package/dist/{mode-dispatch.js → internal/mode-dispatch.js} +1 -3
- package/dist/internal/parser.cjs +728 -0
- package/dist/internal/parser.d.cts +947 -0
- package/dist/internal/parser.d.ts +947 -0
- package/dist/internal/parser.js +711 -0
- package/dist/message.cjs +84 -26
- package/dist/message.d.cts +49 -9
- package/dist/message.d.ts +49 -9
- package/dist/message.js +84 -27
- package/dist/modifiers.cjs +1023 -240
- package/dist/modifiers.d.cts +42 -1
- package/dist/modifiers.d.ts +42 -1
- package/dist/modifiers.js +1023 -240
- package/dist/parser.cjs +11 -463
- package/dist/parser.d.cts +3 -537
- package/dist/parser.d.ts +3 -537
- package/dist/parser.js +2 -433
- package/dist/phase2-seed.cjs +59 -0
- package/dist/phase2-seed.js +56 -0
- package/dist/primitives.cjs +557 -208
- package/dist/primitives.d.cts +10 -14
- package/dist/primitives.d.ts +10 -14
- package/dist/primitives.js +557 -208
- package/dist/program.cjs +5 -1
- package/dist/program.d.cts +5 -3
- package/dist/program.d.ts +5 -3
- package/dist/program.js +6 -1
- package/dist/suggestion.cjs +22 -8
- package/dist/suggestion.js +22 -8
- package/dist/usage-internals.cjs +3 -2
- package/dist/usage-internals.js +4 -2
- package/dist/usage.cjs +195 -40
- package/dist/usage.d.cts +92 -11
- package/dist/usage.d.ts +92 -11
- package/dist/usage.js +194 -41
- package/dist/validate.cjs +170 -0
- package/dist/validate.js +164 -0
- package/dist/valueparser.cjs +1270 -187
- package/dist/valueparser.d.cts +320 -14
- package/dist/valueparser.d.ts +320 -14
- package/dist/valueparser.js +1269 -188
- package/package.json +9 -9
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const require_annotations = require('./internal/annotations.cjs');
|
|
2
|
+
const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
|
|
3
|
+
const require_parser = require('./internal/parser.cjs');
|
|
4
|
+
const require_annotation_state = require('./annotation-state.cjs');
|
|
5
|
+
|
|
6
|
+
//#region src/extension.ts
|
|
7
|
+
const emptyTraits = Object.freeze({});
|
|
8
|
+
/**
|
|
9
|
+
* Defines stable extension traits on a parser object.
|
|
10
|
+
*
|
|
11
|
+
* @param parser The parser object to annotate.
|
|
12
|
+
* @param traits Traits to enable.
|
|
13
|
+
* @throws {TypeError} If a trait property cannot be defined on `parser`.
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
*/
|
|
16
|
+
function defineTraits(parser, traits) {
|
|
17
|
+
if (traits.inheritsAnnotations === true) require_parser.defineInheritedAnnotationParser(parser);
|
|
18
|
+
if (traits.completesFromSource === true) Object.defineProperty(parser, require_parser.unmatchedNonCliDependencySourceStateMarker, {
|
|
19
|
+
value: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
enumerable: true
|
|
22
|
+
});
|
|
23
|
+
if (traits.requiresSourceBinding === true) Object.defineProperty(parser, require_parser.annotationWrapperRequiresSourceBindingKey, {
|
|
24
|
+
value: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
enumerable: false
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Reads the stable extension traits defined on a parser object.
|
|
31
|
+
*
|
|
32
|
+
* @param parser The parser object to inspect.
|
|
33
|
+
* @returns The enabled traits. Returns an empty object when none are set.
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
*/
|
|
36
|
+
function getTraits(parser) {
|
|
37
|
+
const traits = {
|
|
38
|
+
...Reflect.get(parser, require_parser.inheritParentAnnotationsKey) === true ? { inheritsAnnotations: true } : {},
|
|
39
|
+
...Reflect.get(parser, require_parser.unmatchedNonCliDependencySourceStateMarker) === true ? { completesFromSource: true } : {},
|
|
40
|
+
...Reflect.get(parser, require_parser.annotationWrapperRequiresSourceBindingKey) === true ? { requiresSourceBinding: true } : {}
|
|
41
|
+
};
|
|
42
|
+
return Object.keys(traits).length > 0 ? traits : emptyTraits;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Delegates suggest-time runtime nodes to an inner parser while preserving an
|
|
46
|
+
* outer parser's own source metadata node.
|
|
47
|
+
*
|
|
48
|
+
* @param innerParser The wrapped parser that owns the underlying nodes.
|
|
49
|
+
* @param outerParser The outer parser that may contribute its own source node.
|
|
50
|
+
* @param state The outer parser state.
|
|
51
|
+
* @param path The parser path within the parse tree.
|
|
52
|
+
* @param innerState The state to use when collecting inner nodes.
|
|
53
|
+
* @param position Whether the outer node is appended or prepended.
|
|
54
|
+
* @returns The composed runtime nodes.
|
|
55
|
+
* @since 1.0.0
|
|
56
|
+
*/
|
|
57
|
+
function delegateSuggestNodes(innerParser, outerParser, state, path, innerState, position = "append") {
|
|
58
|
+
return require_parser.getDelegatingSuggestRuntimeNodes(innerParser, outerParser, state, path, innerState, position);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Maps the source capability of a parser's dependency metadata while
|
|
62
|
+
* preserving any derived or transform capabilities unchanged.
|
|
63
|
+
*
|
|
64
|
+
* @param parser The parser whose source metadata should be transformed.
|
|
65
|
+
* @param mapSource Function that transforms the source capability.
|
|
66
|
+
* @returns The dependency metadata with its source capability transformed when
|
|
67
|
+
* present; otherwise the original dependency metadata, or
|
|
68
|
+
* `undefined` when the parser has no dependency metadata.
|
|
69
|
+
* @since 1.0.0
|
|
70
|
+
*/
|
|
71
|
+
function mapSourceMetadata(parser, mapSource) {
|
|
72
|
+
return require_parser.composeWrappedSourceMetadata(parser.dependencyMetadata, mapSource);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
exports.defineTraits = defineTraits;
|
|
77
|
+
exports.delegateSuggestNodes = delegateSuggestNodes;
|
|
78
|
+
exports.dispatchByMode = require_mode_dispatch.dispatchByMode;
|
|
79
|
+
exports.getTraits = getTraits;
|
|
80
|
+
exports.inheritAnnotations = require_annotations.inheritAnnotations;
|
|
81
|
+
exports.injectAnnotations = require_annotations.injectAnnotations;
|
|
82
|
+
exports.isInjectedAnnotationState = require_annotations.isInjectedAnnotationState;
|
|
83
|
+
exports.mapModeValue = require_mode_dispatch.mapModeValue;
|
|
84
|
+
exports.mapSourceMetadata = mapSourceMetadata;
|
|
85
|
+
exports.unwrapInjectedAnnotationState = require_annotations.unwrapInjectedAnnotationState;
|
|
86
|
+
exports.withAnnotationView = require_annotation_state.withAnnotationView;
|
|
87
|
+
exports.wrapForMode = require_mode_dispatch.wrapForMode;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { inheritAnnotations, injectAnnotations, isInjectedAnnotationState, unwrapInjectedAnnotationState } from "./internal/annotations.cjs";
|
|
2
|
+
import { Mode, Parser } from "./internal/parser.cjs";
|
|
3
|
+
import { withAnnotationView } from "./annotation-state.cjs";
|
|
4
|
+
import { dispatchByMode, mapModeValue, wrapForMode } from "./internal/mode-dispatch.cjs";
|
|
5
|
+
|
|
6
|
+
//#region src/extension.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Stable trait flags for custom parser extensions.
|
|
10
|
+
*
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
interface ParserTraits {
|
|
14
|
+
/**
|
|
15
|
+
* Whether parent-state annotations should be injected into rebuilt child
|
|
16
|
+
* states instead of relying on structural inheritance.
|
|
17
|
+
*/
|
|
18
|
+
readonly inheritsAnnotations?: true;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a missing CLI state can still complete from a source-backed
|
|
21
|
+
* fallback such as config or environment data.
|
|
22
|
+
*/
|
|
23
|
+
readonly completesFromSource?: true;
|
|
24
|
+
/**
|
|
25
|
+
* Whether annotation-only primitive states should count as completable only
|
|
26
|
+
* when they come from a nested source-bound parser.
|
|
27
|
+
*/
|
|
28
|
+
readonly requiresSourceBinding?: true;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Suggest-time runtime node used to seed dependency-aware completion.
|
|
32
|
+
*
|
|
33
|
+
* @since 1.0.0
|
|
34
|
+
*/
|
|
35
|
+
interface SuggestNode {
|
|
36
|
+
/** Path from the root parser to this node. */
|
|
37
|
+
readonly path: readonly PropertyKey[];
|
|
38
|
+
/** The parser whose dependency metadata should be inspected. */
|
|
39
|
+
readonly parser: Parser<Mode, unknown, unknown>;
|
|
40
|
+
/** Current parser state for this node. */
|
|
41
|
+
readonly state: unknown;
|
|
42
|
+
/** Whether this node reflects explicit input consumption. */
|
|
43
|
+
readonly matched?: boolean;
|
|
44
|
+
/** Snapshotted default dependency values for derived parsers. */
|
|
45
|
+
readonly defaultDependencyValues?: readonly unknown[];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Public view of a parser's source capability metadata.
|
|
49
|
+
*
|
|
50
|
+
* @since 1.0.0
|
|
51
|
+
*/
|
|
52
|
+
type ParserSourceMetadata<M extends Mode = Mode, TValue = unknown, TState = unknown> = NonNullable<NonNullable<Parser<M, TValue, TState>["dependencyMetadata"]>["source"]>;
|
|
53
|
+
/**
|
|
54
|
+
* Defines stable extension traits on a parser object.
|
|
55
|
+
*
|
|
56
|
+
* @param parser The parser object to annotate.
|
|
57
|
+
* @param traits Traits to enable.
|
|
58
|
+
* @throws {TypeError} If a trait property cannot be defined on `parser`.
|
|
59
|
+
* @since 1.0.0
|
|
60
|
+
*/
|
|
61
|
+
declare function defineTraits(parser: object, traits: ParserTraits): void;
|
|
62
|
+
/**
|
|
63
|
+
* Reads the stable extension traits defined on a parser object.
|
|
64
|
+
*
|
|
65
|
+
* @param parser The parser object to inspect.
|
|
66
|
+
* @returns The enabled traits. Returns an empty object when none are set.
|
|
67
|
+
* @since 1.0.0
|
|
68
|
+
*/
|
|
69
|
+
declare function getTraits(parser: object): ParserTraits;
|
|
70
|
+
/**
|
|
71
|
+
* Delegates suggest-time runtime nodes to an inner parser while preserving an
|
|
72
|
+
* outer parser's own source metadata node.
|
|
73
|
+
*
|
|
74
|
+
* @param innerParser The wrapped parser that owns the underlying nodes.
|
|
75
|
+
* @param outerParser The outer parser that may contribute its own source node.
|
|
76
|
+
* @param state The outer parser state.
|
|
77
|
+
* @param path The parser path within the parse tree.
|
|
78
|
+
* @param innerState The state to use when collecting inner nodes.
|
|
79
|
+
* @param position Whether the outer node is appended or prepended.
|
|
80
|
+
* @returns The composed runtime nodes.
|
|
81
|
+
* @since 1.0.0
|
|
82
|
+
*/
|
|
83
|
+
declare function delegateSuggestNodes<TInnerState>(innerParser: Parser<Mode, unknown, TInnerState>, outerParser: Parser<Mode, unknown, unknown>, state: unknown, path: readonly PropertyKey[], innerState: TInnerState, position?: "append" | "prepend"): readonly SuggestNode[];
|
|
84
|
+
/**
|
|
85
|
+
* Maps the source capability of a parser's dependency metadata while
|
|
86
|
+
* preserving any derived or transform capabilities unchanged.
|
|
87
|
+
*
|
|
88
|
+
* @param parser The parser whose source metadata should be transformed.
|
|
89
|
+
* @param mapSource Function that transforms the source capability.
|
|
90
|
+
* @returns The dependency metadata with its source capability transformed when
|
|
91
|
+
* present; otherwise the original dependency metadata, or
|
|
92
|
+
* `undefined` when the parser has no dependency metadata.
|
|
93
|
+
* @since 1.0.0
|
|
94
|
+
*/
|
|
95
|
+
declare function mapSourceMetadata<M extends Mode, TValue, TState>(parser: Pick<Parser<M, TValue, TState>, "dependencyMetadata">, mapSource: (source: ParserSourceMetadata<M, TValue, TState>) => ParserSourceMetadata<M, TValue, TState>): Parser<M, TValue, TState>["dependencyMetadata"] | undefined;
|
|
96
|
+
//#endregion
|
|
97
|
+
export { ParserSourceMetadata, ParserTraits, SuggestNode, defineTraits, delegateSuggestNodes, dispatchByMode, getTraits, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView, wrapForMode };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { inheritAnnotations, injectAnnotations, isInjectedAnnotationState, unwrapInjectedAnnotationState } from "./internal/annotations.js";
|
|
2
|
+
import { Mode, Parser } from "./internal/parser.js";
|
|
3
|
+
import { withAnnotationView } from "./annotation-state.js";
|
|
4
|
+
import { dispatchByMode, mapModeValue, wrapForMode } from "./internal/mode-dispatch.js";
|
|
5
|
+
|
|
6
|
+
//#region src/extension.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Stable trait flags for custom parser extensions.
|
|
10
|
+
*
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
interface ParserTraits {
|
|
14
|
+
/**
|
|
15
|
+
* Whether parent-state annotations should be injected into rebuilt child
|
|
16
|
+
* states instead of relying on structural inheritance.
|
|
17
|
+
*/
|
|
18
|
+
readonly inheritsAnnotations?: true;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a missing CLI state can still complete from a source-backed
|
|
21
|
+
* fallback such as config or environment data.
|
|
22
|
+
*/
|
|
23
|
+
readonly completesFromSource?: true;
|
|
24
|
+
/**
|
|
25
|
+
* Whether annotation-only primitive states should count as completable only
|
|
26
|
+
* when they come from a nested source-bound parser.
|
|
27
|
+
*/
|
|
28
|
+
readonly requiresSourceBinding?: true;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Suggest-time runtime node used to seed dependency-aware completion.
|
|
32
|
+
*
|
|
33
|
+
* @since 1.0.0
|
|
34
|
+
*/
|
|
35
|
+
interface SuggestNode {
|
|
36
|
+
/** Path from the root parser to this node. */
|
|
37
|
+
readonly path: readonly PropertyKey[];
|
|
38
|
+
/** The parser whose dependency metadata should be inspected. */
|
|
39
|
+
readonly parser: Parser<Mode, unknown, unknown>;
|
|
40
|
+
/** Current parser state for this node. */
|
|
41
|
+
readonly state: unknown;
|
|
42
|
+
/** Whether this node reflects explicit input consumption. */
|
|
43
|
+
readonly matched?: boolean;
|
|
44
|
+
/** Snapshotted default dependency values for derived parsers. */
|
|
45
|
+
readonly defaultDependencyValues?: readonly unknown[];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Public view of a parser's source capability metadata.
|
|
49
|
+
*
|
|
50
|
+
* @since 1.0.0
|
|
51
|
+
*/
|
|
52
|
+
type ParserSourceMetadata<M extends Mode = Mode, TValue = unknown, TState = unknown> = NonNullable<NonNullable<Parser<M, TValue, TState>["dependencyMetadata"]>["source"]>;
|
|
53
|
+
/**
|
|
54
|
+
* Defines stable extension traits on a parser object.
|
|
55
|
+
*
|
|
56
|
+
* @param parser The parser object to annotate.
|
|
57
|
+
* @param traits Traits to enable.
|
|
58
|
+
* @throws {TypeError} If a trait property cannot be defined on `parser`.
|
|
59
|
+
* @since 1.0.0
|
|
60
|
+
*/
|
|
61
|
+
declare function defineTraits(parser: object, traits: ParserTraits): void;
|
|
62
|
+
/**
|
|
63
|
+
* Reads the stable extension traits defined on a parser object.
|
|
64
|
+
*
|
|
65
|
+
* @param parser The parser object to inspect.
|
|
66
|
+
* @returns The enabled traits. Returns an empty object when none are set.
|
|
67
|
+
* @since 1.0.0
|
|
68
|
+
*/
|
|
69
|
+
declare function getTraits(parser: object): ParserTraits;
|
|
70
|
+
/**
|
|
71
|
+
* Delegates suggest-time runtime nodes to an inner parser while preserving an
|
|
72
|
+
* outer parser's own source metadata node.
|
|
73
|
+
*
|
|
74
|
+
* @param innerParser The wrapped parser that owns the underlying nodes.
|
|
75
|
+
* @param outerParser The outer parser that may contribute its own source node.
|
|
76
|
+
* @param state The outer parser state.
|
|
77
|
+
* @param path The parser path within the parse tree.
|
|
78
|
+
* @param innerState The state to use when collecting inner nodes.
|
|
79
|
+
* @param position Whether the outer node is appended or prepended.
|
|
80
|
+
* @returns The composed runtime nodes.
|
|
81
|
+
* @since 1.0.0
|
|
82
|
+
*/
|
|
83
|
+
declare function delegateSuggestNodes<TInnerState>(innerParser: Parser<Mode, unknown, TInnerState>, outerParser: Parser<Mode, unknown, unknown>, state: unknown, path: readonly PropertyKey[], innerState: TInnerState, position?: "append" | "prepend"): readonly SuggestNode[];
|
|
84
|
+
/**
|
|
85
|
+
* Maps the source capability of a parser's dependency metadata while
|
|
86
|
+
* preserving any derived or transform capabilities unchanged.
|
|
87
|
+
*
|
|
88
|
+
* @param parser The parser whose source metadata should be transformed.
|
|
89
|
+
* @param mapSource Function that transforms the source capability.
|
|
90
|
+
* @returns The dependency metadata with its source capability transformed when
|
|
91
|
+
* present; otherwise the original dependency metadata, or
|
|
92
|
+
* `undefined` when the parser has no dependency metadata.
|
|
93
|
+
* @since 1.0.0
|
|
94
|
+
*/
|
|
95
|
+
declare function mapSourceMetadata<M extends Mode, TValue, TState>(parser: Pick<Parser<M, TValue, TState>, "dependencyMetadata">, mapSource: (source: ParserSourceMetadata<M, TValue, TState>) => ParserSourceMetadata<M, TValue, TState>): Parser<M, TValue, TState>["dependencyMetadata"] | undefined;
|
|
96
|
+
//#endregion
|
|
97
|
+
export { ParserSourceMetadata, ParserTraits, SuggestNode, defineTraits, delegateSuggestNodes, dispatchByMode, getTraits, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView, wrapForMode };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { inheritAnnotations, injectAnnotations, isInjectedAnnotationState, unwrapInjectedAnnotationState } from "./internal/annotations.js";
|
|
2
|
+
import { dispatchByMode, mapModeValue, wrapForMode } from "./internal/mode-dispatch.js";
|
|
3
|
+
import { annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, defineInheritedAnnotationParser, getDelegatingSuggestRuntimeNodes, inheritParentAnnotationsKey, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
|
|
4
|
+
import { withAnnotationView } from "./annotation-state.js";
|
|
5
|
+
|
|
6
|
+
//#region src/extension.ts
|
|
7
|
+
const emptyTraits = Object.freeze({});
|
|
8
|
+
/**
|
|
9
|
+
* Defines stable extension traits on a parser object.
|
|
10
|
+
*
|
|
11
|
+
* @param parser The parser object to annotate.
|
|
12
|
+
* @param traits Traits to enable.
|
|
13
|
+
* @throws {TypeError} If a trait property cannot be defined on `parser`.
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
*/
|
|
16
|
+
function defineTraits(parser, traits) {
|
|
17
|
+
if (traits.inheritsAnnotations === true) defineInheritedAnnotationParser(parser);
|
|
18
|
+
if (traits.completesFromSource === true) Object.defineProperty(parser, unmatchedNonCliDependencySourceStateMarker, {
|
|
19
|
+
value: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
enumerable: true
|
|
22
|
+
});
|
|
23
|
+
if (traits.requiresSourceBinding === true) Object.defineProperty(parser, annotationWrapperRequiresSourceBindingKey, {
|
|
24
|
+
value: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
enumerable: false
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Reads the stable extension traits defined on a parser object.
|
|
31
|
+
*
|
|
32
|
+
* @param parser The parser object to inspect.
|
|
33
|
+
* @returns The enabled traits. Returns an empty object when none are set.
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
*/
|
|
36
|
+
function getTraits(parser) {
|
|
37
|
+
const traits = {
|
|
38
|
+
...Reflect.get(parser, inheritParentAnnotationsKey) === true ? { inheritsAnnotations: true } : {},
|
|
39
|
+
...Reflect.get(parser, unmatchedNonCliDependencySourceStateMarker) === true ? { completesFromSource: true } : {},
|
|
40
|
+
...Reflect.get(parser, annotationWrapperRequiresSourceBindingKey) === true ? { requiresSourceBinding: true } : {}
|
|
41
|
+
};
|
|
42
|
+
return Object.keys(traits).length > 0 ? traits : emptyTraits;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Delegates suggest-time runtime nodes to an inner parser while preserving an
|
|
46
|
+
* outer parser's own source metadata node.
|
|
47
|
+
*
|
|
48
|
+
* @param innerParser The wrapped parser that owns the underlying nodes.
|
|
49
|
+
* @param outerParser The outer parser that may contribute its own source node.
|
|
50
|
+
* @param state The outer parser state.
|
|
51
|
+
* @param path The parser path within the parse tree.
|
|
52
|
+
* @param innerState The state to use when collecting inner nodes.
|
|
53
|
+
* @param position Whether the outer node is appended or prepended.
|
|
54
|
+
* @returns The composed runtime nodes.
|
|
55
|
+
* @since 1.0.0
|
|
56
|
+
*/
|
|
57
|
+
function delegateSuggestNodes(innerParser, outerParser, state, path, innerState, position = "append") {
|
|
58
|
+
return getDelegatingSuggestRuntimeNodes(innerParser, outerParser, state, path, innerState, position);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Maps the source capability of a parser's dependency metadata while
|
|
62
|
+
* preserving any derived or transform capabilities unchanged.
|
|
63
|
+
*
|
|
64
|
+
* @param parser The parser whose source metadata should be transformed.
|
|
65
|
+
* @param mapSource Function that transforms the source capability.
|
|
66
|
+
* @returns The dependency metadata with its source capability transformed when
|
|
67
|
+
* present; otherwise the original dependency metadata, or
|
|
68
|
+
* `undefined` when the parser has no dependency metadata.
|
|
69
|
+
* @since 1.0.0
|
|
70
|
+
*/
|
|
71
|
+
function mapSourceMetadata(parser, mapSource) {
|
|
72
|
+
return composeWrappedSourceMetadata(parser.dependencyMetadata, mapSource);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { defineTraits, delegateSuggestNodes, dispatchByMode, getTraits, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView, wrapForMode };
|