Merge branch blueprint-compiler:main into main

This commit is contained in:
kotontrion 2025-03-02 15:26:42 +00:00
commit c1fbcef6d0
94 changed files with 850 additions and 232 deletions

View file

@ -0,0 +1,4 @@
using Gtk 4.0;
//comment
// Trailing whitespace:
//

View file

@ -0,0 +1,4 @@
using Gtk 4.0;
// comment
// Trailing whitespace:
//

View file

@ -0,0 +1,21 @@
using Gtk 4.0;
Box {
styles []
}
Box {
styles ["a"]
}
Box {
styles ["a",]
}
Box {
styles ["a", "b"]
}
Box {
styles ["a", "b",]
}

View file

@ -0,0 +1,31 @@
using Gtk 4.0;
Box {
styles []
}
Box {
styles [
"a",
]
}
Box {
styles [
"a",
]
}
Box {
styles [
"a",
"b",
]
}
Box {
styles [
"a",
"b",
]
}

View file

@ -11,7 +11,7 @@ Overlay {
notify::icon-name => $on_icon_name_changed(label) swapped;
styles [
"destructive"
"destructive",
]
}

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
BoolFilter {
expression: expr item.visible;
}

View file

@ -0,0 +1 @@
4,20,4,"item" must be cast to its object type

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
Label {
label: expr 1;
}

View file

@ -0,0 +1 @@
4,10,4,Cannot convert Gtk.Expression to string

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
BoolFilter {
expression: expr $closure(item as <Entry>) as <bool>;
}

View file

@ -0,0 +1 @@
4,29,4,"item" can only be used for looking up properties

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
BoolFilter {
expression: expr item as <Label>;
}

View file

@ -0,0 +1 @@
4,20,4,"item" can only be used for looking up properties

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
Entry {
margin-bottom: 10.5;
}

View file

@ -0,0 +1 @@
4,18,4,Cannot convert 10.5 to integer

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
Label {
notify::
}

View file

@ -0,0 +1,2 @@
5,1,0,Expected a signal detail name
4,9,3,Unexpected tokens

View file

@ -0,0 +1,3 @@
using Gtk 4.0;
int {}

View file

@ -0,0 +1 @@
3,1,3,int is not a class

View file

@ -0,0 +1,7 @@
using Gtk 4.0;
Overlay {
child: my_menu;
}
menu my_menu {}

View file

@ -0,0 +1 @@
4,10,7,Cannot assign Gio.Menu to Gtk.Widget

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
$MyObject obj {
signal1 => $handler() swapped not-swapped;
}

View file

@ -0,0 +1 @@
4,33,11,'swapped' and 'not-swapped' flags cannot be used together

View file

@ -0,0 +1,6 @@
using Gtk 4.0;
$MyObject obj {
signal1 => $handler() not-swapped;
signal2 => $handler(obj) swapped;
}

View file

@ -0,0 +1,2 @@
4,25,11,'not-swapped' is the default for handlers that do not specify an object
5,28,7,'swapped' is the default for handlers that specify an object

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
Label {
label: _('Hello, World!');
}

View file

@ -0,0 +1 @@
4,12,15,gettext may not recognize single-quoted strings

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
Entry {
margin-bottom: "10";
}

View file

@ -0,0 +1 @@
4,18,4,Cannot convert string to number

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
Button {
child: "Click me";
}

View file

@ -0,0 +1 @@
4,10,10,Cannot convert string to Gtk.Widget

View file

@ -0,0 +1,6 @@
using Gtk 4.0;
using Gio 2.0;
Gio.ListStore {
item-type: "Button";
}

View file

@ -0,0 +1 @@
5,14,8,Cannot convert string to GType

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
Button {
child: _("Click me");
}

View file

@ -0,0 +1 @@
4,10,13,Cannot convert translated string to Gtk.Widget

View file

@ -0,0 +1,7 @@
using Gtk 4.0;
StringList {
strings: [
_("Test")
];
}

View file

@ -0,0 +1 @@
5,5,9,Arrays can't contain translated strings

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
Button {
label: typeof<Button>;
}

View file

@ -0,0 +1 @@
4,10,14,Cannot convert GType to string

View file

@ -0,0 +1 @@
~

View file

@ -0,0 +1 @@
1,1,0,Could not determine what kind of syntax is meant here

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
Button btn {
label: bind btn.label sync-create;
}

View file

@ -0,0 +1 @@
4,25,11,'sync-create' is now the default. Use 'no-sync-create' if this is not wanted.

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
BuilderListItemFactory {
template {}
}

View file

@ -0,0 +1 @@
4,3,8,Expected type name after 'template' keyword

View file

@ -0,0 +1,9 @@
using Gtk 4.0;
BoolFilter filter1 {
expression: expr true;
}
BoolFilter filter2 {
expression: bind filter1.expression;
}

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkBoolFilter" id="filter1">
<property name="expression">
<constant type="gboolean">true</constant>
</property>
</object>
<object class="GtkBoolFilter" id="filter2">
<property name="expression" bind-source="filter1" bind-property="expression" bind-flags="sync-create"/>
</object>
</interface>

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
Label {
label: bind "Hello, world!";
}

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkLabel">
<binding name="label">
<constant type="gchararray">Hello, world!</constant>
</binding>
</object>
</interface>

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
BoolFilter {
expression: expr item as <Entry>.visible;
}

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkBoolFilter">
<property name="expression">
<lookup name="visible" type="GtkEntry"></lookup>
</property>
</object>
</interface>

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
BoolFilter {
expression: expr $closure(item as <Entry>.visible) as <bool>;
}

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkBoolFilter">
<property name="expression">
<closure function="closure" type="gboolean">
<lookup name="visible" type="GtkEntry"></lookup>
</closure>
</property>
</object>
</interface>

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
BoolFilter {
expression: expr true;
}

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkBoolFilter">
<property name="expression">
<constant type="gboolean">true</constant>
</property>
</object>
</interface>

View file

@ -4,6 +4,7 @@ Box {
visible: bind box2.visible inverted;
orientation: bind box2.orientation;
spacing: bind box2.spacing no-sync-create;
tooltip-text: bind box2.tooltip-text bidirectional;
}
Box box2 {

View file

@ -10,6 +10,7 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<property name="visible" bind-source="box2" bind-property="visible" bind-flags="sync-create|invert-boolean"/>
<property name="orientation" bind-source="box2" bind-property="orientation" bind-flags="sync-create"/>
<property name="spacing" bind-source="box2" bind-property="spacing"/>
<property name="tooltip-text" bind-source="box2" bind-property="tooltip-text" bind-flags="sync-create|bidirectional"/>
</object>
<object class="GtkBox" id="box2">
<property name="spacing">6</property>

View file

@ -1,11 +0,0 @@
using Gtk 4.0;
Box {
visible: bind box2.visible inverted;
orientation: bind box2.orientation;
spacing: bind box2.spacing no-sync-create;
}
Box box2 {
spacing: 6;
}

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
Button obj {
clicked => $handler(obj) not-swapped;
}

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkButton" id="obj">
<signal name="clicked" handler="handler" swapped="False" object="obj"/>
</object>
</interface>

View file

@ -5,6 +5,6 @@ AboutDialog about {
authors: [
"Jane doe <jane-doe@email.com>",
"Jhonny D <jd@email.com>"
"Jhonny D <jd@email.com>",
];
}

View file

@ -3,6 +3,6 @@ using Gtk 4.0;
Label {
styles [
"class-1",
"class-2"
"class-2",
]
}

View file

@ -46,3 +46,5 @@ class TestFormatter(unittest.TestCase):
self.assert_format_test("in2.blp", "out.blp")
self.assert_format_test("correct1.blp", "correct1.blp")
self.assert_format_test("string_in.blp", "string_out.blp")
self.assert_format_test("comment_in.blp", "comment_out.blp")
self.assert_format_test("lists_in.blp", "lists_out.blp")

View file

@ -28,6 +28,7 @@ gi.require_version("Gtk", "4.0")
from gi.repository import Gtk
from blueprintcompiler import decompiler, parser, tokenizer, utils
from blueprintcompiler.ast_utils import AstNode
from blueprintcompiler.completions import complete
from blueprintcompiler.errors import (
CompileError,
@ -61,11 +62,14 @@ class TestSamples(unittest.TestCase):
except:
pass
def assert_ast_doesnt_crash(self, text, tokens, ast):
def assert_ast_doesnt_crash(self, text, tokens, ast: AstNode):
lsp = LanguageServer()
for i in range(len(text)):
ast.get_docs(i)
for i in range(len(text)):
list(complete(LanguageServer(), ast, tokens, i))
list(complete(lsp, ast, tokens, i))
for i in range(len(text)):
ast.get_reference(i)
ast.get_document_symbols()
def assert_sample(self, name, skip_run=False):
@ -194,8 +198,10 @@ class TestSamples(unittest.TestCase):
"adw_breakpoint_template",
"expr_closure",
"expr_closure_args",
"expr_value_closure",
"parseable",
"signal",
"signal_not_swapped",
"template",
"template_binding",
"template_binding_extern",