mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
parser: Simplify parser construction
- Replace several different parse nodes with Match, which matches the exact text of a token but not the token type - Allow arrays to be used in place of Sequence
This commit is contained in:
parent
ad6a2cf538
commit
8d587b62a0
11 changed files with 182 additions and 211 deletions
|
@ -51,94 +51,94 @@ menu_contents = Sequence()
|
|||
|
||||
menu_section = Group(
|
||||
Menu,
|
||||
Sequence(
|
||||
Keyword("section"),
|
||||
[
|
||||
"section",
|
||||
UseLiteral("tag", "section"),
|
||||
Optional(UseIdent("id")),
|
||||
menu_contents
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
menu_submenu = Group(
|
||||
Menu,
|
||||
Sequence(
|
||||
Keyword("submenu"),
|
||||
[
|
||||
"submenu",
|
||||
UseLiteral("tag", "submenu"),
|
||||
Optional(UseIdent("id")),
|
||||
menu_contents
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
menu_attribute = Group(
|
||||
MenuAttribute,
|
||||
Sequence(
|
||||
[
|
||||
UseIdent("name"),
|
||||
Op(":"),
|
||||
":",
|
||||
value.expected("a value"),
|
||||
StmtEnd().expected("`;`"),
|
||||
)
|
||||
Match(";").expected(),
|
||||
]
|
||||
)
|
||||
|
||||
menu_item = Group(
|
||||
Menu,
|
||||
Sequence(
|
||||
Keyword("item"),
|
||||
[
|
||||
"item",
|
||||
UseLiteral("tag", "item"),
|
||||
Optional(UseIdent("id")),
|
||||
OpenBlock().expected("`{`"),
|
||||
Until(menu_attribute, CloseBlock()),
|
||||
)
|
||||
Match("{").expected(),
|
||||
Until(menu_attribute, "}"),
|
||||
]
|
||||
)
|
||||
|
||||
menu_item_shorthand = Group(
|
||||
Menu,
|
||||
Sequence(
|
||||
Keyword("item"),
|
||||
[
|
||||
"item",
|
||||
UseLiteral("tag", "item"),
|
||||
OpenParen(),
|
||||
"(",
|
||||
Group(
|
||||
MenuAttribute,
|
||||
Sequence(UseLiteral("name", "label"), value),
|
||||
[UseLiteral("name", "label"), value],
|
||||
),
|
||||
Optional(Sequence(
|
||||
Comma(),
|
||||
Optional(Sequence(
|
||||
Optional([
|
||||
",",
|
||||
Optional([
|
||||
Group(
|
||||
MenuAttribute,
|
||||
Sequence(UseLiteral("name", "action"), value),
|
||||
[UseLiteral("name", "action"), value],
|
||||
),
|
||||
Optional(Sequence(
|
||||
Comma(),
|
||||
Optional([
|
||||
",",
|
||||
Group(
|
||||
MenuAttribute,
|
||||
Sequence(UseLiteral("name", "icon"), value),
|
||||
[UseLiteral("name", "icon"), value],
|
||||
),
|
||||
))
|
||||
))
|
||||
)),
|
||||
CloseParen().expected("')'"),
|
||||
)
|
||||
])
|
||||
])
|
||||
]),
|
||||
Match(")").expected(),
|
||||
]
|
||||
)
|
||||
|
||||
menu_contents.children = [
|
||||
OpenBlock(),
|
||||
Match("{"),
|
||||
Until(AnyOf(
|
||||
menu_section,
|
||||
menu_submenu,
|
||||
menu_item_shorthand,
|
||||
menu_item,
|
||||
menu_attribute,
|
||||
), CloseBlock()),
|
||||
), "}"),
|
||||
]
|
||||
|
||||
menu = Group(
|
||||
Menu,
|
||||
Sequence(
|
||||
Keyword("menu"),
|
||||
[
|
||||
"menu",
|
||||
UseLiteral("tag", "menu"),
|
||||
Optional(UseIdent("id")),
|
||||
menu_contents
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue