Allow for multiple a11y properties

This commit is contained in:
Julian Schmidhuber 2024-08-13 10:25:16 +02:00
parent b308adc3af
commit 3dfce3bbe0
10 changed files with 103 additions and 7 deletions

View file

@ -17,6 +17,8 @@
#
# SPDX-License-Identifier: LGPL-3.0-or-later
import typing as T
from ..decompiler import escape_quote
from .attributes import BaseAttribute
from .common import *
@ -97,6 +99,16 @@ def get_types(gir):
}
allow_duplicates = [
"controls",
"described-by",
"details",
"flow-to",
"labelled-by",
"owns",
]
def _get_docs(gir, name):
name = name.replace("-", "_")
if gir_type := (
@ -111,7 +123,7 @@ class A11yProperty(BaseAttribute):
grammar = Statement(
UseIdent("name"),
":",
Value,
AnyOf(Value, ["[", UseLiteral("list_form", True), Delimited(Value, ","), "]"]),
)
@property
@ -132,8 +144,8 @@ class A11yProperty(BaseAttribute):
return self.tokens["name"].replace("_", "-")
@property
def value(self) -> Value:
return self.children[0]
def values(self) -> T.List[Value]:
return list(self.children)
@context(ValueTypeCtx)
def value_type(self) -> ValueTypeCtx:
@ -146,7 +158,7 @@ class A11yProperty(BaseAttribute):
SymbolKind.Field,
self.range,
self.group.tokens["name"].range,
self.value.range.text,
", ".join(v.range.text for v in self.values),
)
@validate("name")
@ -165,6 +177,20 @@ class A11yProperty(BaseAttribute):
check=lambda child: child.tokens["name"] == self.tokens["name"],
)
@validate("name")
def list_only_allowed_for_subset(self):
if self.tokens["list_form"] and self.tokens["name"] not in allow_duplicates:
raise CompileError(
f"'{self.tokens['name']}' does not allow a list of values",
)
@validate("name")
def list_non_empty(self):
if len(self.values) == 0:
raise CompileError(
f"'{self.tokens['name']}' may not be empty",
)
@docs("name")
def prop_docs(self):
if self.tokens["name"] in get_types(self.root.gir):

View file

@ -292,8 +292,11 @@ class XmlOutput(OutputFormat):
def _emit_extensions(self, extension, xml: XmlEmitter):
if isinstance(extension, ExtAccessibility):
xml.start_tag("accessibility")
for prop in extension.properties:
self._emit_attribute(prop.tag_name, "name", prop.name, prop.value, xml)
for property in extension.properties:
for val in property.values:
self._emit_attribute(
property.tag_name, "name", property.name, val, xml
)
xml.end_tag()
elif isinstance(extension, AdwBreakpointCondition):