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

Function parse_shorts

preprocessor/docopt.py:334–366  ·  view source on GitHub ↗

shorts ::= '-' ( chars )* [ [ ' ' ] chars ] ;

(tokens, options)

Source from the content-addressed store, hash-verified

332
333
334def parse_shorts(tokens, options):
335 """shorts ::= '-' ( chars )* [ [ ' ' ] chars ] ;"""
336 token = tokens.move()
337 assert token.startswith('-') and not token.startswith('--')
338 left = token.lstrip('-')
339 parsed = []
340 while left != '':
341 short, left = '-' + left[0], left[1:]
342 similar = [o for o in options if o.short == short]
343 if len(similar) > 1:
344 raise tokens.error('%s is specified ambiguously %d times' %
345 (short, len(similar)))
346 elif len(similar) < 1:
347 o = Option(short, None, 0)
348 options.append(o)
349 if tokens.error is DocoptExit:
350 o = Option(short, None, 0, True)
351 else: # why copying is necessary here?
352 o = Option(short, similar[0].long,
353 similar[0].argcount, similar[0].value)
354 value = None
355 if o.argcount != 0:
356 if left == '':
357 if tokens.current() in [None, '--']:
358 raise tokens.error('%s requires argument' % short)
359 value = tokens.move()
360 else:
361 value = left
362 left = ''
363 if tokens.error is DocoptExit:
364 o.value = value if value is not None else True
365 parsed.append(o)
366 return parsed
367
368
369def parse_pattern(source, options):

Callers 2

parse_atomFunction · 0.85
parse_argvFunction · 0.85

Calls 3

OptionClass · 0.85
moveMethod · 0.80
currentMethod · 0.80

Tested by

no test coverage detected