MCPcopy Create free account
hub / github.com/docopt/docopt.cpp / parse_atom

Function parse_atom

docopt.cpp:350–395  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

348static PatternList parse_expr(Tokens& tokens, std::vector<Option>& options);
349
350static 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
397static PatternList parse_seq(Tokens& tokens, std::vector<Option>& options)
398{

Callers 1

parse_seqFunction · 0.85

Calls 7

parse_exprFunction · 0.85
DocoptLanguageErrorClass · 0.85
starts_withFunction · 0.85
parse_longFunction · 0.85
parse_shortFunction · 0.85
is_argument_specFunction · 0.85
popMethod · 0.80

Tested by

no test coverage detected