Change the way values work

Change the parsing for values to make them more reusable, in particular
for when I implement extensions.
This commit is contained in:
James Westman 2023-01-12 13:19:15 -06:00
parent 6938267952
commit 1df46b5a06
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
30 changed files with 707 additions and 291 deletions

View file

@ -21,6 +21,7 @@ from .gobject_object import ObjectContent, validate_parent_type
from .attributes import BaseTypedAttribute
from .values import Value
from .common import *
from .contexts import ValueTypeCtx
def get_property_types(gir):
@ -108,7 +109,7 @@ class A11yProperty(BaseTypedAttribute):
grammar = Statement(
UseIdent("name"),
":",
VALUE_HOOKS.expected("a value"),
Value,
)
@property
@ -129,8 +130,12 @@ class A11yProperty(BaseTypedAttribute):
return self.tokens["name"].replace("_", "-")
@property
def value_type(self) -> GirType:
return get_types(self.root.gir).get(self.tokens["name"])
def value(self) -> Value:
return self.children[0]
@context(ValueTypeCtx)
def value_type(self) -> ValueTypeCtx:
return ValueTypeCtx(get_types(self.root.gir).get(self.tokens["name"]))
@validate("name")
def is_valid_property(self):
@ -161,6 +166,10 @@ class A11y(AstNode):
Until(A11yProperty, "}"),
]
@property
def properties(self) -> T.List[A11yProperty]:
return self.children[A11yProperty]
@validate("accessibility")
def container_is_widget(self):
validate_parent_type(self, "Gtk", "Widget", "accessibility properties")