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,7 +27,21 @@ from ..parser_utils import *
|
|||
from ..xml_emitter import XmlEmitter
|
||||
|
||||
|
||||
class StyleClass(AstNode):
|
||||
grammar = UseQuoted("name")
|
||||
|
||||
def emit_xml(self, xml):
|
||||
xml.put_self_closing("class", name=self.tokens["name"])
|
||||
|
||||
|
||||
class Styles(AstNode):
|
||||
grammar = [
|
||||
Keyword("styles"),
|
||||
"[",
|
||||
Delimited(StyleClass, ","),
|
||||
"]",
|
||||
]
|
||||
|
||||
@validate("styles")
|
||||
def container_is_widget(self):
|
||||
self.validate_parent_type("Gtk", "Widget", "style classes")
|
||||
|
@ -39,28 +53,6 @@ class Styles(AstNode):
|
|||
xml.end_tag()
|
||||
|
||||
|
||||
class StyleClass(AstNode):
|
||||
def emit_xml(self, xml):
|
||||
xml.put_self_closing("class", name=self.tokens["name"])
|
||||
|
||||
|
||||
styles = Group(
|
||||
Styles,
|
||||
[
|
||||
Keyword("styles"),
|
||||
"[",
|
||||
Delimited(
|
||||
Group(
|
||||
StyleClass,
|
||||
UseQuoted("name")
|
||||
),
|
||||
",",
|
||||
),
|
||||
"]",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@completer(
|
||||
applies_in=[ast.ObjectContent],
|
||||
applies_in_subclass=("Gtk", "Widget"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue