cli20 0.1.2
A C++20 typed-schema command-line parser
Loading...
Searching...
No Matches
parser.hh File Reference
#include <array>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "cli/argument.hh"
#include "cli/constraint.hh"
#include "cli/error.hh"
#include "cli/help.hh"

Go to the source code of this file.

Classes

struct  cli::Token
 A single token produced by tokenize(). More...
struct  cli::TokenizeResult
 The result returned by tokenize(). More...
struct  cli::TokenizeResult::SmallVector< T, N >
struct  cli::TokenizerConfig
 Controls how tokenize() recognises option and separator syntax. More...
struct  cli::ParseResult< T >
 The result returned by Parser::parse() and the free cli::parse() function. More...
struct  cli::Parser< T >
 The main parsing engine for a typed argument specification. More...
struct  cli::Parser< T >::Lookup::OptionEntry
struct  cli::Parser< T >::Lookup::CommandEntry

Namespaces

namespace  cli

Macros

#define CLI20_TOKEN_STACK_CAPACITY   32

Enumerations

enum class  cli::TokenType : uint8_t { cli::option , cli::value , cli::positional , cli::command }
 Classifies a single token produced by tokenize(). More...

Functions

static constexpr auto cli::no_prefix () -> std::uint8_t
static constexpr auto cli::short_prefix () -> std::uint8_t
static constexpr auto cli::long_prefix (std::uint8_t i) -> std::uint8_t
static constexpr auto cli::has_prefix (std::uint8_t p) -> bool
static constexpr auto cli::is_short_prefix (std::uint8_t p) -> bool
auto cli::token_prefix_view (const Token &tok, const TokenizerConfig &cfg) -> std::string_view
 Retrieves the matched prefix string for an option token.
template<class OptionLookup, class CommandLookup>
auto cli::tokenize (std::span< const std::string_view > args, OptionLookup option_nargs, CommandLookup is_command, const TokenizerConfig &cfg={}) -> TokenizeResult
 Converts a raw argument span into an ordered sequence of typed tokens.
template<ArgumentSpec T>
auto cli::parse (int argc, char *argv[]) -> ParseResult< T >
 Convenience free function that parses argc/argv into type T.
template<ArgumentSpec T>
auto cli::parse_or_exit (int argc, char *argv[]) -> T
 Parses argc/argv and exits the process on failure.

Variables

constexpr std::size_t cli::token_stack_capacity = CLI20_TOKEN_STACK_CAPACITY
 Number of tokenizer tokens kept in inline stack storage before falling back to heap allocation.
static constexpr std::uint8_t cli::kNoPrefix = 0xff
static constexpr std::uint8_t cli::kShortPrefixBit = 0x80
static constexpr std::uint8_t cli::kPrefixIndexMask = 0x7f

Macro Definition Documentation

◆ CLI20_TOKEN_STACK_CAPACITY

#define CLI20_TOKEN_STACK_CAPACITY   32

Definition at line 29 of file parser.hh.