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

@ -24,6 +24,7 @@ from blueprintcompiler.language.values import Value
from .attributes import BaseAttribute
from .gobject_object import Object, ObjectContent
from .common import *
from .contexts import ValueTypeCtx
class Menu(AstNode):
@ -49,17 +50,23 @@ class Menu(AstNode):
raise CompileError("Menu requires an ID")
class MenuAttribute(BaseAttribute):
class MenuAttribute(AstNode):
tag_name = "attribute"
@property
def value_type(self):
return None
def name(self) -> str:
return self.tokens["name"]
@property
def value(self) -> Value:
return self.children[Value][0]
@context(ValueTypeCtx)
def value_type(self) -> ValueTypeCtx:
return ValueTypeCtx(
None, binding_error=CompileError("Bindings are not permitted in menus")
)
menu_contents = Sequence()
@ -78,7 +85,7 @@ menu_attribute = Group(
[
UseIdent("name"),
":",
VALUE_HOOKS.expected("a value"),
Err(Value, "Expected a value"),
Match(";").expected(),
],
)
@ -102,7 +109,7 @@ menu_item_shorthand = Group(
"(",
Group(
MenuAttribute,
[UseLiteral("name", "label"), VALUE_HOOKS],
[UseLiteral("name", "label"), Value],
),
Optional(
[
@ -111,14 +118,14 @@ menu_item_shorthand = Group(
[
Group(
MenuAttribute,
[UseLiteral("name", "action"), VALUE_HOOKS],
[UseLiteral("name", "action"), Value],
),
Optional(
[
",",
Group(
MenuAttribute,
[UseLiteral("name", "icon"), VALUE_HOOKS],
[UseLiteral("name", "icon"), Value],
),
]
),