MCPcopy Index your code
hub / github.com/docopt/docopt / parse_atom

Function parse_atom

docopt.py:404–427  ·  view source on GitHub ↗

atom ::= '(' expr ')' | '[' expr ']' | 'options' | long | shorts | argument | command ;

(tokens, options)

Source from the content-addressed store, hash-verified

402
403
404def parse_atom(tokens, options):
405 """atom ::= '(' expr ')' | '[' expr ']' | 'options'
406 | long | shorts | argument | command ;
407 """
408 token = tokens.current()
409 result = []
410 if token in '([':
411 tokens.move()
412 matching, pattern = {'(': [')', Required], '[': [']', Optional]}[token]
413 result = pattern(*parse_expr(tokens, options))
414 if tokens.move() != matching:
415 raise tokens.error("unmatched '%s'" % token)
416 return [result]
417 elif token == 'options':
418 tokens.move()
419 return [AnyOptions()]
420 elif token.startswith('--') and token != '--':
421 return parse_long(tokens, options)
422 elif token.startswith('-') and token not in ('-', '--'):
423 return parse_shorts(tokens, options)
424 elif token.startswith('<') and token.endswith('>') or token.isupper():
425 return [Argument(tokens.move())]
426 else:
427 return [Command(tokens.move())]
428
429
430def parse_argv(tokens, options, options_first=False):

Callers 1

parse_seqFunction · 0.85

Calls 8

parse_exprFunction · 0.85
AnyOptionsClass · 0.85
parse_longFunction · 0.85
parse_shortsFunction · 0.85
ArgumentClass · 0.85
CommandClass · 0.85
currentMethod · 0.80
moveMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…