mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
parser: Shorter code for groups
Add a "grammar" property on AstNode types so they can be used in grammar expressions as groups
This commit is contained in:
parent
8d587b62a0
commit
76f7befd68
10 changed files with 119 additions and 159 deletions
|
@ -29,24 +29,6 @@ from .extensions import OBJECT_HOOKS, OBJECT_CONTENT_HOOKS
|
|||
def parse(tokens) -> T.Tuple[ast.UI, T.Optional[MultipleErrors]]:
|
||||
""" Parses a list of tokens into an abstract syntax tree. """
|
||||
|
||||
gtk_directive = Group(
|
||||
ast.GtkDirective,
|
||||
Statement(
|
||||
Match("using").err("File must start with a \"using Gtk\" directive (e.g. `using Gtk 4.0;`)"),
|
||||
Match("Gtk").err("File must start with a \"using Gtk\" directive (e.g. `using Gtk 4.0;`)"),
|
||||
UseNumberText("version").expected("a version number for GTK"),
|
||||
)
|
||||
)
|
||||
|
||||
import_statement = Group(
|
||||
ast.Import,
|
||||
Statement(
|
||||
"using",
|
||||
UseIdent("namespace").expected("a GIR namespace"),
|
||||
UseNumberText("version").expected("a version number"),
|
||||
)
|
||||
)
|
||||
|
||||
object = Group(
|
||||
ast.Object,
|
||||
None
|
||||
|
@ -152,8 +134,8 @@ def parse(tokens) -> T.Tuple[ast.UI, T.Optional[MultipleErrors]]:
|
|||
ui = Group(
|
||||
ast.UI,
|
||||
[
|
||||
gtk_directive,
|
||||
ZeroOrMore(import_statement),
|
||||
ast.GtkDirective,
|
||||
ZeroOrMore(ast.Import),
|
||||
Until(AnyOf(
|
||||
*OBJECT_HOOKS,
|
||||
template,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue