(tokens, name, context)
| 912 | |
| 913 | |
| 914 | def parse_def(tokens, name, context): |
| 915 | first, start = tokens[0] |
| 916 | tokens = tokens[1:] |
| 917 | assert first.startswith("def ") |
| 918 | first = first.split(None, 1)[1] |
| 919 | first = first.removesuffix(":") |
| 920 | if "(" not in first: |
| 921 | func_name = first |
| 922 | sig = ((), None, None, {}) |
| 923 | elif not first.endswith(")"): |
| 924 | raise TemplateError( |
| 925 | f"Function definition doesn't end with ): {first}", |
| 926 | position=start, |
| 927 | name=name, |
| 928 | ) |
| 929 | else: |
| 930 | first = first[:-1] |
| 931 | func_name, sig_text = first.split("(", 1) |
| 932 | sig = parse_signature(sig_text, name, start) |
| 933 | context = context + ("def",) |
| 934 | content = [] |
| 935 | while 1: |
| 936 | if not tokens: |
| 937 | raise TemplateError("Missing {{enddef}}", position=start, name=name) |
| 938 | if isinstance(tokens[0], tuple) and tokens[0][0] == "enddef": |
| 939 | return ("def", start, func_name, sig, content), tokens[1:] |
| 940 | next_chunk, tokens = parse_expr(tokens, name, context) |
| 941 | content.append(next_chunk) |
| 942 | |
| 943 | |
| 944 | def parse_signature(sig_text, name, pos): |
no test coverage detected
searching dependent graphs…