JavaScriptvalidateArgspec

validateArgspec

Python

Validate an argspec string and inspect the parsed argument slots.

validateArgspecfunction#

validateArgspec(spec: string): ValidateArgspecResult

Validate an xparse-style argspec string and report its parsed slots.

Use it to self-check an argspec before injecting a custom command into a Parser. Never throws on a malformed spec: the failure is reported through the valid / error fields of the result. For the notation semantics, see the Argspec guide.

ParameterTypeDescription
specstring
  • The argspec string, such as 'o m', 's m{}', or `d<(,)><[,]>`.
Returns
ValidateArgspecResult —

A ValidateArgspecResult describing validity and slots.

TypeScript
import { validateArgspec } from 'texform';

validateArgspec('o m'); // { valid: true, error: null, argCount: 2, parsed: [ ... ] }
validateArgspec('ABC123').valid; // false

ValidateArgspecResultinterface#

The outcome of validateArgspec: whether the spec is well-formed and, when valid, its parsed slots.

On success valid is true and argCount / parsed describe the slots; on failure valid is false and error carries the reason.

FieldTypeDescription
validboolean

Whether the specification parsed successfully.

errorstring | null

The error message when invalid, otherwise null.

argCountnumber | null

The number of argument slots when valid, otherwise null.

parsedParsedArgSpecSlot[] | null

The per-slot breakdown when valid, otherwise null.

ParsedArgSpecSlotinterface#

One parsed argument slot of an argspec, as reported by validateArgspec and by the parser's command/environment lookups.

FieldTypeDescription
requiredboolean

Whether the argument is mandatory (true) or optional (false).

noLeadingSpaceboolean

Whether leading space before the argument is disallowed.

nullableboolean

Whether an absent optional argument yields a null value.

kindArgSpecKindInfo

The value kind the slot accepts.

formArgSpecFormInfo

The syntactic form the slot takes.