language: Use new extern syntax in signal handlers

This commit is contained in:
James Westman 2022-12-25 16:22:33 -06:00
parent 0b402db4d5
commit 122b049ce9
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
8 changed files with 21 additions and 10 deletions

View file

@ -33,6 +33,7 @@ class Signal(AstNode):
] ]
), ),
"=>", "=>",
Optional(["$", UseLiteral("extern", True)]),
UseIdent("handler").expected("the name of a function to handle the signal"), UseIdent("handler").expected("the name of a function to handle the signal"),
Match("(").expected("argument list"), Match("(").expected("argument list"),
Optional(UseIdent("object")).expected("object identifier"), Optional(UseIdent("object")).expected("object identifier"),
@ -78,6 +79,14 @@ class Signal(AstNode):
def gir_class(self): def gir_class(self):
return self.parent.parent.gir_class 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") @validate("name")
def signal_exists(self): def signal_exists(self):
if self.gir_class is None or isinstance(self.gir_class, UncheckedType): 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 "" object_name = object or ""
name = name.replace("_", "-") name = name.replace("_", "-")
if decompile.truthy(swapped): if decompile.truthy(swapped):
ctx.print(f"{name} => {handler}({object_name}) swapped;") ctx.print(f"{name} => ${handler}({object_name}) swapped;")
else: else:
ctx.print(f"{name} => {handler}({object_name});") ctx.print(f"{name} => ${handler}({object_name});")
return gir return gir

View file

@ -1,5 +1,5 @@
using Gtk 4.0; using Gtk 4.0;
Button { Button {
eaten-by-velociraptors => on_eaten_by_velociraptors(); eaten-by-velociraptors => $on_eaten_by_velociraptors();
} }

View file

@ -1,5 +1,5 @@
using Gtk 4.0; using Gtk 4.0;
Button { Button {
clicked => function(dinosaur); clicked => $function(dinosaur);
} }

View file

@ -1 +1 @@
4,25,8,Could not find object with ID 'dinosaur' 4,26,8,Could not find object with ID 'dinosaur'

View file

@ -2,4 +2,5 @@ using Gtk 4.0;
.MyClass { .MyClass {
prop: typeof(.MyOtherClass); prop: typeof(.MyOtherClass);
clicked => handler();
} }

View file

@ -1,2 +1,3 @@
3,1,8,Use the '$' extern syntax introduced in blueprint 0.8.0 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 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

View file

@ -1,10 +1,10 @@
using Gtk 4.0; using Gtk 4.0;
Entry { Entry {
activate => click(button); activate => $click(button);
} }
Button button { Button button {
clicked => on_button_clicked() swapped; clicked => $on_button_clicked() swapped;
notify::visible => on_button_notify_visible(); notify::visible => $on_button_notify_visible();
} }

View file

@ -2,7 +2,7 @@ using Gtk 4.0;
template TestTemplate : ApplicationWindow { template TestTemplate : ApplicationWindow {
test-property: "Hello, world"; test-property: "Hello, world";
test-signal => on_test_signal(); test-signal => $on_test_signal();
} }
Dialog { Dialog {