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

Function parse_one_cond

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

Source from the content-addressed store, hash-verified

911
912
913def parse_one_cond(tokens, name, context):
914 (first, pos), tokens = tokens[0], tokens[1:]
915 content = []
916 if first.endswith(':'):
917 first = first[:-1]
918 if first.startswith('if '):
919 part = ('if', pos, first[3:].lstrip(), content)
920 elif first.startswith('elif '):
921 part = ('elif', pos, first[5:].lstrip(), content)
922 elif first == 'else':
923 part = ('else', pos, None, content)
924 else:
925 assert 0, "Unexpected token %r at %s" % (first, pos)
926 while 1:
927 if not tokens:
928 raise TemplateError(
929 'No {{endif}}',
930 position=pos, name=name)
931 if (isinstance(tokens[0], tuple) and (
932 tokens[0][0] == 'endif' or tokens[0][0].startswith(
933 'elif ') or tokens[0][0] == 'else')):
934 return part, tokens
935 next_chunk, tokens = parse_expr(tokens, name, context)
936 content.append(next_chunk)
937
938
939def parse_for(tokens, name, context):

Callers 1

parse_condFunction · 0.85

Calls 5

TemplateErrorClass · 0.85
parse_exprFunction · 0.85
endswithMethod · 0.80
startswithMethod · 0.80
lstripMethod · 0.80

Tested by

no test coverage detected