arg_router  1.4.0
C++ command line argument parsing and routing
arg_router::parsing Namespace Reference

Classes

class  dynamic_token_adapter
 
class  parse_target
 
class  pre_parse_data_base
 
class  pre_parse_data
 
class  pre_parse_data< Validator, false >
 
class  pre_parse_data< Validator, true >
 
struct  token_type
 

Typedefs

using pre_parse_result = utility::result< pre_parse_action, multi_lang_exception >
 

Enumerations

enum class  pre_parse_action : std::uint8_t { skip_node , valid_node , skip_node_but_use_sub_targets }
 
enum class  prefix_type : std::uint8_t { }
 

Functions

template<typename T >
constexpr bool match (token_type token) noexcept
 
template<typename Node >
constexpr token_type node_token_type () noexcept
 
template<typename BaseNode , typename... DerivedAndParents>
constexpr auto clean_node_ancestry_list (const BaseNode &base_node, const DerivedAndParents &... derived_and_parents)
 
template<typename Node , typename... Parents>
bool is_runtime_disabled (const Node &node, const Parents &... parents) noexcept
 
constexpr std::string_view to_string (prefix_type prefix) noexcept
 
string to_string (const token_type &token)
 
string to_string (const vector< token_type > &view)
 
token_type get_token_type (std::string_view token)
 
template<typename Node >
token_type get_token_type ([[maybe_unused]] const Node &node, std::string_view token)
 
template<typename Node >
void unknown_argument_exception (const Node &node, token_type unknown_token)
 

Detailed Description

Namespace containing types and functions to aid parsing.

Typedef Documentation

◆ pre_parse_result

Policy-level pre-parse phase result type.

Definition at line 27 of file parsing.hpp.

Enumeration Type Documentation

◆ pre_parse_action

enum arg_router::parsing::pre_parse_action : std::uint8_t
strong

Owning nodes requested action by a pre-parse implementing policy.

Enumerator
skip_node 

This policy is not applicable to the tokens

valid_node 

This policy is applicable to the tokens

skip_node_but_use_sub_targets 

Same as skip_node, but any changes to the given tokens should be made permanent as long as no later policy returns skip_node

Definition at line 15 of file parsing.hpp.

◆ prefix_type

enum arg_router::parsing::prefix_type : std::uint8_t
strong

Enum for the prefix type on a token.

Enumerator
short_ 

Long prefix.

none 

Short prefix.

No prefix

Definition at line 13 of file token_type.hpp.

Function Documentation

◆ clean_node_ancestry_list()

template<typename BaseNode , typename... DerivedAndParents>
constexpr auto arg_router::parsing::clean_node_ancestry_list ( const BaseNode &  base_node,
const DerivedAndParents &...  derived_and_parents 
)
constexpr

Remove the leading entries from the node ancestry list that are derived from BaseNode.

To allow derived types to call the inherited implementations of the pre-parse and parse stages, we need to clean the multiple leading *this references that each parent method call will add. Due to the use of policies we can almost guarantee that OOP parents will not be confused with structural parents (i.e. parents in the tree). It is an almost guarantee because someone could create a custom node that allows for identical policies to it's tree parent and then not define a validator rule to prevent this - but I'd consider that to have bigger problems...

This method is used in tree_node, so anything derived from that that uses its inherited pre-parse and parse methods will not need to use this function.

Template Parameters
BaseNodeBase node type to be used to find derived types in derived_and_parents
DerivedAndParentsPack of (possibly) derived types in descending OOP ancestry order, and then parent tree nodes in ascending ancestry order
Parameters
base_nodeBase node instance
derived_and_parentsDerived type and parent node instances
Returns
Tuple of cleaned const reference ancestors in std::reference_wrapper

Definition at line 105 of file parsing.hpp.

◆ get_token_type() [1/2]

template<typename Node >
token_type arg_router::parsing::get_token_type ( [[maybe_unused] ] const Node &  node,
std::string_view  token 
)
inline

Overload that uses the naming policies of node to control the output.

If the target node is available, this should be the preferred overload.

Template Parameters
NodeTarget node type
Parameters
nodeNode instance
tokenToken to analyse
Returns
Token type

Definition at line 127 of file token_type.hpp.

◆ get_token_type() [2/2]

token_type arg_router::parsing::get_token_type ( std::string_view  token)
inline

Analyse token and return a pair consisting of the prefix type and token stripped of the token.

Parameters
tokenToken to analyse
Returns
Token type

Definition at line 103 of file token_type.hpp.

◆ is_runtime_disabled()

template<typename Node , typename... Parents>
bool arg_router::parsing::is_runtime_disabled ( const Node &  node,
const Parents &...  parents 
)
noexcept

Returns true if node or any of its parents are marked as runtime disabled.

Template Parameters
NodeCurrent node type
ParentsParent nodes' type
Parameters
nodeCurrent node instance
parentsParent nodes of node
Returns
True if the ancestry chain is effectively runtime disabled

Definition at line 133 of file parsing.hpp.

◆ match()

template<typename T >
constexpr bool arg_router::parsing::match ( token_type  token)
constexprnoexcept

Matches token to T by comparing the token against the long, short, or none name traits.

Template Parameters
TType providing the long, short, or none name methods
Parameters
tokenThe token to match against
Returns
True if token matches

Definition at line 36 of file parsing.hpp.

◆ node_token_type()

template<typename Node >
constexpr token_type arg_router::parsing::node_token_type ( )
constexprnoexcept

Returns the token_type of Node, the long form name is preferred if Node has both short and long form names.

Note
The error name is preferred over all others as this function is only used for exception string generation. If no known name method is detected, it is a compilation error
Template Parameters
NodeNode type
Returns
token_type

Definition at line 68 of file parsing.hpp.

◆ to_string() [1/3]

string arg_router::parsing::to_string ( const token_type token)
inline

Creates a string representation of token, it effectively recreates the original token on the command line.

Parameters
tokenToken to convert
Returns
String representation of token

Definition at line 74 of file token_type.hpp.

◆ to_string() [2/3]

string arg_router::parsing::to_string ( const vector< token_type > &  view)
inline

Creates a string representation of view.

Parameters
viewProcessed tokens to convert
Returns
String representation of view

Definition at line 85 of file token_type.hpp.

◆ to_string() [3/3]

constexpr std::string_view arg_router::parsing::to_string ( prefix_type  prefix)
constexprnoexcept

Creates a string version of prefix.

This uses config::long_prefix and config::short_prefix.

Parameters
prefixPrefix type to convert
Returns
String version of prefix

Definition at line 25 of file token_type.hpp.

◆ unknown_argument_exception()

template<typename Node >
void arg_router::parsing::unknown_argument_exception ( const Node &  node,
token_type  unknown_token 
)

Throws a multi_lang_exception with either a error_code::unknown_argument or a error_code::unknown_argument_with_suggestion if the data is available.

Template Parameters
NodeNode type throwing the exception
Parameters
nodeNode throwing the exception, used as a source for the utility::utf8::closest_matching_child_node(const Node& node, parsing::token_type token)
unknown_tokenThe token that caused the exception to be thrown

Definition at line 20 of file unknown_argument_handling.hpp.