(tokens, name, context)
| 850 | |
| 851 | |
| 852 | def parse_for(tokens, name, context): |
| 853 | first, pos = tokens[0] |
| 854 | tokens = tokens[1:] |
| 855 | context = ("for",) + context |
| 856 | content = [] |
| 857 | assert first.startswith("for "), first |
| 858 | first = first.removesuffix(":") |
| 859 | first = first[3:].strip() |
| 860 | match = in_re.search(first) |
| 861 | if not match: |
| 862 | raise TemplateError(f'Bad for (no "in") in {first!r}', position=pos, name=name) |
| 863 | vars = first[: match.start()] |
| 864 | if "(" in vars: |
| 865 | raise TemplateError( |
| 866 | f"You cannot have () in the variable section of a for loop ({vars!r})", |
| 867 | position=pos, |
| 868 | name=name, |
| 869 | ) |
| 870 | vars = tuple(v.strip() for v in first[: match.start()].split(",") if v.strip()) |
| 871 | expr = first[match.end():] |
| 872 | while 1: |
| 873 | if not tokens: |
| 874 | raise TemplateError("No {{endfor}}", position=pos, name=name) |
| 875 | if isinstance(tokens[0], tuple) and tokens[0][0] == "endfor": |
| 876 | return ("for", pos, vars, expr, content), tokens[1:] |
| 877 | next_chunk, tokens = parse_expr(tokens, name, context) |
| 878 | content.append(next_chunk) |
| 879 | |
| 880 | |
| 881 | def parse_default(tokens, name, context): |
no test coverage detected
searching dependent graphs…