mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-05 16:09:07 -04:00
Report duplicate object IDs
This commit is contained in:
parent
dfb09b9357
commit
241668fb94
5 changed files with 68 additions and 1 deletions
|
@ -51,6 +51,11 @@ class UI(AstNode):
|
|||
return gir_ctx
|
||||
|
||||
|
||||
@lazy_prop
|
||||
def objects_by_id(self):
|
||||
return { obj.id: obj for obj in self.iterate_children_recursive() if hasattr(obj, "id") }
|
||||
|
||||
|
||||
@validate()
|
||||
def gir_errors(self):
|
||||
# make sure gir is loaded
|
||||
|
@ -66,6 +71,19 @@ class UI(AstNode):
|
|||
self.children[Template][1].group.start)
|
||||
|
||||
|
||||
@validate()
|
||||
def unique_ids(self):
|
||||
passed = {}
|
||||
for obj in self.iterate_children_recursive():
|
||||
if obj.tokens["id"] is None:
|
||||
continue
|
||||
|
||||
if obj.tokens["id"] in passed:
|
||||
token = obj.group.tokens["id"]
|
||||
raise CompileError(f"Duplicate object ID '{obj.tokens['id']}'", token.start, token.end)
|
||||
passed[obj.tokens["id"]] = obj
|
||||
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.start_tag("interface")
|
||||
for x in self.children:
|
||||
|
|
|
@ -118,6 +118,12 @@ class AstNode:
|
|||
yield from child.get_semantic_tokens()
|
||||
|
||||
|
||||
def iterate_children_recursive(self) -> T.Iterator["AstNode"]:
|
||||
yield self
|
||||
for child in self.children:
|
||||
yield from child.iterate_children_recursive()
|
||||
|
||||
|
||||
def validate(token_name=None, end_token_name=None, skip_incomplete=False):
|
||||
""" Decorator for functions that validate an AST node. Exceptions raised
|
||||
during validation are marked with range information from the tokens. Also
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue