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
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue