mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-05 16:09:07 -04:00
Validate parent object for accessibility and layout
This commit is contained in:
parent
2224f0958c
commit
e759569c3f
8 changed files with 40 additions and 4 deletions
|
@ -106,6 +106,14 @@ def _get_docs(gir, name):
|
|||
|
||||
|
||||
class A11y(AstNode):
|
||||
@validate("accessibility")
|
||||
def container_is_widget(self):
|
||||
widget = self.root.gir.get_type("Widget", "Gtk")
|
||||
container_type = self.parent_by_type(ast.Object).gir_class
|
||||
if container_type and not container_type.assignable_to(widget):
|
||||
raise CompileError(f"{container_type.full_name} is not a {widget.full_name}, so it doesn't have accessibility properties")
|
||||
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.start_tag("accessibility")
|
||||
for child in self.children:
|
||||
|
@ -158,7 +166,7 @@ a11y_prop = Group(
|
|||
a11y = Group(
|
||||
A11y,
|
||||
Sequence(
|
||||
Keyword("accessibility"),
|
||||
Keyword("accessibility", True),
|
||||
OpenBlock().expected("`{`"),
|
||||
Until(a11y_prop, CloseBlock()),
|
||||
)
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
|
||||
from ..ast import BaseAttribute
|
||||
from ..ast_utils import AstNode
|
||||
from ..ast_utils import AstNode, validate
|
||||
from ..completions_utils import *
|
||||
from ..lsp_utils import Completion, CompletionItemKind
|
||||
from ..parse_tree import *
|
||||
|
@ -28,6 +28,14 @@ from ..xml_emitter import XmlEmitter
|
|||
|
||||
|
||||
class Layout(AstNode):
|
||||
@validate("layout")
|
||||
def container_is_widget(self):
|
||||
widget = self.root.gir.get_type("Widget", "Gtk")
|
||||
container_type = self.parent_by_type(ast.Object).gir_class
|
||||
if container_type and not container_type.assignable_to(widget):
|
||||
raise CompileError(f"{container_type.full_name} is not a {widget.full_name}, so it doesn't have layout properties")
|
||||
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.start_tag("layout")
|
||||
for child in self.children:
|
||||
|
@ -56,7 +64,7 @@ layout_prop = Group(
|
|||
layout = Group(
|
||||
Layout,
|
||||
Sequence(
|
||||
Keyword("layout"),
|
||||
Keyword("layout", True),
|
||||
OpenBlock().expected("`{`"),
|
||||
Until(layout_prop, CloseBlock()),
|
||||
)
|
||||
|
|
|
@ -514,12 +514,16 @@ class UseLiteral(ParseNode):
|
|||
|
||||
class Keyword(ParseNode):
|
||||
""" Matches the given identifier. """
|
||||
def __init__(self, kw):
|
||||
def __init__(self, kw, set_token=False):
|
||||
self.kw = kw
|
||||
self.set_token = True
|
||||
|
||||
def _parse(self, ctx: ParseContext):
|
||||
token = ctx.next_token()
|
||||
if token.type != TokenType.IDENT:
|
||||
return False
|
||||
|
||||
if self.set_token:
|
||||
ctx.set_group_val(self.kw, True, token)
|
||||
|
||||
return str(token) == self.kw
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue