@optique/core 0.6.9-dev.197 → 0.6.10
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/LICENSE +1 -1
- package/dist/constructs.cjs +7 -5
- package/dist/constructs.js +7 -5
- package/dist/parser.cjs +26 -7
- package/dist/parser.js +26 -7
- package/package.json +1 -1
package/LICENSE
CHANGED
package/dist/constructs.cjs
CHANGED
|
@@ -269,14 +269,17 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
269
269
|
parsers = labelOrParsers;
|
|
270
270
|
options = maybeParsersOrOptions ?? {};
|
|
271
271
|
}
|
|
272
|
-
const
|
|
272
|
+
const parserKeys = Reflect.ownKeys(parsers);
|
|
273
|
+
const parserPairs = parserKeys.map((k) => [k, parsers[k]]);
|
|
273
274
|
parserPairs.sort(([_, parserA], [__, parserB]) => parserB.priority - parserA.priority);
|
|
275
|
+
const initialState = {};
|
|
276
|
+
for (const key of parserKeys) initialState[key] = parsers[key].initialState;
|
|
274
277
|
return {
|
|
275
278
|
$valueType: [],
|
|
276
279
|
$stateType: [],
|
|
277
|
-
priority: Math.max(...
|
|
280
|
+
priority: Math.max(...parserKeys.map((k) => parsers[k].priority)),
|
|
278
281
|
usage: parserPairs.flatMap(([_, p]) => p.usage),
|
|
279
|
-
initialState
|
|
282
|
+
initialState,
|
|
280
283
|
parse(context) {
|
|
281
284
|
let error = {
|
|
282
285
|
consumed: 0,
|
|
@@ -342,8 +345,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
342
345
|
},
|
|
343
346
|
complete(state) {
|
|
344
347
|
const result = {};
|
|
345
|
-
for (const field
|
|
346
|
-
if (!(field in parsers)) continue;
|
|
348
|
+
for (const field of parserKeys) {
|
|
347
349
|
const valueResult = parsers[field].complete(state[field]);
|
|
348
350
|
if (valueResult.success) result[field] = valueResult.value;
|
|
349
351
|
else return {
|
package/dist/constructs.js
CHANGED
|
@@ -269,14 +269,17 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
269
269
|
parsers = labelOrParsers;
|
|
270
270
|
options = maybeParsersOrOptions ?? {};
|
|
271
271
|
}
|
|
272
|
-
const
|
|
272
|
+
const parserKeys = Reflect.ownKeys(parsers);
|
|
273
|
+
const parserPairs = parserKeys.map((k) => [k, parsers[k]]);
|
|
273
274
|
parserPairs.sort(([_, parserA], [__, parserB]) => parserB.priority - parserA.priority);
|
|
275
|
+
const initialState = {};
|
|
276
|
+
for (const key of parserKeys) initialState[key] = parsers[key].initialState;
|
|
274
277
|
return {
|
|
275
278
|
$valueType: [],
|
|
276
279
|
$stateType: [],
|
|
277
|
-
priority: Math.max(...
|
|
280
|
+
priority: Math.max(...parserKeys.map((k) => parsers[k].priority)),
|
|
278
281
|
usage: parserPairs.flatMap(([_, p]) => p.usage),
|
|
279
|
-
initialState
|
|
282
|
+
initialState,
|
|
280
283
|
parse(context) {
|
|
281
284
|
let error = {
|
|
282
285
|
consumed: 0,
|
|
@@ -342,8 +345,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
342
345
|
},
|
|
343
346
|
complete(state) {
|
|
344
347
|
const result = {};
|
|
345
|
-
for (const field
|
|
346
|
-
if (!(field in parsers)) continue;
|
|
348
|
+
for (const field of parserKeys) {
|
|
347
349
|
const valueResult = parsers[field].complete(state[field]);
|
|
348
350
|
if (valueResult.success) result[field] = valueResult.value;
|
|
349
351
|
else return {
|
package/dist/parser.cjs
CHANGED
|
@@ -93,6 +93,26 @@ function suggest(parser, args) {
|
|
|
93
93
|
return Array.from(parser.suggest(context, prefix));
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
|
+
* Recursively searches for a command within nested exclusive usage terms.
|
|
97
|
+
* When the command is found, returns the expanded usage terms for that command.
|
|
98
|
+
*
|
|
99
|
+
* @param term The usage term to search in
|
|
100
|
+
* @param commandName The command name to find
|
|
101
|
+
* @returns The expanded usage terms if found, null otherwise
|
|
102
|
+
*/
|
|
103
|
+
function findCommandInExclusive(term, commandName) {
|
|
104
|
+
if (term.type !== "exclusive") return null;
|
|
105
|
+
for (const termGroup of term.terms) {
|
|
106
|
+
const firstTerm = termGroup[0];
|
|
107
|
+
if (firstTerm?.type === "command" && firstTerm.name === commandName) return termGroup;
|
|
108
|
+
if (firstTerm?.type === "exclusive") {
|
|
109
|
+
const found = findCommandInExclusive(firstTerm, commandName);
|
|
110
|
+
if (found) return [...found, ...termGroup.slice(1)];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
96
116
|
* Generates a documentation page for a parser based on its current state after
|
|
97
117
|
* attempting to parse the provided arguments. This function is useful for
|
|
98
118
|
* creating help documentation that reflects the current parsing context.
|
|
@@ -149,15 +169,14 @@ function getDocPage(parser, args = []) {
|
|
|
149
169
|
}
|
|
150
170
|
if (entries.length > 0) sections.push({ entries });
|
|
151
171
|
const usage = [...require_usage.normalizeUsage(parser.usage)];
|
|
152
|
-
|
|
172
|
+
let i = 0;
|
|
173
|
+
for (const arg of args) {
|
|
153
174
|
const term = usage[i];
|
|
154
|
-
if (term.type
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (firstTerm?.type !== "command" || firstTerm.name !== arg) continue;
|
|
158
|
-
usage.splice(i, 1, ...termGroup);
|
|
159
|
-
break;
|
|
175
|
+
if (usage.length > i && term.type === "exclusive") {
|
|
176
|
+
const found = findCommandInExclusive(term, arg);
|
|
177
|
+
if (found) usage.splice(i, 1, ...found);
|
|
160
178
|
}
|
|
179
|
+
i++;
|
|
161
180
|
}
|
|
162
181
|
return {
|
|
163
182
|
usage,
|
package/dist/parser.js
CHANGED
|
@@ -93,6 +93,26 @@ function suggest(parser, args) {
|
|
|
93
93
|
return Array.from(parser.suggest(context, prefix));
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
|
+
* Recursively searches for a command within nested exclusive usage terms.
|
|
97
|
+
* When the command is found, returns the expanded usage terms for that command.
|
|
98
|
+
*
|
|
99
|
+
* @param term The usage term to search in
|
|
100
|
+
* @param commandName The command name to find
|
|
101
|
+
* @returns The expanded usage terms if found, null otherwise
|
|
102
|
+
*/
|
|
103
|
+
function findCommandInExclusive(term, commandName) {
|
|
104
|
+
if (term.type !== "exclusive") return null;
|
|
105
|
+
for (const termGroup of term.terms) {
|
|
106
|
+
const firstTerm = termGroup[0];
|
|
107
|
+
if (firstTerm?.type === "command" && firstTerm.name === commandName) return termGroup;
|
|
108
|
+
if (firstTerm?.type === "exclusive") {
|
|
109
|
+
const found = findCommandInExclusive(firstTerm, commandName);
|
|
110
|
+
if (found) return [...found, ...termGroup.slice(1)];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
96
116
|
* Generates a documentation page for a parser based on its current state after
|
|
97
117
|
* attempting to parse the provided arguments. This function is useful for
|
|
98
118
|
* creating help documentation that reflects the current parsing context.
|
|
@@ -149,15 +169,14 @@ function getDocPage(parser, args = []) {
|
|
|
149
169
|
}
|
|
150
170
|
if (entries.length > 0) sections.push({ entries });
|
|
151
171
|
const usage = [...normalizeUsage(parser.usage)];
|
|
152
|
-
|
|
172
|
+
let i = 0;
|
|
173
|
+
for (const arg of args) {
|
|
153
174
|
const term = usage[i];
|
|
154
|
-
if (term.type
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (firstTerm?.type !== "command" || firstTerm.name !== arg) continue;
|
|
158
|
-
usage.splice(i, 1, ...termGroup);
|
|
159
|
-
break;
|
|
175
|
+
if (usage.length > i && term.type === "exclusive") {
|
|
176
|
+
const found = findCommandInExclusive(term, arg);
|
|
177
|
+
if (found) usage.splice(i, 1, ...found);
|
|
160
178
|
}
|
|
179
|
+
i++;
|
|
161
180
|
}
|
|
162
181
|
return {
|
|
163
182
|
usage,
|