mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
feat: add support of internal children
This commit is contained in:
parent
1bd7c37061
commit
8a545d596b
3 changed files with 10 additions and 2 deletions
|
@ -195,7 +195,12 @@ class Template(Object):
|
||||||
|
|
||||||
class Child(AstNode):
|
class Child(AstNode):
|
||||||
def emit_xml(self, xml: XmlEmitter):
|
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:
|
for child in self.children:
|
||||||
child.emit_xml(xml)
|
child.emit_xml(xml)
|
||||||
xml.end_tag()
|
xml.end_tag()
|
||||||
|
|
|
@ -261,9 +261,11 @@ def decompile_object(ctx, gir, klass, id=None):
|
||||||
|
|
||||||
|
|
||||||
@decompiler("child")
|
@decompiler("child")
|
||||||
def decompile_child(ctx, gir, type=None):
|
def decompile_child(ctx, gir, type=None, internal_child=None):
|
||||||
if type is not None:
|
if type is not None:
|
||||||
ctx.print(f"[{type}]")
|
ctx.print(f"[{type}]")
|
||||||
|
elif internal_child is not None:
|
||||||
|
ctx.print(f"[internal-child {internal_child}]")
|
||||||
return gir
|
return gir
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,7 @@ def parse(tokens) -> T.Tuple[ast.UI, T.Optional[MultipleErrors]]:
|
||||||
Sequence(
|
Sequence(
|
||||||
Optional(Sequence(
|
Optional(Sequence(
|
||||||
OpenBracket(),
|
OpenBracket(),
|
||||||
|
Optional(Sequence(Keyword("internal-child"), UseLiteral("internal_child", True))),
|
||||||
UseIdent("child_type").expected("a child type"),
|
UseIdent("child_type").expected("a child type"),
|
||||||
CloseBracket(),
|
CloseBracket(),
|
||||||
)),
|
)),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue