import sys import re if len(sys.argv) != 2: print(f"Usage: {sys.argv[0]} ") sys.exit(1) filename = sys.argv[1] with open(filename, "r", encoding="utf-8") as f: content = f.read() pattern = re.compile( r"""async\s+fn\s+ # async fn (\w+)\s* # имя функции \(([^)]*)\)\s* # аргументы ->\s*([^{\n]+)\s* # возвращаемый тип \{\s*\n # открывающая фигурная скобка + новая строка (.*?) # тело функции (ленивый захват) ^\} # закрывающая фигурная скобка на отдельной строке """, re.DOTALL | re.MULTILINE | re.VERBOSE, ) def replacer(match): name = match.group(1) args = match.group(2) ret = match.group(3).strip() body = match.group(4) # Добавляем 4 пробела в начале каждой строки тела indented_body = "\n".join(" " + line if line.strip() else "" for line in body.splitlines()) return ( f"fn {name}({args}) -> impl std::future::Future {{\n" f" async {{\n" f"{indented_body}\n" f" }}\n" f"}}" ) new_content = pattern.sub(replacer, content) with open(filename, "w", encoding="utf-8") as f: f.write(new_content)