(tokens, name, context)
| 1000 | |
| 1001 | |
| 1002 | def 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 | |
| 1032 | def parse_signature(sig_text, name, pos): |
no test coverage detected