mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-05 16:09:07 -04:00
Merge branch 'variant-literal' into 'main'
Draft: Syntax for variants See merge request jwestman/blueprint-compiler!224
This commit is contained in:
commit
6f87c07320
8 changed files with 337 additions and 14 deletions
|
@ -1,5 +1,7 @@
|
|||
import typing as T
|
||||
|
||||
from blueprintcompiler.language.values import VariantValue
|
||||
|
||||
from ...language import *
|
||||
from .. import OutputFormat
|
||||
from .xml_emitter import XmlEmitter
|
||||
|
@ -83,13 +85,23 @@ class XmlOutput(OutputFormat):
|
|||
if isinstance(child, Menu):
|
||||
self._emit_menu(child, xml)
|
||||
elif isinstance(child, MenuAttribute):
|
||||
xml.start_tag(
|
||||
"attribute",
|
||||
name=child.name,
|
||||
**self._translated_string_attrs(child.value.child),
|
||||
)
|
||||
xml.put_text(child.value.string)
|
||||
xml.end_tag()
|
||||
if isinstance(child.value, StringValue):
|
||||
xml.start_tag(
|
||||
"attribute",
|
||||
name=child.name,
|
||||
**self._translated_string_attrs(child.value.child),
|
||||
)
|
||||
xml.put_text(child.value.string)
|
||||
xml.end_tag()
|
||||
elif isinstance(child.value, VariantValue):
|
||||
xml.start_tag(
|
||||
"attribute",
|
||||
name=child.name,
|
||||
type=child.value.var_type,
|
||||
)
|
||||
xml.put_text(child.value.var_value)
|
||||
xml.end_tag()
|
||||
|
||||
else:
|
||||
raise CompilerBugError()
|
||||
xml.end_tag()
|
||||
|
@ -148,6 +160,11 @@ class XmlOutput(OutputFormat):
|
|||
self._emit_value(values[-1], xml)
|
||||
xml.end_tag()
|
||||
|
||||
elif isinstance(value, VariantValue):
|
||||
xml.start_tag("property", **props, type=value.var_type)
|
||||
xml.put_text(value.var_value)
|
||||
xml.end_tag()
|
||||
|
||||
else:
|
||||
raise CompilerBugError()
|
||||
|
||||
|
@ -205,6 +222,8 @@ class XmlOutput(OutputFormat):
|
|||
xml.put_text(self._object_id(value, value.ident))
|
||||
elif isinstance(value, TypeLiteral):
|
||||
xml.put_text(value.type_name.glib_type_name)
|
||||
elif isinstance(value, VariantValue):
|
||||
xml.put_text(value.value)
|
||||
else:
|
||||
if isinstance(value.value, float) and value.value == int(value.value):
|
||||
xml.put_text(int(value.value))
|
||||
|
@ -284,6 +303,10 @@ class XmlOutput(OutputFormat):
|
|||
xml.start_tag(tag, **attrs)
|
||||
xml.put_text(value.child.value)
|
||||
xml.end_tag()
|
||||
elif isinstance(value.child, VariantValue):
|
||||
xml.start_tag(tag, **attrs, type=value.child.var_type)
|
||||
xml.put_text(value.child.var_value)
|
||||
xml.end_tag()
|
||||
else:
|
||||
xml.start_tag(tag, **attrs)
|
||||
self._emit_value(value, xml)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue