@optique/core 0.6.8 → 0.6.9
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 +10 -2
- package/dist/constructs.js +10 -2
- package/dist/parser.cjs +23 -5
- package/dist/parser.js +23 -5
- package/package.json +1 -1
package/dist/constructs.cjs
CHANGED
|
@@ -647,8 +647,16 @@ function merge(...args) {
|
|
|
647
647
|
});
|
|
648
648
|
},
|
|
649
649
|
getDocFragments(state, _defaultValue) {
|
|
650
|
-
const fragments = parsers.flatMap((p) => {
|
|
651
|
-
|
|
650
|
+
const fragments = parsers.flatMap((p, i) => {
|
|
651
|
+
let parserState;
|
|
652
|
+
if (p.initialState === void 0) {
|
|
653
|
+
const key = `__parser_${i}`;
|
|
654
|
+
if (state.kind === "available" && state.state && typeof state.state === "object" && key in state.state) parserState = {
|
|
655
|
+
kind: "available",
|
|
656
|
+
state: state.state[key]
|
|
657
|
+
};
|
|
658
|
+
else parserState = { kind: "unavailable" };
|
|
659
|
+
} else parserState = state.kind === "unavailable" ? { kind: "unavailable" } : {
|
|
652
660
|
kind: "available",
|
|
653
661
|
state: state.state
|
|
654
662
|
};
|
package/dist/constructs.js
CHANGED
|
@@ -647,8 +647,16 @@ function merge(...args) {
|
|
|
647
647
|
});
|
|
648
648
|
},
|
|
649
649
|
getDocFragments(state, _defaultValue) {
|
|
650
|
-
const fragments = parsers.flatMap((p) => {
|
|
651
|
-
|
|
650
|
+
const fragments = parsers.flatMap((p, i) => {
|
|
651
|
+
let parserState;
|
|
652
|
+
if (p.initialState === void 0) {
|
|
653
|
+
const key = `__parser_${i}`;
|
|
654
|
+
if (state.kind === "available" && state.state && typeof state.state === "object" && key in state.state) parserState = {
|
|
655
|
+
kind: "available",
|
|
656
|
+
state: state.state[key]
|
|
657
|
+
};
|
|
658
|
+
else parserState = { kind: "unavailable" };
|
|
659
|
+
} else parserState = state.kind === "unavailable" ? { kind: "unavailable" } : {
|
|
652
660
|
kind: "available",
|
|
653
661
|
state: state.state
|
|
654
662
|
};
|
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.
|
|
@@ -152,11 +172,9 @@ function getDocPage(parser, args = []) {
|
|
|
152
172
|
let i = 0;
|
|
153
173
|
for (const arg of args) {
|
|
154
174
|
const term = usage[i];
|
|
155
|
-
if (usage.length > i && term.type === "exclusive")
|
|
156
|
-
const
|
|
157
|
-
if (
|
|
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
|
}
|
|
161
179
|
i++;
|
|
162
180
|
}
|
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.
|
|
@@ -152,11 +172,9 @@ function getDocPage(parser, args = []) {
|
|
|
152
172
|
let i = 0;
|
|
153
173
|
for (const arg of args) {
|
|
154
174
|
const term = usage[i];
|
|
155
|
-
if (usage.length > i && term.type === "exclusive")
|
|
156
|
-
const
|
|
157
|
-
if (
|
|
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
|
}
|
|
161
179
|
i++;
|
|
162
180
|
}
|