@@ -60,22 +60,6 @@ find_cmd(std::tuple<std::reference_wrapper<Cmds const> const...> const haystack,
6060 // clang-format on
6161}
6262
63- struct TokensIndexes {
64- std::vector<std::size_t > positionals;
65- std::map<std::string_view, std::vector<std::size_t >> opts_n_flgs;
66-
67- [[nodiscard]] std::optional<std::size_t > first_pos_idx_after (std::size_t const offset) const noexcept {
68- if (this ->positionals .empty ()) return std::nullopt ;
69- std::size_t i = 0 ;
70- auto idx = this ->positionals [i];
71- while (idx <= offset) {
72- if (i + 1 >= this ->positionals .size ()) return std::nullopt ;
73- idx = this ->positionals [++i];
74- }
75- return idx;
76- }
77- };
78-
7963// +-----------------------+
8064// | CmdParser |
8165// +-----------------------+
@@ -94,9 +78,9 @@ class CmdParser {
9478 ArgsMap<Cmd const > operator ()(std::span<char const *> args) {
9579 auto scanner = Scanner (args);
9680 auto const tokens = scanner ();
97- auto const tokens_indexes = this -> index_tokens (tokens);
81+ auto const indexes = index_tokens (tokens);
9882 // TODO: check we did not receive unknown arguments (throw UnknownArgument)
99- auto map = this ->get_args_map (tokens, tokens_indexes , 0 , -1 );
83+ auto map = this ->get_args_map (tokens, indexes , 0 , -1 );
10084 return map;
10185 }
10286
@@ -122,31 +106,6 @@ class CmdParser {
122106
123107 auto get_cmd_fmt () const noexcept { return CmdFmt (this ->cmd_ref .get (), this ->extra_info ); }
124108
125- auto index_tokens (std::span<Token const > const tokens) {
126- auto indexes = TokensIndexes ();
127- if (!tokens.empty ()) { // should never happen
128- for (std::size_t index = 1 ; index < tokens.size (); ++index) {
129- auto const &tok = tokens[index];
130- switch (tok.type ) {
131- case TokenType::PROG_NAME: break ;
132- case TokenType::DASH_DASH:
133- // +1 to ignore the dash-dash
134- for (std::size_t offset = index + 1 ; offset < tokens.size (); ++offset) {
135- indexes.positionals .push_back (offset);
136- }
137- index = tokens.size (); // break below refers to the switch, not the for loop
138- break ;
139- case TokenType::FLG: [[fallthrough]];
140- case TokenType::OPT_OR_FLG_LONG: [[fallthrough]];
141- case TokenType::OPT_LONG_AND_VALUE: [[fallthrough]];
142- case TokenType::OPT_SHORT_AND_VALUE: indexes.opts_n_flgs [*tok.name ].push_back (index); break ;
143- case TokenType::IDENTIFIER: indexes.positionals .push_back (index); break ;
144- }
145- }
146- }
147- return indexes;
148- }
149-
150109 auto get_args_map (
151110 std::span<Token const > const tokens,
152111 TokensIndexes const &indexes,
0 commit comments