Skip to main content

Module token

Module token 

Source
Expand description

Lexing: one command-line item at a time.

arg reads the next item: a long flag, one short letter, a word, or the -- separator. It does not know which flags take a value, so it stops where a value would start; the caller, which knows the flag, then calls Arg::switch (no value) or Arg::value (read it). The derive, the combinators and a hand-written dispatch! on flag names all read items this way.

command lineitems
--path=xLong named path with value x
--path xLong named path, then Arg::value reads x
-vpxShort v, Short p, then Arg::value reads x
-p=xShort p, then Arg::value reads x
-Word -
--Separator; every later word is a Word

Structs§

LongFlag
--name or --name=value.
ShortFlag
One letter of -abc.
ValueOptions
How a flag takes a detached value, beyond the default of any word that is not flag-like.
Word
A word that is not a flag.

Enums§

Arg
One lexed command-line item.
Kind
What the next item is, without consuming it.

Functions§

arg
Lex the next item. Backtracks at the end of the command line.
arg_plus
arg for a command that also takes + options (set +e, declare +x): a word +abc is a bundle like -abc, its letters reported with ShortFlag::plus set. A lone + is a word.
finish
Succeed at the end of the command line; otherwise report what is left over.
flag_word
A flag-like word taken whole as a value, for unknown_flags = "value": the last branch of an alt, after every flag. Only a whole word: once a bundle has bound a letter, an unknown one after it is still an error.
is_negative_number
Whether word is a negative number: - then digits, at most one ., and an optional exponent (e or E, an optional sign, at least one digit). Narrower than a float parse on purpose: -inf and -NaN are likelier misspelled flags.
kind
Classify the next item without consuming it; backtracks at the end of the command line. Meant as a dispatch! scrutinee, so a word is only offered to positional parsers and a flag only to flag parsers.
long_only
GNU’s getopt_long_only: a single-dash word whose name (up to the first =) is_long accepts is a long option, -entry=main as --entry=main, tried before the word is read as a bundle of short options. None, consuming nothing, for anything else, which arg then lexes as usual.
number
A negative number standing where a word starts, as a positional value: for a positional declared allow_negative_numbers, which would otherwise see a flag.
separator_word
-- as a word, for a positional declared double_dash = "preserve": the separator is its value and flags go on being flags.
split
The pieces of value between delimiters; empty pieces are kept.
word
A word that is not a flag: a positional value.