xml: Fix flags and enums

GtkBuilder XML uses enum nicknames, full names, or integer values, but
we accept GIR names, so passing those through doesn't work if the name
has an underscore (which traditionally turns into a dash in the
nickname). Avoid the problem by always writing the integer value of the
enum member.
This commit is contained in:
James Westman 2022-12-19 15:07:31 -06:00
parent 51d8969ced
commit 6c67e1fc5a
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
11 changed files with 34 additions and 14 deletions

View file

@ -168,6 +168,20 @@ class NumberValue(Value):
class Flag(AstNode):
grammar = UseIdent("value")
@property
def name(self) -> str:
return self.tokens["value"]
@property
def value(self) -> T.Optional[int]:
type = self.parent.parent.value_type
if not isinstance(type, Enumeration):
return None
elif member := type.members.get(self.tokens["value"]):
return member.value
else:
return None
@docs()
def docs(self):
type = self.parent.parent.value_type