From 89a9bb79010527018a64848c0196ce8d995e8673 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Fri, 26 Jul 2024 00:11:38 +0200 Subject: [PATCH] nodes: add helper function to retrieve the pretty-printed node as a string --- compiler/nodes.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/nodes.py b/compiler/nodes.py index f0288a7..b73363e 100644 --- a/compiler/nodes.py +++ b/compiler/nodes.py @@ -45,7 +45,10 @@ class Node: return f"{self.__class__.__name__}({vals})" def pprint(self, depth: int | None = None, indent: str = "\t"): - print("\n".join(self._pprint(depth=depth, indent=indent))) + print(self._pretty(depth, indent)) + + def _pretty(self, depth: int | None = None, indent: str = "\t") -> str: + return "\n".join(self._pprint(depth=depth, indent=indent)) def _pprint(self, depth: int | None, indent: str, _depth: int = 0) -> list[str]: if depth is not None and _depth >= depth: