add variant support for menus

This commit is contained in:
jgcodes2020 2024-12-14 14:00:09 -05:00
parent f894301571
commit a75adc7d1b
4 changed files with 39 additions and 13 deletions

View file

@ -19,7 +19,7 @@
import typing as T
from blueprintcompiler.language.values import StringValue
from blueprintcompiler.language.values import StringValue, VariantValue
from .common import *
from .contexts import ValueTypeCtx
@ -98,8 +98,12 @@ class MenuAttribute(AstNode):
return self.tokens["name"]
@property
def value(self) -> StringValue:
return self.children[StringValue][0]
def value(self) -> StringValue | VariantValue:
if len(self.children[StringValue]) > 0:
return self.children[StringValue][0]
elif len(self.children[VariantValue]) > 0:
return self.children[VariantValue][0]
raise CompilerBugError()
@property
def document_symbol(self) -> DocumentSymbol:
@ -133,7 +137,7 @@ menu_attribute = Group(
[
UseIdent("name"),
":",
Err(StringValue, "Expected string or translated string"),
Err(AnyOf(StringValue, VariantValue), "Expected string or translated string"),
Match(";").expected(),
],
)