@optique/core 1.0.0-dev.1335 → 1.0.0-dev.1354
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 +17 -0
- package/dist/constructs.js +17 -0
- package/package.json +1 -1
package/dist/constructs.cjs
CHANGED
|
@@ -146,6 +146,19 @@ function extractRequiredUsage(usage) {
|
|
|
146
146
|
return required;
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
|
+
* Validates that every element of the given array is a {@link Parser} object.
|
|
150
|
+
* @param parsers The array of values to validate.
|
|
151
|
+
* @param callerName The name of the calling function, used in error messages.
|
|
152
|
+
* @throws {TypeError} If any element is not a valid {@link Parser}.
|
|
153
|
+
*/
|
|
154
|
+
function assertParsers(parsers, callerName) {
|
|
155
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
156
|
+
const p = parsers[i];
|
|
157
|
+
const r = p;
|
|
158
|
+
if (p == null || typeof p !== "object" && typeof p !== "function" || !(r.$mode === "sync" || r.$mode === "async") || !Array.isArray(r.usage) || typeof r.priority !== "number" || Number.isNaN(r.priority) || !("initialState" in p) || typeof r.parse !== "function" || typeof r.complete !== "function" || typeof r.suggest !== "function" || typeof r.getDocFragments !== "function") throw new TypeError(`${callerName} argument at index ${i} is not a valid Parser.`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
149
162
|
* Analyzes parsers to determine what types of inputs are expected.
|
|
150
163
|
* @param parsers The parsers being combined
|
|
151
164
|
* @returns Context about what types of inputs are expected
|
|
@@ -306,6 +319,7 @@ function or(...args) {
|
|
|
306
319
|
options = void 0;
|
|
307
320
|
}
|
|
308
321
|
if (parsers.length < 1) throw new TypeError("or() requires at least one parser argument.");
|
|
322
|
+
assertParsers(parsers, "or()");
|
|
309
323
|
const noMatchContext = analyzeNoMatchContext(parsers);
|
|
310
324
|
const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
311
325
|
const syncParsers = parsers;
|
|
@@ -496,6 +510,7 @@ function longestMatch(...args) {
|
|
|
496
510
|
options = void 0;
|
|
497
511
|
}
|
|
498
512
|
if (parsers.length < 1) throw new TypeError("longestMatch() requires at least one parser argument.");
|
|
513
|
+
assertParsers(parsers, "longestMatch()");
|
|
499
514
|
const noMatchContext = analyzeNoMatchContext(parsers);
|
|
500
515
|
const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
501
516
|
const syncParsers = parsers;
|
|
@@ -1655,6 +1670,7 @@ function merge(...args) {
|
|
|
1655
1670
|
const endIndex = hasOptions ? args.length - 1 : args.length;
|
|
1656
1671
|
const rawParsers = args.slice(startIndex, endIndex);
|
|
1657
1672
|
if (rawParsers.length < 1) throw new TypeError("merge() requires at least one parser argument.");
|
|
1673
|
+
assertParsers(rawParsers, "merge()");
|
|
1658
1674
|
const combinedMode = rawParsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
1659
1675
|
const isAsync = combinedMode === "async";
|
|
1660
1676
|
const syncRawParsers = rawParsers;
|
|
@@ -2098,6 +2114,7 @@ function tryParseSuggestList(context, stateArray, parsers, matchedParsers, remai
|
|
|
2098
2114
|
}
|
|
2099
2115
|
function concat(...parsers) {
|
|
2100
2116
|
if (parsers.length < 1) throw new TypeError("concat() requires at least one parser argument.");
|
|
2117
|
+
assertParsers(parsers, "concat()");
|
|
2101
2118
|
const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
2102
2119
|
const isAsync = combinedMode === "async";
|
|
2103
2120
|
const syncParsers = parsers;
|
package/dist/constructs.js
CHANGED
|
@@ -146,6 +146,19 @@ function extractRequiredUsage(usage) {
|
|
|
146
146
|
return required;
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
|
+
* Validates that every element of the given array is a {@link Parser} object.
|
|
150
|
+
* @param parsers The array of values to validate.
|
|
151
|
+
* @param callerName The name of the calling function, used in error messages.
|
|
152
|
+
* @throws {TypeError} If any element is not a valid {@link Parser}.
|
|
153
|
+
*/
|
|
154
|
+
function assertParsers(parsers, callerName) {
|
|
155
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
156
|
+
const p = parsers[i];
|
|
157
|
+
const r = p;
|
|
158
|
+
if (p == null || typeof p !== "object" && typeof p !== "function" || !(r.$mode === "sync" || r.$mode === "async") || !Array.isArray(r.usage) || typeof r.priority !== "number" || Number.isNaN(r.priority) || !("initialState" in p) || typeof r.parse !== "function" || typeof r.complete !== "function" || typeof r.suggest !== "function" || typeof r.getDocFragments !== "function") throw new TypeError(`${callerName} argument at index ${i} is not a valid Parser.`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
149
162
|
* Analyzes parsers to determine what types of inputs are expected.
|
|
150
163
|
* @param parsers The parsers being combined
|
|
151
164
|
* @returns Context about what types of inputs are expected
|
|
@@ -306,6 +319,7 @@ function or(...args) {
|
|
|
306
319
|
options = void 0;
|
|
307
320
|
}
|
|
308
321
|
if (parsers.length < 1) throw new TypeError("or() requires at least one parser argument.");
|
|
322
|
+
assertParsers(parsers, "or()");
|
|
309
323
|
const noMatchContext = analyzeNoMatchContext(parsers);
|
|
310
324
|
const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
311
325
|
const syncParsers = parsers;
|
|
@@ -496,6 +510,7 @@ function longestMatch(...args) {
|
|
|
496
510
|
options = void 0;
|
|
497
511
|
}
|
|
498
512
|
if (parsers.length < 1) throw new TypeError("longestMatch() requires at least one parser argument.");
|
|
513
|
+
assertParsers(parsers, "longestMatch()");
|
|
499
514
|
const noMatchContext = analyzeNoMatchContext(parsers);
|
|
500
515
|
const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
501
516
|
const syncParsers = parsers;
|
|
@@ -1655,6 +1670,7 @@ function merge(...args) {
|
|
|
1655
1670
|
const endIndex = hasOptions ? args.length - 1 : args.length;
|
|
1656
1671
|
const rawParsers = args.slice(startIndex, endIndex);
|
|
1657
1672
|
if (rawParsers.length < 1) throw new TypeError("merge() requires at least one parser argument.");
|
|
1673
|
+
assertParsers(rawParsers, "merge()");
|
|
1658
1674
|
const combinedMode = rawParsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
1659
1675
|
const isAsync = combinedMode === "async";
|
|
1660
1676
|
const syncRawParsers = rawParsers;
|
|
@@ -2098,6 +2114,7 @@ function tryParseSuggestList(context, stateArray, parsers, matchedParsers, remai
|
|
|
2098
2114
|
}
|
|
2099
2115
|
function concat(...parsers) {
|
|
2100
2116
|
if (parsers.length < 1) throw new TypeError("concat() requires at least one parser argument.");
|
|
2117
|
+
assertParsers(parsers, "concat()");
|
|
2101
2118
|
const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
2102
2119
|
const isAsync = combinedMode === "async";
|
|
2103
2120
|
const syncParsers = parsers;
|