mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Accept string literals for parseable types
GtkBuilder knows some class-specific parsing methods, so we can use string literals for these types and pass them straight to the XML.
This commit is contained in:
parent
3804d91118
commit
2130c78da9
4 changed files with 29 additions and 4 deletions
|
@ -376,7 +376,7 @@ class LiteralValue(Value):
|
||||||
try:
|
try:
|
||||||
int(self.tokens["value"])
|
int(self.tokens["value"])
|
||||||
except:
|
except:
|
||||||
raise CompileError(f"Cannot convert {self.tokens['value']} to integer")
|
raise CompileError(f"Cannot convert {self.group.tokens['value']} to integer")
|
||||||
|
|
||||||
elif isinstance(type, gir.UIntType):
|
elif isinstance(type, gir.UIntType):
|
||||||
try:
|
try:
|
||||||
|
@ -384,19 +384,31 @@ class LiteralValue(Value):
|
||||||
if int(self.tokens["value"]) < 0:
|
if int(self.tokens["value"]) < 0:
|
||||||
raise Exception()
|
raise Exception()
|
||||||
except:
|
except:
|
||||||
raise CompileError(f"Cannot convert {self.tokens['value']} to unsigned integer")
|
raise CompileError(f"Cannot convert {self.group.tokens['value']} to unsigned integer")
|
||||||
|
|
||||||
elif isinstance(type, gir.FloatType):
|
elif isinstance(type, gir.FloatType):
|
||||||
try:
|
try:
|
||||||
float(self.tokens["value"])
|
float(self.tokens["value"])
|
||||||
except:
|
except:
|
||||||
raise CompileError(f"Cannot convert {self.tokens['value']} to float")
|
raise CompileError(f"Cannot convert {self.group.tokens['value']} to float")
|
||||||
|
|
||||||
elif isinstance(type, gir.StringType):
|
elif isinstance(type, gir.StringType):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
elif isinstance(type, gir.Class) or isinstance(type, gir.Interface):
|
||||||
|
parseable_types = [
|
||||||
|
"Gdk.Paintable",
|
||||||
|
"Gdk.Texture",
|
||||||
|
"Gdk.Pixbuf",
|
||||||
|
"GLib.File",
|
||||||
|
"Gtk.ShortcutTrigger",
|
||||||
|
"Gtk.ShortcutAction",
|
||||||
|
]
|
||||||
|
if type.full_name not in parseable_types:
|
||||||
|
raise CompileError(f"Cannot convert {self.group.tokens['value']} to {type.full_name}")
|
||||||
|
|
||||||
elif type is not None:
|
elif type is not None:
|
||||||
raise CompileError(f"Cannot convert {self.tokens['value']} to {type.full_name}")
|
raise CompileError(f"Cannot convert {self.group.tokens['value']} to {type.full_name}")
|
||||||
|
|
||||||
|
|
||||||
class Flag(AstNode):
|
class Flag(AstNode):
|
||||||
|
|
5
tests/samples/parseable.blp
Normal file
5
tests/samples/parseable.blp
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
using Gtk 4.0;
|
||||||
|
|
||||||
|
Gtk.Shortcut {
|
||||||
|
trigger: "Escape";
|
||||||
|
}
|
7
tests/samples/parseable.ui
Normal file
7
tests/samples/parseable.ui
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk" version="4.0"/>
|
||||||
|
<object class="GtkShortcut">
|
||||||
|
<property name="trigger">Escape</property>
|
||||||
|
</object>
|
||||||
|
</interface>
|
|
@ -104,6 +104,7 @@ class TestSamples(unittest.TestCase):
|
||||||
self.assert_sample("layout")
|
self.assert_sample("layout")
|
||||||
self.assert_sample("menu")
|
self.assert_sample("menu")
|
||||||
self.assert_sample("object_prop")
|
self.assert_sample("object_prop")
|
||||||
|
self.assert_sample("parseable")
|
||||||
self.assert_sample("property")
|
self.assert_sample("property")
|
||||||
self.assert_sample("signal")
|
self.assert_sample("signal")
|
||||||
self.assert_sample("size_group")
|
self.assert_sample("size_group")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue