diff --git a/blueprintcompiler/language/gobject_signal.py b/blueprintcompiler/language/gobject_signal.py index 11a69e0..74d7472 100644 --- a/blueprintcompiler/language/gobject_signal.py +++ b/blueprintcompiler/language/gobject_signal.py @@ -33,6 +33,7 @@ class Signal(AstNode): ] ), "=>", + Optional(["$", UseLiteral("extern", True)]), UseIdent("handler").expected("the name of a function to handle the signal"), Match("(").expected("argument list"), Optional(UseIdent("object")).expected("object identifier"), @@ -78,6 +79,14 @@ class Signal(AstNode): def gir_class(self): return self.parent.parent.gir_class + @validate("handler") + def old_extern(self): + if not self.tokens["extern"]: + raise UpgradeWarning( + "Use the '$' extern syntax introduced in blueprint 0.8.0", + actions=[CodeAction("Use '$' syntax", "$" + self.tokens["handler"])], + ) + @validate("name") def signal_exists(self): if self.gir_class is None or isinstance(self.gir_class, UncheckedType): @@ -116,7 +125,7 @@ def decompile_signal(ctx, gir, name, handler, swapped="false", object=None): object_name = object or "" name = name.replace("_", "-") if decompile.truthy(swapped): - ctx.print(f"{name} => {handler}({object_name}) swapped;") + ctx.print(f"{name} => ${handler}({object_name}) swapped;") else: - ctx.print(f"{name} => {handler}({object_name});") + ctx.print(f"{name} => ${handler}({object_name});") return gir diff --git a/tests/sample_errors/signal_dne.blp b/tests/sample_errors/signal_dne.blp index 9c5d046..0f90432 100644 --- a/tests/sample_errors/signal_dne.blp +++ b/tests/sample_errors/signal_dne.blp @@ -1,5 +1,5 @@ using Gtk 4.0; Button { - eaten-by-velociraptors => on_eaten_by_velociraptors(); + eaten-by-velociraptors => $on_eaten_by_velociraptors(); } diff --git a/tests/sample_errors/signal_object_dne.blp b/tests/sample_errors/signal_object_dne.blp index 8c9610c..5492117 100644 --- a/tests/sample_errors/signal_object_dne.blp +++ b/tests/sample_errors/signal_object_dne.blp @@ -1,5 +1,5 @@ using Gtk 4.0; Button { - clicked => function(dinosaur); + clicked => $function(dinosaur); } \ No newline at end of file diff --git a/tests/sample_errors/signal_object_dne.err b/tests/sample_errors/signal_object_dne.err index dfffc0f..b76b98a 100644 --- a/tests/sample_errors/signal_object_dne.err +++ b/tests/sample_errors/signal_object_dne.err @@ -1 +1 @@ -4,25,8,Could not find object with ID 'dinosaur' \ No newline at end of file +4,26,8,Could not find object with ID 'dinosaur' \ No newline at end of file diff --git a/tests/sample_errors/warn_old_extern.blp b/tests/sample_errors/warn_old_extern.blp index e50fb0f..c7ad01d 100644 --- a/tests/sample_errors/warn_old_extern.blp +++ b/tests/sample_errors/warn_old_extern.blp @@ -2,4 +2,5 @@ using Gtk 4.0; .MyClass { prop: typeof(.MyOtherClass); + clicked => handler(); } \ No newline at end of file diff --git a/tests/sample_errors/warn_old_extern.err b/tests/sample_errors/warn_old_extern.err index 8209d23..c3b3fe2 100644 --- a/tests/sample_errors/warn_old_extern.err +++ b/tests/sample_errors/warn_old_extern.err @@ -1,2 +1,3 @@ 3,1,8,Use the '$' extern syntax introduced in blueprint 0.8.0 -4,16,13,Use the '$' extern syntax introduced in blueprint 0.8.0 \ No newline at end of file +4,16,13,Use the '$' extern syntax introduced in blueprint 0.8.0 +5,14,7,Use the '$' extern syntax introduced in blueprint 0.8.0 \ No newline at end of file diff --git a/tests/samples/signal.blp b/tests/samples/signal.blp index 1965e74..5f3aa7f 100644 --- a/tests/samples/signal.blp +++ b/tests/samples/signal.blp @@ -1,10 +1,10 @@ using Gtk 4.0; Entry { - activate => click(button); + activate => $click(button); } Button button { - clicked => on_button_clicked() swapped; - notify::visible => on_button_notify_visible(); + clicked => $on_button_clicked() swapped; + notify::visible => $on_button_notify_visible(); } diff --git a/tests/samples/template.blp b/tests/samples/template.blp index 7773e25..a0ed5cc 100644 --- a/tests/samples/template.blp +++ b/tests/samples/template.blp @@ -2,7 +2,7 @@ using Gtk 4.0; template TestTemplate : ApplicationWindow { test-property: "Hello, world"; - test-signal => on_test_signal(); + test-signal => $on_test_signal(); } Dialog {