mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Make template parent optional
Not recommended, since you lose some type checking.
This commit is contained in:
parent
1897478480
commit
6b78338d1a
5 changed files with 24 additions and 8 deletions
|
@ -143,7 +143,7 @@ class Object(AstNode):
|
||||||
|
|
||||||
@validate("class_name")
|
@validate("class_name")
|
||||||
def gir_class_exists(self):
|
def gir_class_exists(self):
|
||||||
if not self.tokens["ignore_gir"] and self.gir_ns is not None:
|
if self.tokens["class_name"] and not self.tokens["ignore_gir"] and self.gir_ns is not None:
|
||||||
self.root.gir.validate_class(self.tokens["class_name"], self.tokens["namespace"])
|
self.root.gir.validate_class(self.tokens["class_name"], self.tokens["namespace"])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -153,7 +153,7 @@ class Object(AstNode):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def gir_class(self):
|
def gir_class(self):
|
||||||
if not self.tokens["ignore_gir"]:
|
if self.tokens["class_name"] and not self.tokens["ignore_gir"]:
|
||||||
return self.root.gir.get_class(self.tokens["class_name"], self.tokens["namespace"])
|
return self.root.gir.get_class(self.tokens["class_name"], self.tokens["namespace"])
|
||||||
|
|
||||||
|
|
||||||
|
@ -181,10 +181,13 @@ class Object(AstNode):
|
||||||
|
|
||||||
class Template(Object):
|
class Template(Object):
|
||||||
def emit_xml(self, xml: XmlEmitter):
|
def emit_xml(self, xml: XmlEmitter):
|
||||||
xml.start_tag("template", **{
|
if self.gir_class:
|
||||||
"class": self.tokens["name"],
|
parent = self.gir_class.glib_type_name
|
||||||
"parent": self.gir_class.glib_type_name if self.gir_class else self.tokens["class_name"],
|
elif self.tokens["class_name"]:
|
||||||
})
|
parent = self.tokens["class_name"]
|
||||||
|
else:
|
||||||
|
parent = None
|
||||||
|
xml.start_tag("template", **{"class": self.tokens["name"]}, parent=parent)
|
||||||
for child in self.children:
|
for child in self.children:
|
||||||
child.emit_xml(xml)
|
child.emit_xml(xml)
|
||||||
xml.end_tag()
|
xml.end_tag()
|
||||||
|
|
|
@ -140,8 +140,12 @@ def parse(tokens) -> T.Tuple[ast.UI, T.Optional[MultipleErrors]]:
|
||||||
Sequence(
|
Sequence(
|
||||||
Keyword("template"),
|
Keyword("template"),
|
||||||
UseIdent("name").expected("template class name"),
|
UseIdent("name").expected("template class name"),
|
||||||
Op(":").expected("`:`"),
|
Optional(
|
||||||
class_name.expected("parent class"),
|
Sequence(
|
||||||
|
Op(":"),
|
||||||
|
class_name.expected("parent class"),
|
||||||
|
)
|
||||||
|
),
|
||||||
object_content.expected("block"),
|
object_content.expected("block"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
3
tests/samples/template_no_parent.blp
Normal file
3
tests/samples/template_no_parent.blp
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
using Gtk 4.0;
|
||||||
|
|
||||||
|
template GtkListItem {}
|
5
tests/samples/template_no_parent.ui
Normal file
5
tests/samples/template_no_parent.ui
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk" version="4.0"/>
|
||||||
|
<template class="GtkListItem"></template>
|
||||||
|
</interface>
|
|
@ -131,6 +131,7 @@ class TestSamples(unittest.TestCase):
|
||||||
self.assert_sample("strings")
|
self.assert_sample("strings")
|
||||||
self.assert_sample("style")
|
self.assert_sample("style")
|
||||||
self.assert_sample("template")
|
self.assert_sample("template")
|
||||||
|
self.assert_sample("template_no_parent")
|
||||||
self.assert_sample("translated")
|
self.assert_sample("translated")
|
||||||
self.assert_sample("uint")
|
self.assert_sample("uint")
|
||||||
self.assert_sample("using")
|
self.assert_sample("using")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue