mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-05 16:09:07 -04:00
decompiler: Allow separating blocks
This will be useful for closure arguments.
This commit is contained in:
parent
638b5f1dc2
commit
479fe17589
1 changed files with 13 additions and 0 deletions
|
@ -52,6 +52,7 @@ class TextFragment:
|
|||
@dataclass
|
||||
class BlockInfo:
|
||||
terminator: T.Optional[TextFragment] = None
|
||||
separator: T.Optional[TextFragment] = None
|
||||
|
||||
|
||||
class LineType(Enum):
|
||||
|
@ -105,9 +106,17 @@ class DecompileCtx:
|
|||
if terminator := block.terminator:
|
||||
self.print(terminator.text, terminator.newline_after, terminator.indent)
|
||||
|
||||
def separate_block_elements(self) -> None:
|
||||
block = self._blocks[-1]
|
||||
if separator := block.separator:
|
||||
self.print(separator.text, separator.newline_after, separator.indent)
|
||||
|
||||
def end_block_with(self, text: str, newline_after: bool = True, indent: bool = True) -> None:
|
||||
self._blocks[-1].terminator = TextFragment(text, newline_after, indent)
|
||||
|
||||
def separate_block_elements_with(self, text: str, newline_after: bool = False, indent: bool = False) -> None:
|
||||
self._blocks[-1].separator = TextFragment(text, newline_after, indent)
|
||||
|
||||
def print(self, line: str, newline: bool = True, indent: bool = True) -> None:
|
||||
if line == "}" or line == "]":
|
||||
self._indent -= 1
|
||||
|
@ -206,7 +215,11 @@ def _decompile_element(
|
|||
ctx.start_block()
|
||||
gir = decompiler(ctx, gir, **args)
|
||||
|
||||
first = True
|
||||
for child in xml.children:
|
||||
if not first:
|
||||
ctx.separate_block_elements()
|
||||
first = False
|
||||
_decompile_element(ctx, gir, child)
|
||||
|
||||
ctx.end_block()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue