| 319 | } |
| 320 | |
| 321 | parse_result parse_sequence( |
| 322 | detail::token_iterator const & tokens, const option_style & style) const |
| 323 | { |
| 324 | LYRA_PRINT_SCOPE("arguments::parse_sequence"); |
| 325 | LYRA_PRINT_DEBUG("(?)", get_usage_text(style), |
| 326 | "?=", tokens ? tokens.argument().name : "", ".."); |
| 327 | |
| 328 | std::vector<std::size_t> parsing_count(parsers.size(), 0); |
| 329 | auto p_result = parse_result::ok( |
| 330 | detail::parse_state(parser_result_type::empty_match, tokens)); |
| 331 | |
| 332 | // Sequential parsing means we walk through the given parsers in order |
| 333 | // and exhaust the tokens as we match parsers. |
| 334 | auto parsing_count_i = parsing_count.begin(); |
| 335 | for (auto & p : parsers) |
| 336 | { |
| 337 | auto parser_cardinality = p->cardinality(); |
| 338 | // This is a greedy sequential parsing algo. As it parses the |
| 339 | // current argument as much as possible. |
| 340 | do |
| 341 | { |
| 342 | auto subresult |
| 343 | = p->parse(p_result.value().remainingTokens(), style); |
| 344 | if (subresult.has_value() |
| 345 | && parser_result_type::short_circuit_all |
| 346 | == subresult.value().type()) |
| 347 | return subresult; |
| 348 | if (!subresult) break; |
| 349 | if (parser_result_type::no_match == subresult.value().type()) |
| 350 | { |
| 351 | LYRA_PRINT_DEBUG("(!)", get_usage_text(style), "!=", |
| 352 | p_result.value().remainingTokens() |
| 353 | ? p_result.value().remainingTokens().argument().name |
| 354 | : "", |
| 355 | "==>", subresult.value().type()); |
| 356 | break; |
| 357 | } |
| 358 | if (parser_result_type::matched == subresult.value().type()) |
| 359 | { |
| 360 | LYRA_PRINT_DEBUG("(=)", get_usage_text(style), "==", |
| 361 | p_result.value().remainingTokens() |
| 362 | ? p_result.value().remainingTokens().argument().name |
| 363 | : "", |
| 364 | "==>", subresult.value().type()); |
| 365 | *parsing_count_i += 1; |
| 366 | p_result = subresult; |
| 367 | } |
| 368 | if (parser_result_type::empty_match == subresult.value().type()) |
| 369 | { |
| 370 | LYRA_PRINT_DEBUG("(=)", get_usage_text(style), "==", |
| 371 | p_result.value().remainingTokens() |
| 372 | ? p_result.value().remainingTokens().argument().name |
| 373 | : "", |
| 374 | "==>", subresult.value().type()); |
| 375 | *parsing_count_i += 1; |
| 376 | } |
| 377 | } |
| 378 | while (p_result.value().have_tokens() |
nothing calls this directly
no test coverage detected