mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-05 16:09:07 -04:00
Improved validation
This commit is contained in:
parent
981c2e3b7d
commit
f1e1811e1f
13 changed files with 51 additions and 13 deletions
|
@ -108,10 +108,7 @@ 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")
|
||||
self.validate_parent_type("Gtk", "Widget", "accessibility properties")
|
||||
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
|
||||
from .. import ast
|
||||
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,10 @@ from ..xml_emitter import XmlEmitter
|
|||
|
||||
|
||||
class Filters(AstNode):
|
||||
@validate()
|
||||
def container_is_file_filter(self):
|
||||
self.validate_parent_type("Gtk", "FileFilter", "file filter properties")
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.start_tag(self.tokens["tag_name"])
|
||||
for child in self.children:
|
||||
|
@ -46,7 +50,7 @@ def create_node(tag_name: str, singular: str):
|
|||
return Group(
|
||||
Filters,
|
||||
Statement(
|
||||
Keyword(tag_name),
|
||||
Keyword(tag_name, True),
|
||||
UseLiteral("tag_name", tag_name),
|
||||
OpenBracket(),
|
||||
Delimited(
|
||||
|
|
|
@ -30,10 +30,7 @@ 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")
|
||||
self.validate_parent_type("Gtk", "Widget", "layout properties")
|
||||
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
|
|
|
@ -28,6 +28,10 @@ from ..xml_emitter import XmlEmitter
|
|||
|
||||
|
||||
class Widgets(AstNode):
|
||||
@validate("widgets")
|
||||
def container_is_size_group(self):
|
||||
self.validate_parent_type("Gtk", "SizeGroup", "size group properties")
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.start_tag("widgets")
|
||||
for child in self.children:
|
||||
|
@ -57,7 +61,7 @@ class Widget(AstNode):
|
|||
widgets = Group(
|
||||
Widgets,
|
||||
Statement(
|
||||
Keyword("widgets"),
|
||||
Keyword("widgets", True),
|
||||
OpenBracket(),
|
||||
Delimited(
|
||||
Group(
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
|
||||
from .. import ast
|
||||
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,10 @@ from ..xml_emitter import XmlEmitter
|
|||
|
||||
|
||||
class Styles(AstNode):
|
||||
@validate("styles")
|
||||
def container_is_widget(self):
|
||||
self.validate_parent_type("Gtk", "Widget", "style classes")
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.start_tag("style")
|
||||
for child in self.children:
|
||||
|
@ -43,7 +47,7 @@ class StyleClass(AstNode):
|
|||
styles = Group(
|
||||
Styles,
|
||||
Statement(
|
||||
Keyword("styles"),
|
||||
Keyword("styles", True),
|
||||
OpenBracket(),
|
||||
Delimited(
|
||||
Group(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue