|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -import re |
4 | | -from typing import Match |
5 | 3 |
|
6 | | -from .components import transformer |
| 4 | +class Compiler: |
| 5 | + def compile(self, input_string: str) -> str: |
| 6 | + tokens = self.tokenize(input_string) |
| 7 | + parsed = self.parse(tokens) |
| 8 | + return self.transform(parsed) |
7 | 9 |
|
8 | | -BIRD_TAG_PATTERN = re.compile(r"<bird:(\w+)([^>]*)>(.*?)</bird:\1>") |
| 10 | + def tokenize(self, input_string: str) -> str: ... |
9 | 11 |
|
| 12 | + def parse(self, tokens: str) -> str: ... |
10 | 13 |
|
11 | | -class BirdCompiler: |
12 | | - def __init__(self) -> None: |
13 | | - self.transformer = transformer |
14 | | - |
15 | | - def compile(self, content: str) -> str: |
16 | | - parts = content.splitlines() |
17 | | - result = [] |
18 | | - |
19 | | - for part in parts: |
20 | | - if match := BIRD_TAG_PATTERN.search(part): |
21 | | - transformed = [item for item in self.transform_bird_line(part, match)] |
22 | | - result.append("".join(transformed)) |
23 | | - else: |
24 | | - result.append(part) |
25 | | - |
26 | | - return "\n".join(result) |
27 | | - |
28 | | - def transform_bird_line(self, line: str, match: Match[str]): |
29 | | - start, end = match.span() |
30 | | - |
31 | | - yield line[:start].strip() |
32 | | - |
33 | | - tag_name, attrs, content = match.groups() |
34 | | - yield self.transformer.transform(tag_name, attrs, content) |
35 | | - |
36 | | - yield line[end:].strip() |
| 14 | + def transform(self, parsed_content: str) -> str: ... |
0 commit comments