mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Compare commits
16 commits
Author | SHA1 | Date | |
---|---|---|---|
|
2e42dc6848 | ||
|
a12d3f5c81 | ||
|
a83c7e936d | ||
|
3816f4fe8d | ||
|
e9d61cb6f9 | ||
|
6a77bfee0a | ||
|
f50b898e4c | ||
|
cc09f3d3bb | ||
|
f93d5d2acd | ||
|
394014429e | ||
|
a4e0c3701b | ||
|
c1fbcef6d0 | ||
|
404ae76787 | ||
|
e07da3c339 | ||
|
2ae41020ab | ||
|
f48b840cfa |
28 changed files with 209 additions and 37 deletions
|
@ -3,7 +3,7 @@ stages:
|
|||
- pages
|
||||
|
||||
build:
|
||||
image: registry.gitlab.gnome.org/jwestman/blueprint-compiler
|
||||
image: registry.gitlab.gnome.org/gnome/blueprint-compiler
|
||||
stage: build
|
||||
script:
|
||||
- black --check --diff ./ tests
|
||||
|
@ -33,7 +33,7 @@ build:
|
|||
path: coverage.xml
|
||||
|
||||
fuzz:
|
||||
image: registry.gitlab.gnome.org/jwestman/blueprint-compiler
|
||||
image: registry.gitlab.gnome.org/gnome/blueprint-compiler
|
||||
stage: build
|
||||
script:
|
||||
- meson _build
|
||||
|
|
|
@ -8,7 +8,7 @@ in the NEWS file.
|
|||
3. Make a new commit with just these two changes. Use `Release v{version}` as the commit message. Tag the commit as `v{version}` and push the tag.
|
||||
4. Create a "Post-release version bump" commit.
|
||||
5. Go to the Releases page in GitLab and create a new release from the tag.
|
||||
6. Announce the release through relevant channels (Twitter, TWIG, etc.)
|
||||
6. Announce the release through relevant channels (Mastodon, TWIG, etc.)
|
||||
|
||||
## Related projects
|
||||
|
||||
|
|
27
blueprint-compiler.doap
Normal file
27
blueprint-compiler.doap
Normal file
|
@ -0,0 +1,27 @@
|
|||
<Project xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
|
||||
xmlns:foaf="http://xmlns.com/foaf/0.1/"
|
||||
xmlns:gnome="http://api.gnome.org/doap-extensions#"
|
||||
xmlns="http://usefulinc.com/ns/doap#">
|
||||
|
||||
<name xml:lang="en">Blueprint</name>
|
||||
<shortdesc xml:lang="en">A modern language for creating GTK interfaces</shortdesc>
|
||||
<description xml:lang="en">Blueprint is a language and associated tooling for building user interfaces for GTK.</description>
|
||||
<category rdf:resource="http://api.gnome.org/doap-extensions#apps" />
|
||||
<programming-language>Python</programming-language>
|
||||
|
||||
<homepage
|
||||
rdf:resource="https://gnome.gitlab.gnome.org/blueprint-compiler/" />
|
||||
<download-page
|
||||
rdf:resource="https://gitlab.gnome.org/GNOME/blueprint-compiler/-/releases" />
|
||||
<bug-database
|
||||
rdf:resource="https://gitlab.gnome.org/GNOME/blueprint-compiler/issues" />
|
||||
|
||||
<maintainer>
|
||||
<foaf:Person>
|
||||
<foaf:name>James Westman</foaf:name>
|
||||
<foaf:mbox rdf:resource="mailto:james@jwestman.net" />
|
||||
<gnome:userid>jwestman</gnome:userid>
|
||||
</foaf:Person>
|
||||
</maintainer>
|
||||
</Project>
|
|
@ -255,7 +255,11 @@ def decompile_element(
|
|||
|
||||
ctx._node_stack.append(xml)
|
||||
ctx.start_block()
|
||||
gir = decompiler(*args, **kwargs)
|
||||
|
||||
try:
|
||||
gir = decompiler(*args, **kwargs)
|
||||
except TypeError as e:
|
||||
raise UnsupportedError(tag=xml.tag)
|
||||
|
||||
if not decompiler._skip_children:
|
||||
for child in xml.children:
|
||||
|
@ -266,8 +270,6 @@ def decompile_element(
|
|||
|
||||
except UnsupportedError as e:
|
||||
raise e
|
||||
except TypeError as e:
|
||||
raise UnsupportedError(tag=xml.tag)
|
||||
|
||||
|
||||
def decompile(data: str) -> str:
|
||||
|
|
|
@ -219,7 +219,7 @@ def report_bug(): # pragma: no cover
|
|||
f"""{Colors.BOLD}{Colors.RED}***** COMPILER BUG *****
|
||||
The blueprint-compiler program has crashed. Please report the above stacktrace,
|
||||
along with the input file(s) if possible, on GitLab:
|
||||
{Colors.BOLD}{Colors.BLUE}{Colors.UNDERLINE}https://gitlab.gnome.org/jwestman/blueprint-compiler/-/issues/new?issue
|
||||
{Colors.BOLD}{Colors.BLUE}{Colors.UNDERLINE}https://gitlab.gnome.org/GNOME/blueprint-compiler/-/issues/new?issue
|
||||
{Colors.CLEAR}"""
|
||||
)
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ def decompile_file(in_file, out_file) -> T.Union[str, CouldNotPort]:
|
|||
print(
|
||||
f"""{Colors.FAINT}Either the original XML file had an error, or there is a bug in the
|
||||
porting tool. If you think it's a bug (which is likely), please file an issue on GitLab:
|
||||
{Colors.BLUE}{Colors.UNDERLINE}https://gitlab.gnome.org/jwestman/blueprint-compiler/-/issues/new?issue{Colors.CLEAR}\n"""
|
||||
{Colors.BLUE}{Colors.UNDERLINE}https://gitlab.gnome.org/GNOME/blueprint-compiler/-/issues/new?issue{Colors.CLEAR}\n"""
|
||||
)
|
||||
|
||||
return CouldNotPort("does not compile")
|
||||
|
@ -136,7 +136,7 @@ def step1():
|
|||
wrap.write(
|
||||
f"""[wrap-git]
|
||||
directory = blueprint-compiler
|
||||
url = https://gitlab.gnome.org/jwestman/blueprint-compiler.git
|
||||
url = https://gitlab.gnome.org/GNOME/blueprint-compiler.git
|
||||
revision = {VERSION}
|
||||
depth = 1
|
||||
|
||||
|
|
|
@ -81,8 +81,8 @@ class AdwBreakpointSetter(AstNode):
|
|||
return self.tokens["property"]
|
||||
|
||||
@property
|
||||
def value(self) -> Value:
|
||||
return self.children[Value][0]
|
||||
def value(self) -> T.Optional[Value]:
|
||||
return self.children[Value][0] if len(self.children[Value]) > 0 else None
|
||||
|
||||
@property
|
||||
def gir_class(self) -> T.Optional[GirType]:
|
||||
|
@ -106,7 +106,10 @@ class AdwBreakpointSetter(AstNode):
|
|||
return None
|
||||
|
||||
@property
|
||||
def document_symbol(self) -> DocumentSymbol:
|
||||
def document_symbol(self) -> T.Optional[DocumentSymbol]:
|
||||
if self.value is None:
|
||||
return None
|
||||
|
||||
return DocumentSymbol(
|
||||
f"{self.object_id}.{self.property_name}",
|
||||
SymbolKind.Property,
|
||||
|
|
|
@ -302,12 +302,18 @@ expr.children = [
|
|||
|
||||
@decompiler("lookup", skip_children=True, cdata=True)
|
||||
def decompile_lookup(
|
||||
ctx: DecompileCtx, gir: gir.GirContext, cdata: str, name: str, type: str
|
||||
ctx: DecompileCtx,
|
||||
gir: gir.GirContext,
|
||||
cdata: str,
|
||||
name: str,
|
||||
type: T.Optional[str] = None,
|
||||
):
|
||||
if ctx.parent_node is not None and ctx.parent_node.tag == "property":
|
||||
ctx.print("expr ")
|
||||
|
||||
if t := ctx.type_by_cname(type):
|
||||
if type is None:
|
||||
type = ""
|
||||
elif t := ctx.type_by_cname(type):
|
||||
type = decompile.full_name(t)
|
||||
else:
|
||||
type = "$" + type
|
||||
|
@ -327,7 +333,7 @@ def decompile_lookup(
|
|||
if constant == ctx.template_class:
|
||||
ctx.print("template." + name)
|
||||
elif constant == "":
|
||||
ctx.print("item as <" + type + ">." + name)
|
||||
ctx.print(f"item as <{type}>.{name}")
|
||||
else:
|
||||
ctx.print(constant + "." + name)
|
||||
return
|
||||
|
|
|
@ -225,8 +225,14 @@ class Signal(AstNode):
|
|||
|
||||
|
||||
@decompiler("signal")
|
||||
def decompile_signal(ctx, gir, name, handler, swapped=None, after="false", object=None):
|
||||
def decompile_signal(
|
||||
ctx: DecompileCtx, gir, name, handler, swapped=None, after="false", object=None
|
||||
):
|
||||
object_name = object or ""
|
||||
|
||||
if object_name == ctx.template_class:
|
||||
object_name = "template"
|
||||
|
||||
name = name.replace("_", "-")
|
||||
line = f"{name} => ${handler}({object_name})"
|
||||
|
||||
|
|
|
@ -225,12 +225,12 @@ class Flag(AstNode):
|
|||
return self.tokens["value"]
|
||||
|
||||
@property
|
||||
def value(self) -> T.Optional[int]:
|
||||
def value(self) -> T.Optional[str]:
|
||||
type = self.context[ValueTypeCtx].value_type
|
||||
if not isinstance(type, Enumeration):
|
||||
return None
|
||||
elif member := type.members.get(self.name):
|
||||
return member.value
|
||||
return member.nick
|
||||
else:
|
||||
return None
|
||||
|
||||
|
|
|
@ -308,6 +308,9 @@ class XmlOutput(OutputFormat):
|
|||
|
||||
elif isinstance(extension, AdwBreakpointSetters):
|
||||
for setter in extension.setters:
|
||||
if setter.value is None:
|
||||
continue
|
||||
|
||||
attrs = {}
|
||||
|
||||
if isinstance(setter.value.child, Translated):
|
||||
|
|
|
@ -73,6 +73,7 @@ class XmlEmitter:
|
|||
self._needs_newline = False
|
||||
|
||||
def put_cdata(self, text: str):
|
||||
text = text.replace("]]>", "]]]]><![CDATA[>")
|
||||
self.result += f"<![CDATA[{text}]]>"
|
||||
self._needs_newline = False
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
""" Utilities for parsing an AST from a token stream. """
|
||||
"""Utilities for parsing an AST from a token stream."""
|
||||
|
||||
import typing as T
|
||||
from enum import Enum
|
||||
|
|
|
@ -9,7 +9,7 @@ from pathlib import Path
|
|||
|
||||
__all__ = ["get_docs_section"]
|
||||
|
||||
DOCS_ROOT = "https://jwestman.pages.gitlab.gnome.org/blueprint-compiler"
|
||||
DOCS_ROOT = "https://gnome.pages.gitlab.gnome.org/blueprint-compiler"
|
||||
|
||||
|
||||
sections: dict[str, "Section"] = {}
|
||||
|
@ -132,5 +132,8 @@ if __name__ == "__main__":
|
|||
# print the sections to a json file
|
||||
with open(outfile, "w") as f:
|
||||
json.dump(
|
||||
{name: section.to_json() for name, section in sections.items()}, f, indent=2
|
||||
{name: section.to_json() for name, section in sections.items()},
|
||||
f,
|
||||
indent=2,
|
||||
sort_keys=True,
|
||||
)
|
||||
|
|
|
@ -16,7 +16,7 @@ a module in your flatpak manifest:
|
|||
"sources": [
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://gitlab.gnome.org/jwestman/blueprint-compiler",
|
||||
"url": "https://gitlab.gnome.org/GNOME/blueprint-compiler",
|
||||
"tag": "v0.16.0"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -26,7 +26,7 @@ Blueprint is a markup language and compiler for GTK 4 user interfaces.
|
|||
|
||||
using Gtk 4.0;
|
||||
|
||||
template MyAppWindow : ApplicationWindow {
|
||||
template $MyAppWindow: ApplicationWindow {
|
||||
default-width: 600;
|
||||
default-height: 300;
|
||||
title: _("Hello, Blueprint!");
|
||||
|
@ -35,7 +35,7 @@ Blueprint is a markup language and compiler for GTK 4 user interfaces.
|
|||
HeaderBar {}
|
||||
|
||||
Label {
|
||||
label: bind MyAppWindow.main_text;
|
||||
label: bind template.main_text;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ Features
|
|||
Links
|
||||
-----
|
||||
|
||||
- `Source code <https://gitlab.gnome.org/jwestman/blueprint-compiler>`_
|
||||
- `Source code <https://gitlab.gnome.org/GNOME/blueprint-compiler>`_
|
||||
- `Workbench <https://github.com/sonnyp/Workbench>`_ lets you try, preview and export Blueprint
|
||||
- `GNOME Builder <https://developer.gnome.org/documentation/introduction/builder.html>`_ provides builtin support
|
||||
- `Vim syntax highlighting plugin by thetek42 <https://github.com/thetek42/vim-blueprint-syntax>`_
|
||||
|
|
|
@ -10,7 +10,7 @@ Properties are the main way to set values on objects, but they are limited by th
|
|||
|
||||
Extensions are a feature of ``Gtk.Buildable``--see `Gtk.Buildable.custom_tag_start() <https://docs.gtk.org/gtk4/vfunc.Buildable.custom_tag_start.html>`_ for internal details.
|
||||
|
||||
Because they aren't part of the type system, they aren't present in typelib files like properties and signals are. Therefore, if a library adds a new extension, syntax for it must be added to Blueprint manually. If there's a commonly used extension that isn't supported by Blueprint, please `file an issue <https://gitlab.gnome.org/jwestman/blueprint-compiler/-/issues>`_.
|
||||
Because they aren't part of the type system, they aren't present in typelib files like properties and signals are. Therefore, if a library adds a new extension, syntax for it must be added to Blueprint manually. If there's a commonly used extension that isn't supported by Blueprint, please `file an issue <https://gitlab.gnome.org/GNOME/blueprint-compiler/-/issues>`_.
|
||||
|
||||
.. rst-class:: grammar-block
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ Setting up Blueprint on a new or existing project
|
|||
Using the porting tool
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Clone `blueprint-compiler <https://gitlab.gnome.org/jwestman/blueprint-compiler>`_
|
||||
Clone `blueprint-compiler <https://gitlab.gnome.org/GNOME/blueprint-compiler>`_
|
||||
from source. You can install it using ``meson _build`` and ``ninja -C _build install``,
|
||||
or you can leave it uninstalled.
|
||||
|
||||
|
@ -29,7 +29,7 @@ blueprint-compiler works as a meson subproject.
|
|||
|
||||
[wrap-git]
|
||||
directory = blueprint-compiler
|
||||
url = https://gitlab.gnome.org/jwestman/blueprint-compiler.git
|
||||
url = https://gitlab.gnome.org/GNOME/blueprint-compiler.git
|
||||
revision = main
|
||||
depth = 1
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
|
|||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<object class="GApplication">
|
||||
<property name="flags">1|4</property>
|
||||
<property name="flags">is-service|handles-open</property>
|
||||
</object>
|
||||
<object class="GtkEventControllerScroll">
|
||||
<property name="flags">1</property>
|
||||
|
|
15
tests/samples/issue_187.ui
Normal file
15
tests/samples/issue_187.ui
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<template class="GtkListItem">
|
||||
<property name="child">
|
||||
<object class="GtkLabel">
|
||||
<binding name="label">
|
||||
<lookup type="RecentObject" name="filename">
|
||||
<lookup name="item">GtkListItem</lookup>
|
||||
</lookup>
|
||||
</binding>
|
||||
</object>
|
||||
</property>
|
||||
</template>
|
||||
</interface>
|
7
tests/samples/issue_187_dec.blp
Normal file
7
tests/samples/issue_187_dec.blp
Normal file
|
@ -0,0 +1,7 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template ListItem {
|
||||
child: Label {
|
||||
label: bind template.item as <$RecentObject>.filename;
|
||||
};
|
||||
}
|
17
tests/samples/list_factory_nested.blp
Normal file
17
tests/samples/list_factory_nested.blp
Normal file
|
@ -0,0 +1,17 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Gtk.ListView {
|
||||
factory: Gtk.BuilderListItemFactory list_item_factory {
|
||||
template ListItem {
|
||||
child: Gtk.ListView {
|
||||
factory: Gtk.BuilderListItemFactory list_item_factory {
|
||||
template ListItem {
|
||||
child: Gtk.Label {
|
||||
label: bind template.item as <$MyObject>.name;
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
44
tests/samples/list_factory_nested.ui
Normal file
44
tests/samples/list_factory_nested.ui
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?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="GtkListView">
|
||||
<property name="factory">
|
||||
<object class="GtkBuilderListItemFactory" id="list_item_factory">
|
||||
<property name="bytes"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="GtkListItem">
|
||||
<property name="child">
|
||||
<object class="GtkListView">
|
||||
<property name="factory">
|
||||
<object class="GtkBuilderListItemFactory" id="list_item_factory">
|
||||
<property name="bytes"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="GtkListItem">
|
||||
<property name="child">
|
||||
<object class="GtkLabel">
|
||||
<binding name="label">
|
||||
<lookup name="name" type="MyObject">
|
||||
<lookup name="item" type="GtkListItem">
|
||||
<constant>GtkListItem</constant>
|
||||
</lookup>
|
||||
</lookup>
|
||||
</binding>
|
||||
</object>
|
||||
</property>
|
||||
</template>
|
||||
</interface>]]]]><![CDATA[></property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</property>
|
||||
</template>
|
||||
</interface>]]></property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</interface>
|
18
tests/samples/list_factory_nested_dec.blp
Normal file
18
tests/samples/list_factory_nested_dec.blp
Normal file
|
@ -0,0 +1,18 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
ListView {
|
||||
factory: BuilderListItemFactory list_item_factory {
|
||||
template ListItem {
|
||||
child: ListView {
|
||||
factory: BuilderListItemFactory list_item_factory {
|
||||
template ListItem {
|
||||
child: Label {
|
||||
label: bind template.item as <$MyObject>.name;
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
7
tests/samples/signal_template_object.blp
Normal file
7
tests/samples/signal_template_object.blp
Normal file
|
@ -0,0 +1,7 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template $MyTemplate {
|
||||
Button {
|
||||
clicked => $my_signal_handler(template);
|
||||
}
|
||||
}
|
16
tests/samples/signal_template_object.ui
Normal file
16
tests/samples/signal_template_object.ui
Normal 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"/>
|
||||
<template class="MyTemplate">
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<signal name="clicked" handler="my_signal_handler" object="MyTemplate"/>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
|
@ -181,11 +181,7 @@ class TestSamples(unittest.TestCase):
|
|||
|
||||
def test_samples(self):
|
||||
# list the samples directory
|
||||
samples = [
|
||||
f.stem
|
||||
for f in Path(__file__).parent.glob("samples/*.blp")
|
||||
if not f.stem.endswith("_dec")
|
||||
]
|
||||
samples = [f.stem for f in Path(__file__).parent.glob("samples/*.blp")]
|
||||
samples.sort()
|
||||
for sample in samples:
|
||||
REQUIRE_ADW_1_4 = ["adw_breakpoint"]
|
||||
|
@ -202,6 +198,7 @@ class TestSamples(unittest.TestCase):
|
|||
"parseable",
|
||||
"signal",
|
||||
"signal_not_swapped",
|
||||
"signal_template_object",
|
||||
"template",
|
||||
"template_binding",
|
||||
"template_binding_extern",
|
||||
|
@ -215,7 +212,7 @@ class TestSamples(unittest.TestCase):
|
|||
]
|
||||
|
||||
# Decompiler-only tests
|
||||
SKIP_COMPILE = ["issue_177", "translator_comments"]
|
||||
SKIP_COMPILE = ["issue_177", "issue_187", "translator_comments"]
|
||||
|
||||
SKIP_DECOMPILE = [
|
||||
# Comments are not preserved in either direction
|
||||
|
@ -228,7 +225,7 @@ class TestSamples(unittest.TestCase):
|
|||
continue
|
||||
|
||||
with self.subTest(sample):
|
||||
if sample not in SKIP_COMPILE:
|
||||
if sample not in SKIP_COMPILE and not sample.endswith("_dec"):
|
||||
self.assert_sample(sample, skip_run=sample in SKIP_RUN)
|
||||
|
||||
with self.subTest("decompile/" + sample):
|
||||
|
|
|
@ -25,7 +25,7 @@ from blueprintcompiler.tokenizer import Token, TokenType, tokenize
|
|||
|
||||
|
||||
class TestTokenizer(unittest.TestCase):
|
||||
def assert_tokenize(self, string: str, expect: [Token]):
|
||||
def assert_tokenize(self, string: str, expect: list[Token]):
|
||||
try:
|
||||
tokens = tokenize(string)
|
||||
self.assertEqual(len(tokens), len(expect))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue