| 348 | static PatternList parse_expr(Tokens& tokens, std::vector<Option>& options); |
| 349 | |
| 350 | static PatternList parse_atom(Tokens& tokens, std::vector<Option>& options) |
| 351 | { |
| 352 | // atom ::= '(' expr ')' | '[' expr ']' | 'options' |
| 353 | // | long | shorts | argument | command ; |
| 354 | |
| 355 | std::string const& token = tokens.current(); |
| 356 | |
| 357 | PatternList ret; |
| 358 | |
| 359 | if (token == "[") { |
| 360 | tokens.pop(); |
| 361 | |
| 362 | auto expr = parse_expr(tokens, options); |
| 363 | |
| 364 | auto trailing = tokens.pop(); |
| 365 | if (trailing != "]") { |
| 366 | throw DocoptLanguageError("Mismatched '['"); |
| 367 | } |
| 368 | |
| 369 | ret.emplace_back(std::make_shared<Optional>(std::move(expr))); |
| 370 | } else if (token=="(") { |
| 371 | tokens.pop(); |
| 372 | |
| 373 | auto expr = parse_expr(tokens, options); |
| 374 | |
| 375 | auto trailing = tokens.pop(); |
| 376 | if (trailing != ")") { |
| 377 | throw DocoptLanguageError("Mismatched '('"); |
| 378 | } |
| 379 | |
| 380 | ret.emplace_back(std::make_shared<Required>(std::move(expr))); |
| 381 | } else if (token == "options") { |
| 382 | tokens.pop(); |
| 383 | ret.emplace_back(std::make_shared<OptionsShortcut>()); |
| 384 | } else if (starts_with(token, "--") && token != "--") { |
| 385 | ret = parse_long(tokens, options); |
| 386 | } else if (starts_with(token, "-") && token != "-" && token != "--") { |
| 387 | ret = parse_short(tokens, options); |
| 388 | } else if (is_argument_spec(token)) { |
| 389 | ret.emplace_back(std::make_shared<Argument>(tokens.pop())); |
| 390 | } else { |
| 391 | ret.emplace_back(std::make_shared<Command>(tokens.pop())); |
| 392 | } |
| 393 | |
| 394 | return ret; |
| 395 | } |
| 396 | |
| 397 | static PatternList parse_seq(Tokens& tokens, std::vector<Option>& options) |
| 398 | { |
no test coverage detected