@optique/core 1.0.5 → 1.0.7
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 +353 -31
- package/dist/constructs.js +354 -32
- package/dist/internal/parser.cjs +34 -0
- package/dist/internal/parser.d.cts +52 -0
- package/dist/internal/parser.d.ts +52 -0
- package/dist/internal/parser.js +33 -1
- package/dist/modifiers.cjs +53 -0
- package/dist/modifiers.js +54 -1
- package/package.json +1 -1
package/dist/internal/parser.js
CHANGED
|
@@ -8,6 +8,12 @@ import { createInputTrace } from "../input-trace.js";
|
|
|
8
8
|
|
|
9
9
|
//#region src/internal/parser.ts
|
|
10
10
|
/**
|
|
11
|
+
* Internal symbol used by transparent combinators to expose independently
|
|
12
|
+
* competing parse operations to shared-buffer parents.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
const parseLanesKey = Symbol("parseLanes");
|
|
16
|
+
/**
|
|
11
17
|
* Internal marker for wrappers whose `{ hasCliValue: false }` states should
|
|
12
18
|
* be treated as unmatched dependency-source states during completion-time
|
|
13
19
|
* Phase 1.
|
|
@@ -385,6 +391,32 @@ function composeWrappedSourceMetadata(dependencyMetadata, wrapSource) {
|
|
|
385
391
|
};
|
|
386
392
|
}
|
|
387
393
|
/**
|
|
394
|
+
* Defines internal parse-lane metadata without exposing it through object
|
|
395
|
+
* spreads used by custom parser wrappers.
|
|
396
|
+
*
|
|
397
|
+
* @internal
|
|
398
|
+
*/
|
|
399
|
+
function defineParseLanes(parser, lanes) {
|
|
400
|
+
if (lanes == null) return;
|
|
401
|
+
Object.defineProperty(parser, parseLanesKey, {
|
|
402
|
+
value: lanes,
|
|
403
|
+
configurable: true,
|
|
404
|
+
enumerable: false
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Gets parse-lane metadata defined directly on a parser.
|
|
409
|
+
*
|
|
410
|
+
* Inherited metadata belongs to the parser's prototype and must not bypass an
|
|
411
|
+
* overriding `parse()` implementation on a custom wrapper.
|
|
412
|
+
*
|
|
413
|
+
* @internal
|
|
414
|
+
*/
|
|
415
|
+
function getOwnParseLanes(parser) {
|
|
416
|
+
if (!Object.hasOwn(parser, parseLanesKey)) return void 0;
|
|
417
|
+
return parser[parseLanesKey];
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
388
420
|
* Marks a parser as inheriting parent-state annotations through wrapper-state
|
|
389
421
|
* reconstruction.
|
|
390
422
|
*
|
|
@@ -708,4 +740,4 @@ function buildDocPage(parser, context, args) {
|
|
|
708
740
|
}
|
|
709
741
|
|
|
710
742
|
//#endregion
|
|
711
|
-
export { annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, createParserContext, defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, getDelegatingSuggestRuntimeNodes, getDocPage, getDocPageAsync, getDocPageSync, getParserSuggestRuntimeNodes, inheritParentAnnotationsKey, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync, unmatchedNonCliDependencySourceStateMarker };
|
|
743
|
+
export { annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, createParserContext, defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingOnlyAnnotationCompletionParser, getDelegatingSuggestRuntimeNodes, getDocPage, getDocPageAsync, getDocPageSync, getOwnParseLanes, getParserSuggestRuntimeNodes, inheritParentAnnotationsKey, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync, unmatchedNonCliDependencySourceStateMarker };
|
package/dist/modifiers.cjs
CHANGED
|
@@ -226,6 +226,44 @@ function processOptionalStyleResult(result, innerState, context) {
|
|
|
226
226
|
};
|
|
227
227
|
return result;
|
|
228
228
|
}
|
|
229
|
+
function adaptOptionalStyleParseLanes(parser) {
|
|
230
|
+
const lanes = require_parser.getOwnParseLanes(parser);
|
|
231
|
+
if (lanes == null) return void 0;
|
|
232
|
+
const consumptionGroup = {};
|
|
233
|
+
return lanes.map((lane) => ({
|
|
234
|
+
priority: lane.priority,
|
|
235
|
+
zeroConsumptionGroup: lane.zeroConsumptionGroup,
|
|
236
|
+
settlesZeroConsumption: lane.settlesZeroConsumption,
|
|
237
|
+
leadingNames: lane.leadingNames,
|
|
238
|
+
acceptingAnyToken: false,
|
|
239
|
+
requiredConsumptionGroups: [...lane.requiredConsumptionGroups?.map((group) => ({
|
|
240
|
+
id: group.id,
|
|
241
|
+
...group.isActive == null ? {} : { isActive(state) {
|
|
242
|
+
const innerState = Array.isArray(state) ? state[0] : parser.initialState;
|
|
243
|
+
return group.isActive?.(innerState) ?? true;
|
|
244
|
+
} }
|
|
245
|
+
})) ?? [], {
|
|
246
|
+
id: consumptionGroup,
|
|
247
|
+
isActive(state) {
|
|
248
|
+
return Array.isArray(state);
|
|
249
|
+
}
|
|
250
|
+
}],
|
|
251
|
+
parse(context) {
|
|
252
|
+
const innerState = deriveOptionalInnerParseState(context.state, parser);
|
|
253
|
+
const innerContext = {
|
|
254
|
+
...context,
|
|
255
|
+
state: innerState
|
|
256
|
+
};
|
|
257
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => {
|
|
258
|
+
const result = lane.parse(innerContext);
|
|
259
|
+
return processOptionalStyleResult(result, innerState, context);
|
|
260
|
+
}, async () => {
|
|
261
|
+
const result = await lane.parse(innerContext);
|
|
262
|
+
return processOptionalStyleResult(result, innerState, context);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
229
267
|
/**
|
|
230
268
|
* Creates a `shouldDeferCompletion` adapter that unwraps the outer state
|
|
231
269
|
* shape (`[TState] | undefined`) used by {@link optional} and
|
|
@@ -410,6 +448,7 @@ function optional(parser) {
|
|
|
410
448
|
const composed = require_dependency_metadata.composeDependencyMetadata(parser.dependencyMetadata, "optional");
|
|
411
449
|
if (composed != null) optionalParser.dependencyMetadata = composed;
|
|
412
450
|
}
|
|
451
|
+
require_parser.defineParseLanes(optionalParser, adaptOptionalStyleParseLanes(parser));
|
|
413
452
|
require_parser.defineInheritedAnnotationParser(optionalParser);
|
|
414
453
|
require_parser.defineSourceBindingOnlyAnnotationCompletionParser(optionalParser);
|
|
415
454
|
return optionalParser;
|
|
@@ -639,6 +678,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
639
678
|
} });
|
|
640
679
|
if (composed != null) withDefaultParser.dependencyMetadata = composed;
|
|
641
680
|
}
|
|
681
|
+
require_parser.defineParseLanes(withDefaultParser, adaptOptionalStyleParseLanes(parser));
|
|
642
682
|
require_parser.defineInheritedAnnotationParser(withDefaultParser);
|
|
643
683
|
require_parser.defineSourceBindingOnlyAnnotationCompletionParser(withDefaultParser);
|
|
644
684
|
return withDefaultParser;
|
|
@@ -778,6 +818,7 @@ function map(parser, transform) {
|
|
|
778
818
|
return parser.getDocFragments(state, void 0);
|
|
779
819
|
}
|
|
780
820
|
};
|
|
821
|
+
require_parser.defineParseLanes(mappedParser, require_parser.getOwnParseLanes(parser));
|
|
781
822
|
delete mappedParser.normalizeValue;
|
|
782
823
|
delete mappedParser.validateValue;
|
|
783
824
|
if ("placeholder" in parser) Object.defineProperty(mappedParser, "placeholder", {
|
|
@@ -1484,6 +1525,7 @@ function multiple(parser, options = {}) {
|
|
|
1484
1525
|
*/
|
|
1485
1526
|
function nonEmpty(parser) {
|
|
1486
1527
|
const syncParser = parser;
|
|
1528
|
+
const consumptionGroup = {};
|
|
1487
1529
|
const processNonEmptyResult = (result) => {
|
|
1488
1530
|
if (!result.success) return result;
|
|
1489
1531
|
if (result.consumed.length === 0) return {
|
|
@@ -1531,6 +1573,17 @@ function nonEmpty(parser) {
|
|
|
1531
1573
|
return syncParser.getDocFragments(state, defaultValue);
|
|
1532
1574
|
}
|
|
1533
1575
|
};
|
|
1576
|
+
require_parser.defineParseLanes(nonEmptyParser, require_parser.getOwnParseLanes(parser)?.map((lane) => ({
|
|
1577
|
+
priority: lane.priority,
|
|
1578
|
+
zeroConsumptionGroup: lane.zeroConsumptionGroup,
|
|
1579
|
+
settlesZeroConsumption: lane.settlesZeroConsumption,
|
|
1580
|
+
leadingNames: lane.leadingNames,
|
|
1581
|
+
acceptingAnyToken: lane.acceptingAnyToken,
|
|
1582
|
+
requiredConsumptionGroups: [...lane.requiredConsumptionGroups ?? [], { id: consumptionGroup }],
|
|
1583
|
+
parse(context) {
|
|
1584
|
+
return lane.parse(context);
|
|
1585
|
+
}
|
|
1586
|
+
})));
|
|
1534
1587
|
if ("placeholder" in parser) Object.defineProperty(nonEmptyParser, "placeholder", {
|
|
1535
1588
|
get() {
|
|
1536
1589
|
return parser.placeholder;
|
package/dist/modifiers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { annotateFreshArray, annotationKey, getAnnotations, inheritAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./internal/annotations.js";
|
|
2
2
|
import { formatMessage, message, text } from "./message.js";
|
|
3
3
|
import { dispatchByMode, dispatchIterableByMode, mapModeValue, wrapForMode } from "./internal/mode-dispatch.js";
|
|
4
|
-
import { defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
|
|
4
|
+
import { defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingOnlyAnnotationCompletionParser, getOwnParseLanes, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
|
|
5
5
|
import { getDelegatedAnnotationState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeNestedDelegatedAnnotationState } from "./annotation-state.js";
|
|
6
6
|
import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
|
|
7
7
|
import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
|
|
@@ -226,6 +226,44 @@ function processOptionalStyleResult(result, innerState, context) {
|
|
|
226
226
|
};
|
|
227
227
|
return result;
|
|
228
228
|
}
|
|
229
|
+
function adaptOptionalStyleParseLanes(parser) {
|
|
230
|
+
const lanes = getOwnParseLanes(parser);
|
|
231
|
+
if (lanes == null) return void 0;
|
|
232
|
+
const consumptionGroup = {};
|
|
233
|
+
return lanes.map((lane) => ({
|
|
234
|
+
priority: lane.priority,
|
|
235
|
+
zeroConsumptionGroup: lane.zeroConsumptionGroup,
|
|
236
|
+
settlesZeroConsumption: lane.settlesZeroConsumption,
|
|
237
|
+
leadingNames: lane.leadingNames,
|
|
238
|
+
acceptingAnyToken: false,
|
|
239
|
+
requiredConsumptionGroups: [...lane.requiredConsumptionGroups?.map((group) => ({
|
|
240
|
+
id: group.id,
|
|
241
|
+
...group.isActive == null ? {} : { isActive(state) {
|
|
242
|
+
const innerState = Array.isArray(state) ? state[0] : parser.initialState;
|
|
243
|
+
return group.isActive?.(innerState) ?? true;
|
|
244
|
+
} }
|
|
245
|
+
})) ?? [], {
|
|
246
|
+
id: consumptionGroup,
|
|
247
|
+
isActive(state) {
|
|
248
|
+
return Array.isArray(state);
|
|
249
|
+
}
|
|
250
|
+
}],
|
|
251
|
+
parse(context) {
|
|
252
|
+
const innerState = deriveOptionalInnerParseState(context.state, parser);
|
|
253
|
+
const innerContext = {
|
|
254
|
+
...context,
|
|
255
|
+
state: innerState
|
|
256
|
+
};
|
|
257
|
+
return dispatchByMode(parser.mode, () => {
|
|
258
|
+
const result = lane.parse(innerContext);
|
|
259
|
+
return processOptionalStyleResult(result, innerState, context);
|
|
260
|
+
}, async () => {
|
|
261
|
+
const result = await lane.parse(innerContext);
|
|
262
|
+
return processOptionalStyleResult(result, innerState, context);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
229
267
|
/**
|
|
230
268
|
* Creates a `shouldDeferCompletion` adapter that unwraps the outer state
|
|
231
269
|
* shape (`[TState] | undefined`) used by {@link optional} and
|
|
@@ -410,6 +448,7 @@ function optional(parser) {
|
|
|
410
448
|
const composed = composeDependencyMetadata(parser.dependencyMetadata, "optional");
|
|
411
449
|
if (composed != null) optionalParser.dependencyMetadata = composed;
|
|
412
450
|
}
|
|
451
|
+
defineParseLanes(optionalParser, adaptOptionalStyleParseLanes(parser));
|
|
413
452
|
defineInheritedAnnotationParser(optionalParser);
|
|
414
453
|
defineSourceBindingOnlyAnnotationCompletionParser(optionalParser);
|
|
415
454
|
return optionalParser;
|
|
@@ -639,6 +678,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
639
678
|
} });
|
|
640
679
|
if (composed != null) withDefaultParser.dependencyMetadata = composed;
|
|
641
680
|
}
|
|
681
|
+
defineParseLanes(withDefaultParser, adaptOptionalStyleParseLanes(parser));
|
|
642
682
|
defineInheritedAnnotationParser(withDefaultParser);
|
|
643
683
|
defineSourceBindingOnlyAnnotationCompletionParser(withDefaultParser);
|
|
644
684
|
return withDefaultParser;
|
|
@@ -778,6 +818,7 @@ function map(parser, transform) {
|
|
|
778
818
|
return parser.getDocFragments(state, void 0);
|
|
779
819
|
}
|
|
780
820
|
};
|
|
821
|
+
defineParseLanes(mappedParser, getOwnParseLanes(parser));
|
|
781
822
|
delete mappedParser.normalizeValue;
|
|
782
823
|
delete mappedParser.validateValue;
|
|
783
824
|
if ("placeholder" in parser) Object.defineProperty(mappedParser, "placeholder", {
|
|
@@ -1484,6 +1525,7 @@ function multiple(parser, options = {}) {
|
|
|
1484
1525
|
*/
|
|
1485
1526
|
function nonEmpty(parser) {
|
|
1486
1527
|
const syncParser = parser;
|
|
1528
|
+
const consumptionGroup = {};
|
|
1487
1529
|
const processNonEmptyResult = (result) => {
|
|
1488
1530
|
if (!result.success) return result;
|
|
1489
1531
|
if (result.consumed.length === 0) return {
|
|
@@ -1531,6 +1573,17 @@ function nonEmpty(parser) {
|
|
|
1531
1573
|
return syncParser.getDocFragments(state, defaultValue);
|
|
1532
1574
|
}
|
|
1533
1575
|
};
|
|
1576
|
+
defineParseLanes(nonEmptyParser, getOwnParseLanes(parser)?.map((lane) => ({
|
|
1577
|
+
priority: lane.priority,
|
|
1578
|
+
zeroConsumptionGroup: lane.zeroConsumptionGroup,
|
|
1579
|
+
settlesZeroConsumption: lane.settlesZeroConsumption,
|
|
1580
|
+
leadingNames: lane.leadingNames,
|
|
1581
|
+
acceptingAnyToken: lane.acceptingAnyToken,
|
|
1582
|
+
requiredConsumptionGroups: [...lane.requiredConsumptionGroups ?? [], { id: consumptionGroup }],
|
|
1583
|
+
parse(context) {
|
|
1584
|
+
return lane.parse(context);
|
|
1585
|
+
}
|
|
1586
|
+
})));
|
|
1534
1587
|
if ("placeholder" in parser) Object.defineProperty(nonEmptyParser, "placeholder", {
|
|
1535
1588
|
get() {
|
|
1536
1589
|
return parser.placeholder;
|