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
|
@ -27,19 +27,9 @@ from ..parser_utils import *
|
|||
from ..xml_emitter import XmlEmitter
|
||||
|
||||
|
||||
class Widgets(AstNode):
|
||||
@validate("widgets")
|
||||
def container_is_size_group(self):
|
||||
self.validate_parent_type("Gtk", "SizeGroup", "size group properties")
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.start_tag("widgets")
|
||||
for child in self.children:
|
||||
child.emit_xml(xml)
|
||||
xml.end_tag()
|
||||
|
||||
|
||||
class Widget(AstNode):
|
||||
grammar = UseIdent("name")
|
||||
|
||||
@validate("name")
|
||||
def obj_widget(self):
|
||||
object = self.root.objects_by_id.get(self.tokens["name"])
|
||||
|
@ -58,21 +48,23 @@ class Widget(AstNode):
|
|||
xml.put_self_closing("widget", name=self.tokens["name"])
|
||||
|
||||
|
||||
widgets = Group(
|
||||
Widgets,
|
||||
[
|
||||
class Widgets(AstNode):
|
||||
grammar = [
|
||||
Keyword("widgets"),
|
||||
"[",
|
||||
Delimited(
|
||||
Group(
|
||||
Widget,
|
||||
UseIdent("name"),
|
||||
),
|
||||
",",
|
||||
),
|
||||
Delimited(Widget, ","),
|
||||
"]",
|
||||
]
|
||||
)
|
||||
|
||||
@validate("widgets")
|
||||
def container_is_size_group(self):
|
||||
self.validate_parent_type("Gtk", "SizeGroup", "size group properties")
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.start_tag("widgets")
|
||||
for child in self.children:
|
||||
child.emit_xml(xml)
|
||||
xml.end_tag()
|
||||
|
||||
|
||||
@completer(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue