MCPcopy Create free account
hub / github.com/numpy/numpy / parse_def

Function parse_def

tools/npy_tempita/__init__.py:1002–1029  ·  view source on GitHub ↗
(tokens, name, context)

Source from the content-addressed store, hash-verified

1000
1001
1002def parse_def(tokens, name, context):
1003 first, start = tokens[0]
1004 tokens = tokens[1:]
1005 assert first.startswith('def ')
1006 first = first.split(None, 1)[1]
1007 if first.endswith(':'):
1008 first = first[:-1]
1009 if '(' not in first:
1010 func_name = first
1011 sig = ((), None, None, {})
1012 elif not first.endswith(')'):
1013 raise TemplateError("Function definition doesn't end with ): %s" %
1014 first, position=start, name=name)
1015 else:
1016 first = first[:-1]
1017 func_name, sig_text = first.split('(', 1)
1018 sig = parse_signature(sig_text, name, start)
1019 context = context + ('def',)
1020 content = []
1021 while 1:
1022 if not tokens:
1023 raise TemplateError(
1024 'Missing {{enddef}}',
1025 position=start, name=name)
1026 if (isinstance(tokens[0], tuple) and tokens[0][0] == 'enddef'):
1027 return ('def', start, func_name, sig, content), tokens[1:]
1028 next_chunk, tokens = parse_expr(tokens, name, context)
1029 content.append(next_chunk)
1030
1031
1032def parse_signature(sig_text, name, pos):

Callers 1

parse_exprFunction · 0.85

Calls 6

TemplateErrorClass · 0.85
parse_signatureFunction · 0.85
parse_exprFunction · 0.85
startswithMethod · 0.80
endswithMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected