Fix menus

- Menus require an ID
- The top level menu block can't have attributes
This commit is contained in:
James Westman 2022-12-19 14:36:32 -06:00
parent 8a1dba662a
commit 51d8969ced
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
9 changed files with 43 additions and 13 deletions

View file

@ -39,6 +39,11 @@ class Menu(AstNode):
def tag(self) -> str:
return self.tokens["tag"]
@validate("menu")
def has_id(self):
if self.tokens["tag"] == "menu" and self.tokens["id"] is None:
raise CompileError("Menu requires an ID")
class MenuAttribute(BaseAttribute):
tag_name = "attribute"
@ -137,7 +142,27 @@ menu_contents.children = [
menu: Group = Group(
Menu,
["menu", UseLiteral("tag", "menu"), Optional(UseIdent("id")), menu_contents],
[
Keyword("menu"),
UseLiteral("tag", "menu"),
Optional(UseIdent("id")),
[
Match("{"),
Until(
AnyOf(
menu_section,
menu_submenu,
menu_item_shorthand,
menu_item,
Fail(
menu_attribute,
"Attributes are not permitted at the top level of a menu",
),
),
"}",
),
],
],
)
from .ui import UI