Skip to main content

Module xparse

Module xparse 

Source
Expand description

Parser for the xparse argument specification mini-language — the string in the second group of \NewDocumentCommand{\foo}{<spec>}{…} (and the environment variants). It describes argument shapes; processing behavior is ignored.

The full grammar is tokenized so the cursor never desyncs on a type’s trailing material (delimiter tokens, {default} groups, embellishment sets). But our ArgSpec model only distinguishes a {…} ArgKind::Brace from a […] ArgKind::Bracket slot, because that is all the CST produces and all a consumer (the formatter’s arity glue) can act on. So an ArgSpec is emitted only for argument types that yield an actual {…}/[…] node:

  • m → required brace; o, O{default} → optional bracket.
  • r⟨t1⟩⟨t2⟩ / R⟨…⟩{default} (required delimited) and d⟨t1⟩⟨t2⟩ / D⟨…⟩{default} (optional delimited) → an ArgSpec only when the delimiters are literally [/] (bracket) or {/} (brace); other delimiters ((/), </>, …) produce no CST node, so no slot.
  • s (star), t⟨token⟩ (optional token), v (verbatim), and e/E (embellishments) produce no {…}/[…] node, so no slot — but their trailing material is still consumed.

This keeps the emitted slot count equal to the GROUP/OPTIONAL nodes the greedy parser actually attaches, which is what the formatter counts. Modifiers (+, !) and argument processors (>{…}) are skipped. Unknown type letters stop the scan (conservative: never panic, never invent slots).

Functions§

parse_spec
Parse an xparse argument-spec string into the {…}/[…] argument slots it declares, in order. See the module docs for the type-by-type mapping.