mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
preliminary variant syntax
This commit is contained in:
parent
778a979714
commit
f894301571
4 changed files with 58 additions and 3 deletions
|
@ -371,6 +371,42 @@ class IdentLiteral(AstNode):
|
|||
else:
|
||||
return None
|
||||
|
||||
class VariantValue(AstNode):
|
||||
grammar = [
|
||||
"variant",
|
||||
"<",
|
||||
UseQuoted("type"),
|
||||
">",
|
||||
"(",
|
||||
UseQuoted("value"),
|
||||
")"
|
||||
]
|
||||
|
||||
@property
|
||||
def var_type(self) -> str:
|
||||
return self.tokens["type"]
|
||||
|
||||
@property
|
||||
def var_value(self) -> str:
|
||||
return self.tokens["value"]
|
||||
|
||||
@validate()
|
||||
def validate_for_type(self) -> None:
|
||||
expected_type = self.context[ValueTypeCtx].value_type
|
||||
if (
|
||||
isinstance(expected_type, gir.IntType)
|
||||
or isinstance(expected_type, gir.UIntType)
|
||||
or isinstance(expected_type, gir.FloatType)
|
||||
or isinstance(expected_type, gir.FloatType)
|
||||
):
|
||||
raise CompileError(f"Cannot convert variant to number")
|
||||
elif isinstance(expected_type, gir.StringType):
|
||||
raise CompileError("Cannot convert variant to string")
|
||||
if isinstance(expected_type, gir.Boxed) and expected_type.full_name == "GLib.Variant":
|
||||
pass
|
||||
else:
|
||||
raise CompileError(f"Cannot convert variant into {expected_type.full_name}")
|
||||
pass
|
||||
|
||||
class Literal(AstNode):
|
||||
grammar = AnyOf(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue