v1: executing-plans 模式生成,54 文件 1320 行 Python

This commit is contained in:
hangshuo652
2026-05-24 10:02:52 +08:00
commit 06b295f780
55 changed files with 1749 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
import re
from pathlib import Path
class CopybookPreprocessor:
def __init__(self, search_paths: list[str] | None = None):
self.search_paths = search_paths or ["./copybooks"]
def expand(self, source_text: str) -> str:
pattern = re.compile(
r'^ COPY\s+(\w+(?:-\w+)?)\s*(?:\.|$.|$)',
re.MULTILINE)
return pattern.sub(self._replace_copy, source_text)
def _replace_copy(self, match):
name = match.group(1).strip()
for path in self.search_paths:
for ext in ["", ".cpy", ".cbl", ".copy"]:
p = Path(path) / f"{name}{ext}"
if p.exists():
content = p.read_text()
return f" *> COPY {name}\n{content}\n *> END COPY {name}"
return f" *> COPY {name} NOT FOUND"