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:
James Westman 2022-01-17 00:04:26 -06:00
parent 8d587b62a0
commit 76f7befd68
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
10 changed files with 119 additions and 159 deletions

View file

@ -27,19 +27,6 @@ from ..parser_utils import *
from ..xml_emitter import XmlEmitter
class Layout(AstNode):
@validate("layout")
def container_is_widget(self):
self.validate_parent_type("Gtk", "Widget", "layout properties")
def emit_xml(self, xml: XmlEmitter):
xml.start_tag("layout")
for child in self.children:
child.emit_xml(xml)
xml.end_tag()
class LayoutProperty(BaseAttribute):
tag_name = "property"
@ -58,14 +45,24 @@ layout_prop = Group(
)
)
layout = Group(
Layout,
Sequence(
class Layout(AstNode):
grammar = Sequence(
Keyword("layout"),
"{",
Until(layout_prop, "}"),
)
)
@validate("layout")
def container_is_widget(self):
self.validate_parent_type("Gtk", "Widget", "layout properties")
def emit_xml(self, xml: XmlEmitter):
xml.start_tag("layout")
for child in self.children:
child.emit_xml(xml)
xml.end_tag()
@completer(