From 8a545d596b2ee82650852a48eb28259aeb66be64 Mon Sep 17 00:00:00 2001 From: Gleb Smirnov Date: Sat, 22 Jan 2022 09:42:49 +0300 Subject: [PATCH] feat: add support of internal children --- blueprintcompiler/ast.py | 7 ++++++- blueprintcompiler/decompiler.py | 4 +++- blueprintcompiler/parser.py | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/blueprintcompiler/ast.py b/blueprintcompiler/ast.py index 6a96b8a..a7f1f65 100644 --- a/blueprintcompiler/ast.py +++ b/blueprintcompiler/ast.py @@ -195,7 +195,12 @@ class Template(Object): class Child(AstNode): def emit_xml(self, xml: XmlEmitter): - xml.start_tag("child", type=self.tokens["child_type"]) + child_type = internal_child = None + if self.tokens["internal_child"]: + internal_child = self.tokens["child_type"] + else: + child_type = self.tokens["child_type"] + xml.start_tag("child", type=child_type, internal_child=internal_child) for child in self.children: child.emit_xml(xml) xml.end_tag() diff --git a/blueprintcompiler/decompiler.py b/blueprintcompiler/decompiler.py index 85e099d..aa315ec 100644 --- a/blueprintcompiler/decompiler.py +++ b/blueprintcompiler/decompiler.py @@ -261,9 +261,11 @@ def decompile_object(ctx, gir, klass, id=None): @decompiler("child") -def decompile_child(ctx, gir, type=None): +def decompile_child(ctx, gir, type=None, internal_child=None): if type is not None: ctx.print(f"[{type}]") + elif internal_child is not None: + ctx.print(f"[internal-child {internal_child}]") return gir diff --git a/blueprintcompiler/parser.py b/blueprintcompiler/parser.py index 25ab1a1..0c6d9fe 100644 --- a/blueprintcompiler/parser.py +++ b/blueprintcompiler/parser.py @@ -107,6 +107,7 @@ def parse(tokens) -> T.Tuple[ast.UI, T.Optional[MultipleErrors]]: Sequence( Optional(Sequence( OpenBracket(), + Optional(Sequence(Keyword("internal-child"), UseLiteral("internal_child", True))), UseIdent("child_type").expected("a child type"), CloseBracket(), )),