MCPcopy Create free account
hub / github.com/PlatformLab/NanoLog / parse_atom

Function parse_atom

preprocessor/docopt.py:402–425  ·  view source on GitHub ↗

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

(tokens, options)

Source from the content-addressed store, hash-verified

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

Callers 1

parse_seqFunction · 0.85

Calls 8

parse_exprFunction · 0.85
OptionsShortcutClass · 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