Fix 'template' keyword in list item factories

This commit is contained in:
James Westman 2023-05-13 20:15:28 -05:00
parent 5a782c653b
commit 46e467bbfb
7 changed files with 30 additions and 13 deletions

View file

@ -36,6 +36,16 @@ class ValueTypeCtx:
class ScopeCtx:
node: AstNode
@cached_property
def template(self):
from .ui import UI
from .gtk_list_item_factory import ExtListItemFactory
if isinstance(self.node, UI):
return self.node.template
elif isinstance(self.node, ExtListItemFactory):
return self.node
@cached_property
def objects(self) -> T.Dict[str, Object]:
return {
@ -45,6 +55,8 @@ class ScopeCtx:
}
def validate_unique_ids(self) -> None:
from .gtk_list_item_factory import ExtListItemFactory
passed = {}
for obj in self._iter_recursive(self.node):
if obj.tokens["id"] is None:
@ -52,7 +64,9 @@ class ScopeCtx:
if obj.tokens["id"] in passed:
token = obj.group.tokens["id"]
if not isinstance(obj, Template):
if not isinstance(obj, Template) and not isinstance(
obj, ExtListItemFactory
):
raise CompileError(
f"Duplicate object ID '{obj.tokens['id']}'",
token.start,

View file

@ -106,7 +106,7 @@ class LiteralExpr(ExprBase):
if isinstance(self.literal.value, IdentLiteral):
if object := self.context[ScopeCtx].objects.get(self.literal.value.ident):
return not isinstance(object, Template)
return not object.gir_class.incomplete
return True

View file

@ -96,11 +96,6 @@ class Signal(AstNode):
# This happens for classes defined by the app itself
return
if isinstance(self.parent.parent, Template):
# If the signal is part of a template, it might be defined by
# the application and thus not in gir
return
if self.gir_signal is None:
raise CompileError(
f"Class {self.gir_class.full_name} does not contain a signal called {self.tokens['name']}",

View file

@ -7,7 +7,7 @@ from .contexts import ScopeCtx
class ExtListItemFactory(AstNode):
grammar = [Keyword("template"), Optional(TypeName), ObjectContent]
grammar = [UseExact("id", "template"), Optional(TypeName), ObjectContent]
@property
def type_name(self) -> T.Optional[TypeName]: