v3: gstack-code-gen 生成
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class CopybookPreprocessor:
|
||||
def __init__(self, paths=None):
|
||||
self.paths = paths or ["./copybooks"]
|
||||
|
||||
def expand(self, text: str) -> str:
|
||||
def _rep(m):
|
||||
n = m.group(1).strip()
|
||||
for p in self.paths:
|
||||
for e in ("", ".cpy", ".cbl"):
|
||||
f = Path(p) / f"{n}{e}"
|
||||
if f.exists():
|
||||
return f" *> COPY {n}\n{f.read_text()}\n *> END COPY {n}"
|
||||
return f" *> COPY {n} NOT FOUND"
|
||||
return re.sub(r'^ COPY\s+(\w+(?:-\w+)?)\s*\.', _rep, text, flags=re.MULTILINE)
|
||||
Reference in New Issue
Block a user