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

@ -28,19 +28,6 @@ from ..parser_utils import *
from ..xml_emitter import XmlEmitter
class Items(AstNode):
@validate("items")
def container_is_combo_box_text(self):
self.validate_parent_type("Gtk", "ComboBoxText", "combo box items")
def emit_xml(self, xml: XmlEmitter):
xml.start_tag("items")
for child in self.children:
child.emit_xml(xml)
xml.end_tag()
class Item(BaseTypedAttribute):
tag_name = "item"
attr_name = "id"
@ -61,15 +48,25 @@ item = Group(
]
)
items = Group(
Items,
[
class Items(AstNode):
grammar = [
Keyword("items"),
"[",
Delimited(item, ","),
"]",
]
)
@validate("items")
def container_is_combo_box_text(self):
self.validate_parent_type("Gtk", "ComboBoxText", "combo box items")
def emit_xml(self, xml: XmlEmitter):
xml.start_tag("items")
for child in self.children:
child.emit_xml(xml)
xml.end_tag()
@completer(