diff --git a/gtkblueprinttool/ast.py b/gtkblueprinttool/ast.py index 9b755bc..6525a54 100644 --- a/gtkblueprinttool/ast.py +++ b/gtkblueprinttool/ast.py @@ -376,7 +376,7 @@ class LiteralValue(Value): try: int(self.tokens["value"]) 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): try: @@ -384,19 +384,31 @@ class LiteralValue(Value): if int(self.tokens["value"]) < 0: raise Exception() 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): try: float(self.tokens["value"]) 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): 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: - 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): diff --git a/tests/samples/parseable.blp b/tests/samples/parseable.blp new file mode 100644 index 0000000..3bc3584 --- /dev/null +++ b/tests/samples/parseable.blp @@ -0,0 +1,5 @@ +using Gtk 4.0; + +Gtk.Shortcut { + trigger: "Escape"; +} diff --git a/tests/samples/parseable.ui b/tests/samples/parseable.ui new file mode 100644 index 0000000..78ceacb --- /dev/null +++ b/tests/samples/parseable.ui @@ -0,0 +1,7 @@ + + + + + Escape + + diff --git a/tests/test_samples.py b/tests/test_samples.py index b8b6110..0bb20e6 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -104,6 +104,7 @@ class TestSamples(unittest.TestCase): self.assert_sample("layout") self.assert_sample("menu") self.assert_sample("object_prop") + self.assert_sample("parseable") self.assert_sample("property") self.assert_sample("signal") self.assert_sample("size_group")