@optique/core 1.3.0-dev.2361 → 1.3.0-dev.2365

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.
@@ -1529,6 +1529,33 @@ function createLongestMatch(...args) {
1529
1529
  return require_modifiers.fluent(multiResult);
1530
1530
  }
1531
1531
  /**
1532
+ * Creates the initial parse error shared by object-like combinators.
1533
+ * @param context The current parser context.
1534
+ * @param noMatchContext The kinds of input accepted by the combinator.
1535
+ * @param errors Optional custom error formatters.
1536
+ * @returns A zero-consumption parse error.
1537
+ */
1538
+ function createObjectLikeInitialError(context, noMatchContext, errors) {
1539
+ if (context.buffer.length < 1) {
1540
+ const customEndOfInput = errors?.endOfInput;
1541
+ return {
1542
+ consumed: 0,
1543
+ error: customEndOfInput ? typeof customEndOfInput === "function" ? customEndOfInput(noMatchContext) : customEndOfInput : generateNoMatchError(noMatchContext)
1544
+ };
1545
+ }
1546
+ const token = context.buffer[0];
1547
+ const customMessage = errors?.unexpectedInput;
1548
+ if (customMessage) return {
1549
+ consumed: 0,
1550
+ error: typeof customMessage === "function" ? customMessage(token) : customMessage
1551
+ };
1552
+ const baseError = require_message.message`Unexpected option or argument: ${token}.`;
1553
+ return {
1554
+ consumed: 0,
1555
+ error: require_suggestion.createErrorWithSuggestions(baseError, token, context.usage, "both", errors?.suggestions)
1556
+ };
1557
+ }
1558
+ /**
1532
1559
  * Internal sync helper for object suggest functionality.
1533
1560
  * @internal
1534
1561
  */
@@ -1921,19 +1948,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
1921
1948
  checkDuplicateReachableLeadingCommandNames(parserPairs.map(([field, parser]) => [field, parser]));
1922
1949
  const noMatchContext = analyzeNoMatchContext(parserKeys.map((k) => parsers[k]));
1923
1950
  const combinedMode = parserKeys.some((k) => parsers[k].mode === "async") ? "async" : "sync";
1924
- const getInitialError = (context) => ({
1925
- consumed: 0,
1926
- error: context.buffer.length > 0 ? (() => {
1927
- const token = context.buffer[0];
1928
- const customMessage = options.errors?.unexpectedInput;
1929
- if (customMessage) return typeof customMessage === "function" ? customMessage(token) : customMessage;
1930
- const baseError = require_message.message`Unexpected option or argument: ${token}.`;
1931
- return require_suggestion.createErrorWithSuggestions(baseError, token, context.usage, "both", options.errors?.suggestions);
1932
- })() : (() => {
1933
- const customEndOfInput = options.errors?.endOfInput;
1934
- return customEndOfInput ? typeof customEndOfInput === "function" ? customEndOfInput(noMatchContext) : customEndOfInput : generateNoMatchError(noMatchContext);
1935
- })()
1936
- });
1951
+ const getInitialError = (context) => createObjectLikeInitialError(context, noMatchContext, options.errors);
1937
1952
  const parseSync = (context) => {
1938
1953
  let error = getInitialError(context);
1939
1954
  let currentContext = context;
@@ -3803,6 +3818,7 @@ function merge(...args) {
3803
3818
  const syncParsers = syncSorted.map(([p]) => p);
3804
3819
  if (!options.allowDuplicates) checkDuplicateOptionNames(sorted.map(([parser, originalIndex]) => [String(originalIndex), parser.usage]));
3805
3820
  checkDuplicateReachableLeadingCommandNames(sorted.map(([parser, originalIndex]) => [String(originalIndex), parser]));
3821
+ const noMatchContext = analyzeNoMatchContext(rawParsers);
3806
3822
  const mergedFieldParsers = collectChildFieldParsers(parsers);
3807
3823
  const duplicateOutputFieldNames = collectDuplicateFieldNames(mergedFieldParsers);
3808
3824
  const parserStateKey = (index) => `__parser_${index}`;
@@ -3896,8 +3912,7 @@ function merge(...args) {
3896
3912
  };
3897
3913
  return {
3898
3914
  success: false,
3899
- consumed: 0,
3900
- error: require_message.message`No matching option or argument found.`
3915
+ ...createObjectLikeInitialError(context, noMatchContext)
3901
3916
  };
3902
3917
  };
3903
3918
  const parseAsync = async (context) => {
@@ -3942,8 +3957,7 @@ function merge(...args) {
3942
3957
  };
3943
3958
  return {
3944
3959
  success: false,
3945
- consumed: 0,
3946
- error: require_message.message`No matching option or argument found.`
3960
+ ...createObjectLikeInitialError(context, noMatchContext)
3947
3961
  };
3948
3962
  };
3949
3963
  const mergeParser = {
@@ -1529,6 +1529,33 @@ function createLongestMatch(...args) {
1529
1529
  return fluent(multiResult);
1530
1530
  }
1531
1531
  /**
1532
+ * Creates the initial parse error shared by object-like combinators.
1533
+ * @param context The current parser context.
1534
+ * @param noMatchContext The kinds of input accepted by the combinator.
1535
+ * @param errors Optional custom error formatters.
1536
+ * @returns A zero-consumption parse error.
1537
+ */
1538
+ function createObjectLikeInitialError(context, noMatchContext, errors) {
1539
+ if (context.buffer.length < 1) {
1540
+ const customEndOfInput = errors?.endOfInput;
1541
+ return {
1542
+ consumed: 0,
1543
+ error: customEndOfInput ? typeof customEndOfInput === "function" ? customEndOfInput(noMatchContext) : customEndOfInput : generateNoMatchError(noMatchContext)
1544
+ };
1545
+ }
1546
+ const token = context.buffer[0];
1547
+ const customMessage = errors?.unexpectedInput;
1548
+ if (customMessage) return {
1549
+ consumed: 0,
1550
+ error: typeof customMessage === "function" ? customMessage(token) : customMessage
1551
+ };
1552
+ const baseError = message`Unexpected option or argument: ${token}.`;
1553
+ return {
1554
+ consumed: 0,
1555
+ error: createErrorWithSuggestions(baseError, token, context.usage, "both", errors?.suggestions)
1556
+ };
1557
+ }
1558
+ /**
1532
1559
  * Internal sync helper for object suggest functionality.
1533
1560
  * @internal
1534
1561
  */
@@ -1921,19 +1948,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
1921
1948
  checkDuplicateReachableLeadingCommandNames(parserPairs.map(([field, parser]) => [field, parser]));
1922
1949
  const noMatchContext = analyzeNoMatchContext(parserKeys.map((k) => parsers[k]));
1923
1950
  const combinedMode = parserKeys.some((k) => parsers[k].mode === "async") ? "async" : "sync";
1924
- const getInitialError = (context) => ({
1925
- consumed: 0,
1926
- error: context.buffer.length > 0 ? (() => {
1927
- const token = context.buffer[0];
1928
- const customMessage = options.errors?.unexpectedInput;
1929
- if (customMessage) return typeof customMessage === "function" ? customMessage(token) : customMessage;
1930
- const baseError = message`Unexpected option or argument: ${token}.`;
1931
- return createErrorWithSuggestions(baseError, token, context.usage, "both", options.errors?.suggestions);
1932
- })() : (() => {
1933
- const customEndOfInput = options.errors?.endOfInput;
1934
- return customEndOfInput ? typeof customEndOfInput === "function" ? customEndOfInput(noMatchContext) : customEndOfInput : generateNoMatchError(noMatchContext);
1935
- })()
1936
- });
1951
+ const getInitialError = (context) => createObjectLikeInitialError(context, noMatchContext, options.errors);
1937
1952
  const parseSync = (context) => {
1938
1953
  let error = getInitialError(context);
1939
1954
  let currentContext = context;
@@ -3803,6 +3818,7 @@ function merge(...args) {
3803
3818
  const syncParsers = syncSorted.map(([p]) => p);
3804
3819
  if (!options.allowDuplicates) checkDuplicateOptionNames(sorted.map(([parser, originalIndex]) => [String(originalIndex), parser.usage]));
3805
3820
  checkDuplicateReachableLeadingCommandNames(sorted.map(([parser, originalIndex]) => [String(originalIndex), parser]));
3821
+ const noMatchContext = analyzeNoMatchContext(rawParsers);
3806
3822
  const mergedFieldParsers = collectChildFieldParsers(parsers);
3807
3823
  const duplicateOutputFieldNames = collectDuplicateFieldNames(mergedFieldParsers);
3808
3824
  const parserStateKey = (index) => `__parser_${index}`;
@@ -3896,8 +3912,7 @@ function merge(...args) {
3896
3912
  };
3897
3913
  return {
3898
3914
  success: false,
3899
- consumed: 0,
3900
- error: message`No matching option or argument found.`
3915
+ ...createObjectLikeInitialError(context, noMatchContext)
3901
3916
  };
3902
3917
  };
3903
3918
  const parseAsync = async (context) => {
@@ -3942,8 +3957,7 @@ function merge(...args) {
3942
3957
  };
3943
3958
  return {
3944
3959
  success: false,
3945
- consumed: 0,
3946
- error: message`No matching option or argument found.`
3960
+ ...createObjectLikeInitialError(context, noMatchContext)
3947
3961
  };
3948
3962
  };
3949
3963
  const mergeParser = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.3.0-dev.2361",
3
+ "version": "1.3.0-dev.2365",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -225,7 +225,7 @@
225
225
  "fast-check": "^4.7.0",
226
226
  "tsdown": "^0.13.0",
227
227
  "typescript": "^5.8.3",
228
- "@optique/env": "1.3.0-dev.2361+c3135b2d"
228
+ "@optique/env": "1.3.0-dev.2365+f2866aef"
229
229
  },
230
230
  "scripts": {
231
231
  "build": "tsdown",