mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Compare commits
35 commits
72583be267
...
72319b29c6
Author | SHA1 | Date | |
---|---|---|---|
|
72319b29c6 | ||
|
67983aee2e | ||
|
1205fc42ea | ||
|
e9206809d6 | ||
|
d5b2ee3589 | ||
|
8f3ae9a626 | ||
|
e5d6910626 | ||
|
b26433d865 | ||
|
866092ccf7 | ||
|
1e9b01bab9 | ||
|
b9910db849 | ||
|
d0394136cf | ||
|
860580e560 | ||
|
64b96137f5 | ||
|
f5cef37db8 | ||
|
3d0593bc2b | ||
|
bf4d8579b6 | ||
|
2e42dc6848 | ||
|
a12d3f5c81 | ||
|
a83c7e936d | ||
|
3816f4fe8d | ||
|
e9d61cb6f9 | ||
|
6a77bfee0a | ||
|
f50b898e4c | ||
|
cc09f3d3bb | ||
|
f93d5d2acd | ||
|
394014429e | ||
|
a4e0c3701b | ||
|
c1fbcef6d0 | ||
|
404ae76787 | ||
|
04ef0944db | ||
|
aa13c8f5af | ||
|
e07da3c339 | ||
|
2ae41020ab | ||
|
f48b840cfa |
61 changed files with 659 additions and 187 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
|
||||
|
||||
|
|
32
NEWS.md
32
NEWS.md
|
@ -1,3 +1,35 @@
|
|||
# v0.16.0
|
||||
|
||||
## Added
|
||||
- Added more "go to reference" implementations in the language server
|
||||
- Added semantic token support for flag members in the language server
|
||||
- Added property documentation to the hover tooltip for notify signals
|
||||
- The language server now shows relevant sections of the reference documentation when hovering over keywords and symbols
|
||||
- Added `not-swapped` flag to signal handlers, which may be needed for signal handlers that specify an object
|
||||
- Added expression literals, which allow you to specify a Gtk.Expression property (as opposed to the existing expression support, which is for property bindings)
|
||||
|
||||
## Changed
|
||||
- The formatter adds trailing commas to lists (Alexey Yerin)
|
||||
- The formatter removes trailing whitespace from comments (Alexey Yerin)
|
||||
- Autocompleting a commonly translated property automatically adds the `_("")` syntax
|
||||
- Marking a single-quoted string as translatable now generates a warning, since gettext does not recognize it when using the configuration recommended in the blueprint documentation
|
||||
|
||||
## Fixed
|
||||
- Added support for libgirepository-2.0 so that blueprint doesn't crash due to import conflicts on newer versions of PyGObject (Jordan Petridis)
|
||||
- Fixed a bug when decompiling/porting files with enum values
|
||||
- Fixed several issues where tests would fail with versions of GTK that added new deprecations
|
||||
- Addressed a problem with the language server protocol in some editors (Luoyayu)
|
||||
- Fixed an issue where the compiler would crash instead of reporting compiler errors
|
||||
- Fixed a crash in the language server that occurred when a detailed signal (e.g. `notify::*`) was not complete
|
||||
- The language server now properly implements the shutdown command, fixing support for some editors and improving robustness when restarting (Alexey Yerin)
|
||||
- Marking a string in an array as translatable now generates an error, since it doesn't work
|
||||
-
|
||||
|
||||
## Documentation
|
||||
- Added mention of `null` in the Literal Values section
|
||||
- Add apps to Built with Blueprint section (Benedek Dévényi, Vladimir Vaskov)
|
||||
- Corrected and updated many parts of the documentation
|
||||
|
||||
# v0.14.0
|
||||
|
||||
## Added
|
||||
|
|
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>
|
|
@ -196,6 +196,13 @@ class AstNode:
|
|||
|
||||
return None
|
||||
|
||||
def get_child_at(self, idx: int) -> "AstNode":
|
||||
for child in self.children:
|
||||
if idx in child.range:
|
||||
return child.get_child_at(idx)
|
||||
|
||||
return self
|
||||
|
||||
def get_semantic_tokens(self) -> T.Iterator[SemanticToken]:
|
||||
for child in self.children:
|
||||
yield from child.get_semantic_tokens()
|
||||
|
|
|
@ -21,7 +21,18 @@ import typing as T
|
|||
|
||||
from . import annotations, gir, language
|
||||
from .ast_utils import AstNode
|
||||
from .completions_utils import *
|
||||
from .completions_utils import (
|
||||
CompletionContext,
|
||||
CompletionItemKind,
|
||||
CompletionPriority,
|
||||
completer,
|
||||
completers,
|
||||
get_object_id_completions,
|
||||
get_property_completion,
|
||||
get_sort_key,
|
||||
new_statement_patterns,
|
||||
)
|
||||
from .language.contexts import ValueTypeCtx
|
||||
from .language.types import ClassName
|
||||
from .lsp_utils import Completion, CompletionItemKind, TextEdit, get_docs_section
|
||||
from .parser import SKIP_TOKENS
|
||||
|
@ -38,13 +49,6 @@ def _complete(
|
|||
token_idx: int,
|
||||
next_token: Token,
|
||||
) -> T.Iterator[Completion]:
|
||||
for child in ast_node.children:
|
||||
if child.group.start <= idx and (
|
||||
idx < child.group.end or (idx == child.group.end and child.incomplete)
|
||||
):
|
||||
yield from _complete(lsp, child, tokens, idx, token_idx, next_token)
|
||||
return
|
||||
|
||||
prev_tokens: T.List[Token] = []
|
||||
|
||||
# collect the 5 previous non-skipped tokens
|
||||
|
@ -54,7 +58,7 @@ def _complete(
|
|||
prev_tokens.insert(0, token)
|
||||
token_idx -= 1
|
||||
|
||||
for completer in ast_node.completers:
|
||||
for completer in completers:
|
||||
yield from completer(prev_tokens, next_token, ast_node, lsp, idx)
|
||||
|
||||
|
||||
|
@ -76,11 +80,25 @@ def complete(
|
|||
next_token = tokens[next_token_idx]
|
||||
|
||||
# if the current token is an identifier or whitespace, move to the token before it
|
||||
while tokens[token_idx].type in [TokenType.IDENT, TokenType.WHITESPACE]:
|
||||
if tokens[token_idx].type == TokenType.IDENT:
|
||||
idx = tokens[token_idx].start
|
||||
token_idx -= 1
|
||||
|
||||
yield from _complete(lsp, ast_node, tokens, idx, token_idx, next_token)
|
||||
while tokens[token_idx].type == TokenType.WHITESPACE:
|
||||
idx = tokens[token_idx].start
|
||||
token_idx -= 1
|
||||
|
||||
child_node = ast_node.get_child_at(idx)
|
||||
# If the cursor is at the end of a node, completions should be for the next child of the parent, unless the node
|
||||
# is incomplete.
|
||||
while (
|
||||
child_node.range.end == idx
|
||||
and not child_node.incomplete
|
||||
and child_node.parent is not None
|
||||
):
|
||||
child_node = child_node.parent
|
||||
|
||||
yield from _complete(lsp, child_node, tokens, idx, token_idx, next_token)
|
||||
|
||||
|
||||
@completer([language.GtkDirective])
|
||||
|
@ -159,7 +177,13 @@ def _available_namespace_completions(ctx: CompletionContext):
|
|||
|
||||
|
||||
@completer(
|
||||
applies_in=[language.UI, language.ObjectContent, language.Template],
|
||||
applies_in=[
|
||||
language.UI,
|
||||
language.ObjectContent,
|
||||
language.Template,
|
||||
language.TypeName,
|
||||
language.BracketedTypeName,
|
||||
],
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def namespace(ctx: CompletionContext):
|
||||
|
@ -180,7 +204,13 @@ def namespace(ctx: CompletionContext):
|
|||
|
||||
|
||||
@completer(
|
||||
applies_in=[language.UI, language.ObjectContent, language.Template],
|
||||
applies_in=[
|
||||
language.UI,
|
||||
language.ObjectContent,
|
||||
language.Template,
|
||||
language.TypeName,
|
||||
language.BracketedTypeName,
|
||||
],
|
||||
matches=[
|
||||
[(TokenType.IDENT, None), (TokenType.OP, "."), (TokenType.IDENT, None)],
|
||||
[(TokenType.IDENT, None), (TokenType.OP, ".")],
|
||||
|
@ -191,7 +221,11 @@ def object_completer(ctx: CompletionContext):
|
|||
if ns is not None:
|
||||
for c in ns.classes.values():
|
||||
snippet = c.name
|
||||
if str(ctx.next_token) != "{":
|
||||
if (
|
||||
str(ctx.next_token) != "{"
|
||||
and not isinstance(ctx.ast_node, language.TypeName)
|
||||
and not isinstance(ctx.ast_node, language.BracketedTypeName)
|
||||
):
|
||||
snippet += " {\n $0\n}"
|
||||
|
||||
yield Completion(
|
||||
|
@ -205,7 +239,13 @@ def object_completer(ctx: CompletionContext):
|
|||
|
||||
|
||||
@completer(
|
||||
applies_in=[language.UI, language.ObjectContent, language.Template],
|
||||
applies_in=[
|
||||
language.UI,
|
||||
language.ObjectContent,
|
||||
language.Template,
|
||||
language.TypeName,
|
||||
language.BracketedTypeName,
|
||||
],
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def gtk_object_completer(ctx: CompletionContext):
|
||||
|
@ -213,7 +253,11 @@ def gtk_object_completer(ctx: CompletionContext):
|
|||
if ns is not None:
|
||||
for c in ns.classes.values():
|
||||
snippet = c.name
|
||||
if str(ctx.next_token) != "{":
|
||||
if (
|
||||
str(ctx.next_token) != "{"
|
||||
and not isinstance(ctx.ast_node, language.TypeName)
|
||||
and not isinstance(ctx.ast_node, language.BracketedTypeName)
|
||||
):
|
||||
snippet += " {\n $0\n}"
|
||||
|
||||
yield Completion(
|
||||
|
@ -225,6 +269,17 @@ def gtk_object_completer(ctx: CompletionContext):
|
|||
detail=c.detail,
|
||||
)
|
||||
|
||||
if isinstance(ctx.ast_node, language.BracketedTypeName) or (
|
||||
isinstance(ctx.ast_node, language.TypeName)
|
||||
and not isinstance(ctx.ast_node, language.ClassName)
|
||||
):
|
||||
for basic_type in gir.BASIC_TYPES:
|
||||
yield Completion(
|
||||
basic_type,
|
||||
CompletionItemKind.Class,
|
||||
sort_text=get_sort_key(CompletionPriority.CLASS, basic_type),
|
||||
)
|
||||
|
||||
|
||||
@completer(
|
||||
applies_in=[language.ObjectContent],
|
||||
|
@ -236,7 +291,7 @@ def property_completer(ctx: CompletionContext):
|
|||
for prop_name, prop in ctx.ast_node.gir_class.properties.items():
|
||||
yield get_property_completion(
|
||||
prop_name,
|
||||
prop,
|
||||
prop.type,
|
||||
ctx,
|
||||
annotations.is_property_translated(prop),
|
||||
prop.doc,
|
||||
|
@ -245,7 +300,11 @@ def property_completer(ctx: CompletionContext):
|
|||
|
||||
@completer(
|
||||
applies_in=[language.Property, language.A11yProperty],
|
||||
matches=[[(TokenType.IDENT, None), (TokenType.OP, ":")]],
|
||||
matches=[
|
||||
[(TokenType.IDENT, None), (TokenType.OP, ":")],
|
||||
[(TokenType.PUNCTUATION, ",")],
|
||||
[(TokenType.PUNCTUATION, "[")],
|
||||
],
|
||||
)
|
||||
def prop_value_completer(ctx: CompletionContext):
|
||||
if isinstance(ctx.ast_node, language.Property):
|
||||
|
@ -262,6 +321,8 @@ def prop_value_completer(ctx: CompletionContext):
|
|||
)
|
||||
|
||||
if (vt := ctx.ast_node.value_type) is not None:
|
||||
assert isinstance(vt, ValueTypeCtx)
|
||||
|
||||
if isinstance(vt.value_type, gir.Enumeration):
|
||||
for name, member in vt.value_type.members.items():
|
||||
yield Completion(
|
||||
|
@ -287,22 +348,14 @@ def prop_value_completer(ctx: CompletionContext):
|
|||
elif isinstance(vt.value_type, gir.Class) or isinstance(
|
||||
vt.value_type, gir.Interface
|
||||
):
|
||||
yield Completion(
|
||||
"null",
|
||||
CompletionItemKind.Constant,
|
||||
sort_text=get_sort_key(CompletionPriority.KEYWORD, "null"),
|
||||
)
|
||||
if vt.allow_null:
|
||||
yield Completion(
|
||||
"null",
|
||||
CompletionItemKind.Constant,
|
||||
sort_text=get_sort_key(CompletionPriority.KEYWORD, "null"),
|
||||
)
|
||||
|
||||
for id, obj in ctx.ast_node.root.context[language.ScopeCtx].objects.items():
|
||||
if obj.gir_class is not None and obj.gir_class.assignable_to(
|
||||
vt.value_type
|
||||
):
|
||||
yield Completion(
|
||||
id,
|
||||
CompletionItemKind.Variable,
|
||||
signature=" " + obj.signature,
|
||||
sort_text=get_sort_key(CompletionPriority.NAMED_OBJECT, id),
|
||||
)
|
||||
yield from get_object_id_completions(ctx, vt.value_type)
|
||||
|
||||
if isinstance(ctx.ast_node, language.Property):
|
||||
yield from _available_namespace_completions(ctx)
|
||||
|
@ -348,7 +401,7 @@ def signal_completer(ctx: CompletionContext):
|
|||
.lower()
|
||||
)
|
||||
|
||||
snippet = f"{signal_name} => \\$${{1:${name}_{signal_name.replace('-', '_')}}}()$0;"
|
||||
snippet = f"{signal_name} => \\$${{1:{name}_{signal_name.replace('-', '_')}}}()$0;"
|
||||
|
||||
yield Completion(
|
||||
signal_name,
|
||||
|
@ -367,3 +420,58 @@ def template_completer(_ctx: CompletionContext):
|
|||
CompletionItemKind.Snippet,
|
||||
snippet="template ${1:ClassName} : ${2:ParentClass} {\n $0\n}",
|
||||
)
|
||||
|
||||
|
||||
@completer(
|
||||
applies_in=[language.ObjectContent, language.ChildType],
|
||||
matches=[[(TokenType.PUNCTUATION, "[")]],
|
||||
applies_in_subclass=[("Gtk", "Dialog"), ("Gtk", "InfoBar")],
|
||||
)
|
||||
def response_id_completer(ctx: CompletionContext):
|
||||
yield Completion(
|
||||
"action",
|
||||
CompletionItemKind.Snippet,
|
||||
sort_text=get_sort_key(CompletionPriority.KEYWORD, "action"),
|
||||
snippet="action response=$0",
|
||||
)
|
||||
|
||||
|
||||
@completer(
|
||||
[language.ChildAnnotation, language.ExtResponse],
|
||||
[[(TokenType.IDENT, "action"), (TokenType.IDENT, "response"), (TokenType.OP, "=")]],
|
||||
)
|
||||
def complete_response_id(ctx: CompletionContext):
|
||||
gir = ctx.ast_node.root.gir
|
||||
response_type = gir.get_type("ResponseType", "Gtk")
|
||||
yield from [
|
||||
Completion(
|
||||
name,
|
||||
kind=CompletionItemKind.EnumMember,
|
||||
docs=member.doc,
|
||||
)
|
||||
for name, member in response_type.members.items()
|
||||
]
|
||||
|
||||
|
||||
@completer(
|
||||
[language.ChildAnnotation, language.ExtResponse],
|
||||
[
|
||||
[
|
||||
(TokenType.IDENT, "action"),
|
||||
(TokenType.IDENT, "response"),
|
||||
(TokenType.OP, "="),
|
||||
(TokenType.IDENT, None),
|
||||
],
|
||||
[
|
||||
(TokenType.IDENT, "action"),
|
||||
(TokenType.IDENT, "response"),
|
||||
(TokenType.OP, "="),
|
||||
(TokenType.NUMBER, None),
|
||||
],
|
||||
],
|
||||
)
|
||||
def complete_response_default(ctx: CompletionContext):
|
||||
yield Completion(
|
||||
"default",
|
||||
kind=CompletionItemKind.Keyword,
|
||||
)
|
||||
|
|
|
@ -22,7 +22,7 @@ import typing as T
|
|||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
|
||||
from . import gir
|
||||
from . import gir, language
|
||||
from .ast_utils import AstNode
|
||||
from .lsp_utils import Completion, CompletionItemKind
|
||||
from .tokenizer import Token, TokenType
|
||||
|
@ -57,21 +57,40 @@ new_statement_patterns = [
|
|||
[(TokenType.PUNCTUATION, "}")],
|
||||
[(TokenType.PUNCTUATION, "]")],
|
||||
[(TokenType.PUNCTUATION, ";")],
|
||||
[(TokenType.OP, "<")],
|
||||
]
|
||||
|
||||
|
||||
completers = []
|
||||
|
||||
|
||||
def completer(applies_in: T.List, matches: T.List = [], applies_in_subclass=None):
|
||||
def decorator(func: T.Callable[[CompletionContext], T.Generator[Completion]]):
|
||||
def inner(
|
||||
prev_tokens: T.List[Token], next_token: Token, ast_node, lsp, idx: int
|
||||
):
|
||||
if not any(isinstance(ast_node, rule) for rule in applies_in):
|
||||
return
|
||||
|
||||
# For completers that apply in ObjectContent nodes, we can further
|
||||
# check that the object is the right class
|
||||
if applies_in_subclass is not None:
|
||||
type = ast_node.root.gir.get_type(
|
||||
applies_in_subclass[1], applies_in_subclass[0]
|
||||
)
|
||||
if not ast_node.gir_class or not ast_node.gir_class.assignable_to(type):
|
||||
parent_obj = ast_node
|
||||
while parent_obj is not None and not hasattr(parent_obj, "gir_class"):
|
||||
parent_obj = parent_obj.parent
|
||||
|
||||
if (
|
||||
parent_obj is None
|
||||
or not parent_obj.gir_class
|
||||
or not any(
|
||||
[
|
||||
parent_obj.gir_class.assignable_to(
|
||||
parent_obj.root.gir.get_type(c[1], c[0])
|
||||
)
|
||||
for c in applies_in_subclass
|
||||
]
|
||||
)
|
||||
):
|
||||
return
|
||||
|
||||
any_match = len(matches) == 0
|
||||
|
@ -106,8 +125,7 @@ def completer(applies_in: T.List, matches: T.List = [], applies_in_subclass=None
|
|||
)
|
||||
yield from func(context)
|
||||
|
||||
for c in applies_in:
|
||||
c.completers.append(inner)
|
||||
completers.append(inner)
|
||||
return inner
|
||||
|
||||
return decorator
|
||||
|
@ -145,3 +163,18 @@ def get_property_completion(
|
|||
snippet=snippet,
|
||||
docs=doc,
|
||||
)
|
||||
|
||||
|
||||
def get_object_id_completions(
|
||||
ctx: CompletionContext, value_type: T.Optional[gir.GirType] = None
|
||||
):
|
||||
for id, obj in ctx.ast_node.root.context[language.ScopeCtx].objects.items():
|
||||
if value_type is None or (
|
||||
obj.gir_class is not None and obj.gir_class.assignable_to(value_type)
|
||||
):
|
||||
yield Completion(
|
||||
id,
|
||||
CompletionItemKind.Variable,
|
||||
signature=" " + obj.signature,
|
||||
sort_text=get_sort_key(CompletionPriority.NAMED_OBJECT, id),
|
||||
)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -92,29 +92,38 @@ class CompileError(PrintableError):
|
|||
def pretty_print(self, filename: str, code: str, stream=sys.stdout) -> None:
|
||||
assert self.range is not None
|
||||
|
||||
line_num, col_num = utils.idx_to_pos(self.range.start + 1, code)
|
||||
end_line_num, end_col_num = utils.idx_to_pos(self.range.end + 1, code)
|
||||
line = code.splitlines(True)[line_num] if code != "" else ""
|
||||
def format_line(range: Range):
|
||||
line_num, col_num = utils.idx_to_pos(range.start, code)
|
||||
end_line_num, end_col_num = utils.idx_to_pos(range.end, code)
|
||||
line = code.splitlines(True)[line_num] if code != "" else ""
|
||||
|
||||
# Display 1-based line numbers
|
||||
line_num += 1
|
||||
end_line_num += 1
|
||||
# Display 1-based line numbers
|
||||
line_num += 1
|
||||
end_line_num += 1
|
||||
col_num += 1
|
||||
end_col_num += 1
|
||||
|
||||
n_spaces = col_num - 1
|
||||
n_carets = (
|
||||
(end_col_num - col_num)
|
||||
if line_num == end_line_num
|
||||
else (len(line) - n_spaces - 1)
|
||||
)
|
||||
n_spaces = col_num - 1
|
||||
n_carets = (
|
||||
(end_col_num - col_num)
|
||||
if line_num == end_line_num
|
||||
else (len(line) - n_spaces - 1)
|
||||
)
|
||||
|
||||
n_spaces += line.count("\t", 0, col_num)
|
||||
n_carets += line.count("\t", col_num, col_num + n_carets)
|
||||
line = line.replace("\t", " ")
|
||||
n_spaces += line.count("\t", 0, col_num)
|
||||
n_carets += line.count("\t", col_num, col_num + n_carets)
|
||||
line = line.replace("\t", " ")
|
||||
|
||||
n_carets = max(n_carets, 1)
|
||||
|
||||
return line_num, col_num, line.rstrip(), (" " * n_spaces) + ("^" * n_carets)
|
||||
|
||||
line_num, col_num, line, carets = format_line(self.range)
|
||||
|
||||
stream.write(
|
||||
f"""{self.color}{Colors.BOLD}{self.category}: {self.message}{Colors.CLEAR}
|
||||
at {filename} line {line_num} column {col_num}:
|
||||
{Colors.FAINT}{line_num :>4} |{Colors.CLEAR}{line.rstrip()}\n {Colors.FAINT}|{" "*n_spaces}{"^"*n_carets}{Colors.CLEAR}\n"""
|
||||
{Colors.FAINT}{line_num :>4} |{Colors.CLEAR}{line}\n {Colors.FAINT}|{carets}{Colors.CLEAR}\n"""
|
||||
)
|
||||
|
||||
for hint in self.hints:
|
||||
|
@ -139,14 +148,12 @@ at {filename} line {line_num} column {col_num}:
|
|||
)
|
||||
|
||||
for ref in self.references:
|
||||
line_num, col_num = utils.idx_to_pos(ref.range.start + 1, code)
|
||||
line = code.splitlines(True)[line_num]
|
||||
line_num += 1
|
||||
line_num, col_num, line, carets = format_line(ref.range)
|
||||
|
||||
stream.write(
|
||||
f"""{Colors.FAINT}note: {ref.message}:
|
||||
at {filename} line {line_num} column {col_num}:
|
||||
{Colors.FAINT}{line_num :>4} |{line.rstrip()}\n {Colors.FAINT}|{" "*(col_num-1)}^{Colors.CLEAR}\n"""
|
||||
{Colors.FAINT}{line_num :>4} |{line}\n {Colors.FAINT}|{carets}{Colors.CLEAR}\n"""
|
||||
)
|
||||
|
||||
stream.write("\n")
|
||||
|
@ -219,7 +226,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}"""
|
||||
)
|
||||
|
||||
|
|
|
@ -289,7 +289,7 @@ class TypeType(BasicType):
|
|||
return isinstance(other, TypeType)
|
||||
|
||||
|
||||
_BASIC_TYPES = {
|
||||
BASIC_TYPES = {
|
||||
"bool": BoolType,
|
||||
"string": StringType,
|
||||
"int": IntType,
|
||||
|
@ -914,7 +914,7 @@ class Namespace(GirNode):
|
|||
|
||||
def get_type_by_cname(self, cname: str) -> T.Optional[GirType]:
|
||||
"""Gets a type from this namespace by its C name."""
|
||||
for basic in _BASIC_TYPES.values():
|
||||
for basic in BASIC_TYPES.values():
|
||||
if basic.glib_type_name == cname:
|
||||
return basic()
|
||||
|
||||
|
@ -1036,8 +1036,8 @@ class GirContext:
|
|||
return None
|
||||
|
||||
def get_type(self, name: str, ns: str) -> T.Optional[GirType]:
|
||||
if ns is None and name in _BASIC_TYPES:
|
||||
return _BASIC_TYPES[name]()
|
||||
if ns is None and name in BASIC_TYPES:
|
||||
return BASIC_TYPES[name]()
|
||||
|
||||
ns = ns or "Gtk"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -34,10 +34,17 @@ from .gtk_scale import ExtScaleMarks
|
|||
from .gtk_size_group import ExtSizeGroupWidgets
|
||||
from .gtk_string_list import ExtStringListStrings
|
||||
from .gtk_styles import ExtStyles
|
||||
from .gtkbuilder_child import Child, ChildExtension, ChildInternal, ChildType
|
||||
from .gtkbuilder_child import (
|
||||
Child,
|
||||
ChildAnnotation,
|
||||
ChildExtension,
|
||||
ChildInternal,
|
||||
ChildType,
|
||||
)
|
||||
from .gtkbuilder_template import Template
|
||||
from .imports import GtkDirective, Import
|
||||
from .types import ClassName
|
||||
from .response_id import ExtResponse
|
||||
from .types import BracketedTypeName, ClassName, TypeName
|
||||
from .ui import UI
|
||||
from .values import (
|
||||
ArrayValue,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -140,7 +140,7 @@ class ExtAdwResponseDialog(AstNode):
|
|||
|
||||
@completer(
|
||||
applies_in=[ObjectContent],
|
||||
applies_in_subclass=("Adw", "MessageDialog"),
|
||||
applies_in_subclass=[("Adw", "AlertDialog"), ("Adw", "MessageDialog")],
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def complete_adw_message_dialog(_ctx: CompletionContext):
|
||||
|
@ -149,20 +149,6 @@ def complete_adw_message_dialog(_ctx: CompletionContext):
|
|||
)
|
||||
|
||||
|
||||
@completer(
|
||||
applies_in=[ObjectContent],
|
||||
applies_in_subclass=("Adw", "AlertDialog"),
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def complete_adw_alert_dialog(_ctx: CompletionContext):
|
||||
yield Completion(
|
||||
"responses",
|
||||
CompletionItemKind.Keyword,
|
||||
snippet="responses [\n\t$0\n]",
|
||||
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "responses"),
|
||||
)
|
||||
|
||||
|
||||
@decompiler("responses")
|
||||
def decompile_responses(ctx, gir):
|
||||
ctx.print(f"responses [")
|
||||
|
|
|
@ -34,6 +34,7 @@ from ..errors import (
|
|||
CompileError,
|
||||
CompileWarning,
|
||||
DeprecatedWarning,
|
||||
ErrorReference,
|
||||
MultipleErrors,
|
||||
UnusedWarning,
|
||||
UpgradeWarning,
|
||||
|
|
|
@ -48,7 +48,7 @@ class ScopeCtx:
|
|||
return self.node
|
||||
|
||||
@cached_property
|
||||
def objects(self) -> T.Dict[str, Object]:
|
||||
def objects(self) -> T.Dict[str, AstNode]:
|
||||
return {
|
||||
obj.tokens["id"]: obj
|
||||
for obj in self._iter_recursive(self.node)
|
||||
|
@ -58,7 +58,7 @@ class ScopeCtx:
|
|||
def validate_unique_ids(self) -> None:
|
||||
from .gtk_list_item_factory import ExtListItemFactory
|
||||
|
||||
passed = {}
|
||||
passed: T.Dict[str, AstNode] = {}
|
||||
for obj in self._iter_recursive(self.node):
|
||||
if obj.tokens["id"] is None:
|
||||
continue
|
||||
|
@ -71,10 +71,16 @@ class ScopeCtx:
|
|||
raise CompileError(
|
||||
f"Duplicate object ID '{obj.tokens['id']}'",
|
||||
token.range,
|
||||
references=[
|
||||
ErrorReference(
|
||||
passed[obj.tokens["id"]].group.tokens["id"].range,
|
||||
"previous declaration was here",
|
||||
)
|
||||
],
|
||||
)
|
||||
passed[obj.tokens["id"]] = obj
|
||||
|
||||
def _iter_recursive(self, node: AstNode):
|
||||
def _iter_recursive(self, node: AstNode) -> T.Generator[AstNode, T.Any, None]:
|
||||
yield node
|
||||
for child in node.children:
|
||||
if child.context[ScopeCtx] is self:
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
from ..decompiler import decompile_element
|
||||
from .common import *
|
||||
from .contexts import ScopeCtx, ValueTypeCtx
|
||||
from .types import TypeName
|
||||
from .types import BracketedTypeName, TypeName
|
||||
|
||||
expr = Sequence()
|
||||
|
||||
|
@ -196,7 +196,7 @@ class CastExpr(InfixExpr):
|
|||
grammar = [
|
||||
Keyword("as"),
|
||||
AnyOf(
|
||||
["<", TypeName, Match(">").expected()],
|
||||
BracketedTypeName,
|
||||
[
|
||||
UseExact("lparen", "("),
|
||||
TypeName,
|
||||
|
@ -211,7 +211,13 @@ class CastExpr(InfixExpr):
|
|||
|
||||
@property
|
||||
def type(self) -> T.Optional[GirType]:
|
||||
return self.children[TypeName][0].gir_type
|
||||
if len(self.children[BracketedTypeName]) == 1:
|
||||
type_name = self.children[BracketedTypeName][0].type_name
|
||||
return None if type_name is None else type_name.gir_type
|
||||
elif len(self.children[TypeName]) == 1:
|
||||
return self.children[TypeName][0].gir_type
|
||||
else:
|
||||
return None
|
||||
|
||||
@validate()
|
||||
def cast_makes_sense(self):
|
||||
|
@ -302,12 +308,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 +339,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})"
|
||||
|
||||
|
@ -241,3 +247,11 @@ def decompile_signal(ctx, gir, name, handler, swapped=None, after="false", objec
|
|||
line += ";"
|
||||
ctx.print(line)
|
||||
return gir
|
||||
|
||||
|
||||
@completer(
|
||||
[Signal],
|
||||
[[(TokenType.PUNCTUATION, "(")]],
|
||||
)
|
||||
def signal_object_completer(ctx: CompletionContext):
|
||||
yield from get_object_id_completions(ctx)
|
||||
|
|
|
@ -31,6 +31,7 @@ def get_property_types(gir: gir.GirContext) -> T.Dict[str, T.Optional[GirType]]:
|
|||
"autocomplete": gir.get_type("AccessibleAutocomplete", "Gtk"),
|
||||
"description": StringType(),
|
||||
"has-popup": BoolType(),
|
||||
"help-text": StringType(),
|
||||
"key-shortcuts": StringType(),
|
||||
"label": StringType(),
|
||||
"level": IntType(),
|
||||
|
@ -86,6 +87,7 @@ def get_state_types(gir: gir.GirContext) -> T.Dict[str, T.Optional[GirType]]:
|
|||
"invalid": gir.get_type("AccessibleInvalidState", "Gtk"),
|
||||
"pressed": gir.get_type("AccessibleTristate", "Gtk"),
|
||||
"selected": BoolType(),
|
||||
"visited": BoolType(),
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ class ExtComboBoxItems(AstNode):
|
|||
|
||||
@completer(
|
||||
applies_in=[ObjectContent],
|
||||
applies_in_subclass=("Gtk", "ComboBoxText"),
|
||||
applies_in_subclass=[("Gtk", "ComboBoxText")],
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def items_completer(_ctx: CompletionContext):
|
||||
|
|
|
@ -98,7 +98,7 @@ ext_file_filter_suffixes = create_node("suffixes", "suffix")
|
|||
|
||||
@completer(
|
||||
applies_in=[ObjectContent],
|
||||
applies_in_subclass=("Gtk", "FileFilter"),
|
||||
applies_in_subclass=[("Gtk", "FileFilter")],
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def file_filter_completer(_ctx: CompletionContext):
|
||||
|
|
|
@ -90,7 +90,7 @@ class ExtLayout(AstNode):
|
|||
|
||||
@completer(
|
||||
applies_in=[ObjectContent],
|
||||
applies_in_subclass=("Gtk", "Widget"),
|
||||
applies_in_subclass=[("Gtk", "Widget")],
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def layout_completer(_ctx: CompletionContext):
|
||||
|
|
|
@ -23,22 +23,20 @@ from .values import StringValue
|
|||
|
||||
|
||||
class ExtScaleMark(AstNode):
|
||||
grammar = [
|
||||
grammar = Statement(
|
||||
Keyword("mark"),
|
||||
Match("(").expected(),
|
||||
[
|
||||
Optional(AnyOf(UseExact("sign", "-"), UseExact("sign", "+"))),
|
||||
UseNumber("value"),
|
||||
Optional(
|
||||
[
|
||||
",",
|
||||
UseIdent("position"),
|
||||
Optional([",", StringValue]),
|
||||
]
|
||||
),
|
||||
],
|
||||
Match(")").expected(),
|
||||
]
|
||||
Optional(AnyOf(UseExact("sign", "-"), UseExact("sign", "+"))),
|
||||
UseNumber("value").expected("value"),
|
||||
Optional(
|
||||
[
|
||||
",",
|
||||
UseIdent("position").expected("position"),
|
||||
Optional([",", to_parse_node(StringValue).expected("label")]),
|
||||
]
|
||||
),
|
||||
end=")",
|
||||
)
|
||||
|
||||
@property
|
||||
def value(self) -> float:
|
||||
|
@ -134,7 +132,7 @@ class ExtScaleMarks(AstNode):
|
|||
|
||||
@completer(
|
||||
applies_in=[ObjectContent],
|
||||
applies_in_subclass=("Gtk", "Scale"),
|
||||
applies_in_subclass=[("Gtk", "Scale")],
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def complete_marks(_ctx: CompletionContext):
|
||||
|
@ -153,6 +151,23 @@ def complete_mark(_ctx: CompletionContext):
|
|||
yield Completion("mark", CompletionItemKind.Keyword, snippet="mark ($0),")
|
||||
|
||||
|
||||
@completer(
|
||||
applies_in=[ExtScaleMark],
|
||||
matches=[[(TokenType.NUMBER, None), (TokenType.PUNCTUATION, ",")]],
|
||||
)
|
||||
def complete_mark_position(ctx: CompletionContext):
|
||||
gir = ctx.ast_node.root.gir
|
||||
response_type = gir.get_type("PositionType", "Gtk")
|
||||
yield from [
|
||||
Completion(
|
||||
name,
|
||||
kind=CompletionItemKind.EnumMember,
|
||||
docs=member.doc,
|
||||
)
|
||||
for name, member in response_type.members.items()
|
||||
]
|
||||
|
||||
|
||||
@decompiler("marks")
|
||||
def decompile_marks(
|
||||
ctx,
|
||||
|
|
|
@ -101,7 +101,7 @@ class ExtSizeGroupWidgets(AstNode):
|
|||
|
||||
@completer(
|
||||
applies_in=[ObjectContent],
|
||||
applies_in_subclass=("Gtk", "SizeGroup"),
|
||||
applies_in_subclass=[("Gtk", "SizeGroup")],
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def size_group_completer(_ctx: CompletionContext):
|
||||
|
|
|
@ -72,7 +72,7 @@ class ExtStringListStrings(AstNode):
|
|||
|
||||
@completer(
|
||||
applies_in=[ObjectContent],
|
||||
applies_in_subclass=("Gtk", "StringList"),
|
||||
applies_in_subclass=[("Gtk", "StringList")],
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def strings_completer(_ctx: CompletionContext):
|
||||
|
|
|
@ -77,7 +77,7 @@ class ExtStyles(AstNode):
|
|||
|
||||
@completer(
|
||||
applies_in=[ObjectContent],
|
||||
applies_in_subclass=("Gtk", "Widget"),
|
||||
applies_in_subclass=[("Gtk", "Widget")],
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def style_completer(_ctx: CompletionContext):
|
||||
|
|
|
@ -31,7 +31,12 @@ ALLOWED_PARENTS: T.List[T.Tuple[str, str]] = [
|
|||
|
||||
|
||||
class ChildInternal(AstNode):
|
||||
grammar = ["internal-child", UseIdent("internal_child")]
|
||||
grammar = [
|
||||
"[",
|
||||
"internal-child",
|
||||
UseIdent("internal_child").expected("internal child name"),
|
||||
Match("]").expected(),
|
||||
]
|
||||
|
||||
@property
|
||||
def internal_child(self) -> str:
|
||||
|
@ -39,7 +44,7 @@ class ChildInternal(AstNode):
|
|||
|
||||
|
||||
class ChildType(AstNode):
|
||||
grammar = UseIdent("child_type").expected("a child type")
|
||||
grammar = ["[", UseIdent("child_type").expected("a child type"), "]"]
|
||||
|
||||
@property
|
||||
def child_type(self) -> str:
|
||||
|
@ -59,7 +64,7 @@ class ChildExtension(AstNode):
|
|||
|
||||
|
||||
class ChildAnnotation(AstNode):
|
||||
grammar = ["[", AnyOf(ChildInternal, ChildExtension, ChildType), "]"]
|
||||
grammar = AnyOf(ChildInternal, ChildExtension, ChildType)
|
||||
|
||||
@property
|
||||
def child(self) -> T.Union[ChildInternal, ChildExtension, ChildType]:
|
||||
|
|
|
@ -28,19 +28,21 @@ class ExtResponse(AstNode):
|
|||
|
||||
ALLOWED_PARENTS: T.List[T.Tuple[str, str]] = [("Gtk", "Dialog"), ("Gtk", "InfoBar")]
|
||||
|
||||
grammar = [
|
||||
grammar = Statement(
|
||||
"[",
|
||||
Keyword("action"),
|
||||
Keyword("response"),
|
||||
"=",
|
||||
Match("=").expected(),
|
||||
AnyOf(
|
||||
UseIdent("response_id"),
|
||||
[
|
||||
Optional(UseExact("sign", "-")),
|
||||
UseNumber("response_id"),
|
||||
],
|
||||
),
|
||||
).expected("response ID"),
|
||||
Optional([Keyword("default"), UseLiteral("is_default", True)]),
|
||||
]
|
||||
end="]",
|
||||
)
|
||||
|
||||
@validate()
|
||||
def parent_has_action_widgets(self) -> None:
|
||||
|
|
|
@ -27,11 +27,11 @@ class TypeName(AstNode):
|
|||
[
|
||||
UseIdent("namespace"),
|
||||
".",
|
||||
UseIdent("class_name"),
|
||||
UseIdent("class_name").expected("class name"),
|
||||
],
|
||||
[
|
||||
AnyOf("$", [".", UseLiteral("old_extern", True)]),
|
||||
UseIdent("class_name"),
|
||||
UseIdent("class_name").expected("class name"),
|
||||
UseLiteral("extern", True),
|
||||
],
|
||||
UseIdent("class_name"),
|
||||
|
@ -47,7 +47,11 @@ class TypeName(AstNode):
|
|||
|
||||
@validate("class_name")
|
||||
def type_exists(self):
|
||||
if not self.tokens["extern"] and self.gir_ns is not None:
|
||||
if (
|
||||
not self.tokens["extern"]
|
||||
and self.gir_ns is not None
|
||||
and self.tokens["class_name"] is not None
|
||||
):
|
||||
self.root.gir.validate_type(
|
||||
self.tokens["class_name"], self.tokens["namespace"]
|
||||
)
|
||||
|
@ -182,3 +186,14 @@ class TemplateClassName(ClassName):
|
|||
self.root.gir.validate_type(
|
||||
self.tokens["class_name"], self.tokens["namespace"]
|
||||
)
|
||||
|
||||
|
||||
class BracketedTypeName(AstNode):
|
||||
grammar = Statement("<", to_parse_node(TypeName).expected("type name"), end=">")
|
||||
|
||||
@property
|
||||
def type_name(self) -> T.Optional[TypeName]:
|
||||
if len(self.children[TypeName]) == 0:
|
||||
return None
|
||||
|
||||
return self.children[TypeName][0]
|
||||
|
|
|
@ -26,7 +26,7 @@ from .common import *
|
|||
from .contexts import ExprValueCtx, ScopeCtx, ValueTypeCtx
|
||||
from .expression import Expression
|
||||
from .gobject_object import Object
|
||||
from .types import TypeName
|
||||
from .types import BracketedTypeName, TypeName
|
||||
|
||||
|
||||
class Translated(AstNode):
|
||||
|
@ -58,6 +58,19 @@ class Translated(AstNode):
|
|||
f"Cannot convert translated string to {expected_type.full_name}"
|
||||
)
|
||||
|
||||
@validate("context")
|
||||
def context_double_quoted(self):
|
||||
if self.translate_context is None:
|
||||
return
|
||||
|
||||
if not str(self.group.tokens["context"]).startswith('"'):
|
||||
raise CompileWarning("gettext may not recognize single-quoted strings")
|
||||
|
||||
@validate("string")
|
||||
def string_double_quoted(self):
|
||||
if not str(self.group.tokens["string"]).startswith('"'):
|
||||
raise CompileWarning("gettext may not recognize single-quoted strings")
|
||||
|
||||
@docs()
|
||||
def ref_docs(self):
|
||||
return get_docs_section("Syntax Translated")
|
||||
|
@ -67,11 +80,7 @@ class TypeLiteral(AstNode):
|
|||
grammar = [
|
||||
"typeof",
|
||||
AnyOf(
|
||||
[
|
||||
"<",
|
||||
to_parse_node(TypeName).expected("type name"),
|
||||
Match(">").expected(),
|
||||
],
|
||||
BracketedTypeName,
|
||||
[
|
||||
UseExact("lparen", "("),
|
||||
to_parse_node(TypeName).expected("type name"),
|
||||
|
@ -85,8 +94,13 @@ class TypeLiteral(AstNode):
|
|||
return gir.TypeType()
|
||||
|
||||
@property
|
||||
def type_name(self) -> TypeName:
|
||||
return self.children[TypeName][0]
|
||||
def type_name(self) -> T.Optional[TypeName]:
|
||||
if len(self.children[BracketedTypeName]) == 1:
|
||||
return self.children[BracketedTypeName][0].type_name
|
||||
elif len(self.children[TypeName]) == 1:
|
||||
return self.children[TypeName][0]
|
||||
else:
|
||||
return None
|
||||
|
||||
@validate()
|
||||
def validate_for_type(self) -> None:
|
||||
|
@ -212,12 +226,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
|
||||
|
||||
|
@ -325,7 +339,14 @@ class IdentLiteral(AstNode):
|
|||
raise CompileError(
|
||||
'"item" can only be used in an expression literal'
|
||||
)
|
||||
elif self.ident not in ["true", "false"]:
|
||||
elif self.ident in ["true", "false"]:
|
||||
if expected_type is not None and not isinstance(
|
||||
expected_type, gir.BoolType
|
||||
):
|
||||
raise CompileError(
|
||||
f"Cannot assign boolean to {expected_type.full_name}"
|
||||
)
|
||||
else:
|
||||
raise CompileError(
|
||||
f"Could not find object with ID {self.ident}",
|
||||
did_you_mean=(
|
||||
|
|
|
@ -209,6 +209,7 @@ class XmlOutput(OutputFormat):
|
|||
else:
|
||||
xml.put_text(self._object_id(value, value.ident))
|
||||
elif isinstance(value, TypeLiteral):
|
||||
assert value.type_name is not None
|
||||
xml.put_text(value.type_name.glib_type_name)
|
||||
else:
|
||||
if isinstance(value.value, float) and value.value == int(value.value):
|
||||
|
@ -308,6 +309,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
|
||||
|
@ -235,7 +235,15 @@ class ParseNode:
|
|||
start_idx = ctx.index
|
||||
inner_ctx = ctx.create_child()
|
||||
|
||||
if self._parse(inner_ctx):
|
||||
try:
|
||||
result = self._parse(inner_ctx)
|
||||
except Exception as e:
|
||||
# If an exception occurs, there's an explicit error, not just a rule that didn't match. Apply the context
|
||||
# state so that whichever rule handles the exception (e.g. a Statement) knows where the error occurred.
|
||||
ctx.apply_child(inner_ctx)
|
||||
raise e
|
||||
|
||||
if result:
|
||||
ctx.apply_child(inner_ctx)
|
||||
if ctx.index == start_idx:
|
||||
return ParseResult.EMPTY
|
||||
|
@ -269,12 +277,12 @@ class Err(ParseNode):
|
|||
if self.child.parse(ctx).failed():
|
||||
start_idx = ctx.start
|
||||
while ctx.tokens[start_idx].type in SKIP_TOKENS:
|
||||
start_idx += 1
|
||||
start_idx -= 1
|
||||
start_token = ctx.tokens[start_idx]
|
||||
|
||||
raise CompileError(
|
||||
self.message, Range(start_token.start, start_token.start, ctx.text)
|
||||
)
|
||||
position = start_token.start if ctx.start == start_idx else start_token.end
|
||||
|
||||
raise CompileError(self.message, Range(position, position, ctx.text))
|
||||
return True
|
||||
|
||||
|
||||
|
@ -329,8 +337,9 @@ class Statement(ParseNode):
|
|||
"""ParseNode that attempts to match all of its children in sequence. If any
|
||||
child raises an error, the error will be logged but parsing will continue."""
|
||||
|
||||
def __init__(self, *children):
|
||||
def __init__(self, *children, end: str = ";"):
|
||||
self.children = [to_parse_node(child) for child in children]
|
||||
self.end = end
|
||||
|
||||
def _parse(self, ctx) -> bool:
|
||||
for child in self.children:
|
||||
|
@ -340,11 +349,29 @@ class Statement(ParseNode):
|
|||
except CompileError as e:
|
||||
ctx.errors.append(e)
|
||||
ctx.set_group_incomplete()
|
||||
|
||||
token = ctx.peek_token()
|
||||
if str(token) == self.end:
|
||||
ctx.next_token()
|
||||
|
||||
return True
|
||||
|
||||
token = ctx.peek_token()
|
||||
if str(token) != ";":
|
||||
ctx.errors.append(CompileError("Expected `;`", token.range))
|
||||
if str(token) != self.end:
|
||||
start_idx = ctx.index - 1
|
||||
while ctx.tokens[start_idx].type in SKIP_TOKENS:
|
||||
start_idx -= 1
|
||||
start_token = ctx.tokens[start_idx]
|
||||
|
||||
position = (
|
||||
start_token.start if ctx.index - 1 == start_idx else start_token.end
|
||||
)
|
||||
|
||||
ctx.errors.append(
|
||||
CompileError(
|
||||
f"Expected `{self.end}`", Range(position, position, ctx.text)
|
||||
)
|
||||
)
|
||||
else:
|
||||
ctx.next_token()
|
||||
return True
|
||||
|
@ -405,7 +432,6 @@ class Until(ParseNode):
|
|||
ctx.skip_unexpected_token()
|
||||
except CompileError as e:
|
||||
ctx.errors.append(e)
|
||||
ctx.next_token()
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
@ -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,8 +16,8 @@ a module in your flatpak manifest:
|
|||
"sources": [
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://gitlab.gnome.org/jwestman/blueprint-compiler",
|
||||
"tag": "v0.14.0"
|
||||
"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
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ If you're using Meson's `i18n module <https://mesonbuild.com/i18n-module.html#i1
|
|||
|
||||
i18n.gettext('package name', preset: 'glib')
|
||||
|
||||
You must use double quotes for the translated strings in order for gettext to recognize them. Newer versions of blueprint will warn you if you use single quotes.
|
||||
|
||||
Contexts
|
||||
--------
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
project('blueprint-compiler',
|
||||
version: '0.14.0',
|
||||
version: '0.16.0',
|
||||
)
|
||||
|
||||
prefix = get_option('prefix')
|
||||
|
|
|
@ -1 +1 @@
|
|||
4,6,22,Action widget must have ID
|
||||
4,5,24,Action widget must have ID
|
||||
|
|
|
@ -1 +1 @@
|
|||
4,6,18,Gtk.Box doesn't have action widgets
|
||||
4,5,20,Gtk.Box doesn't have action widgets
|
||||
|
|
5
tests/sample_errors/convert_bool_to_obj.blp
Normal file
5
tests/sample_errors/convert_bool_to_obj.blp
Normal file
|
@ -0,0 +1,5 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Button {
|
||||
child: false;
|
||||
}
|
1
tests/sample_errors/convert_bool_to_obj.err
Normal file
1
tests/sample_errors/convert_bool_to_obj.err
Normal file
|
@ -0,0 +1 @@
|
|||
4,10,5,Cannot assign boolean to Gtk.Widget
|
|
@ -1 +1 @@
|
|||
1,0,0,File must start with a "using Gtk" directive (e.g. `using Gtk 4.0;`)
|
||||
1,1,0,File must start with a "using Gtk" directive (e.g. `using Gtk 4.0;`)
|
|
@ -1 +1 @@
|
|||
6,1,1,Expected `;`
|
||||
5,4,0,Expected `;`
|
|
@ -1,2 +1 @@
|
|||
5,1,0,Expected a signal detail name
|
||||
4,9,3,Unexpected tokens
|
||||
4,11,0,Expected a signal detail name
|
|
@ -1,2 +1 @@
|
|||
4,5,21,Attributes are not permitted at the top level of a menu
|
||||
4,16,10,Unexpected tokens
|
||||
4,5,21,Attributes are not permitted at the top level of a menu
|
|
@ -1 +1 @@
|
|||
1,11,0,Expected a version number for GTK
|
||||
1,10,0,Expected a version number for GTK
|
||||
|
|
5
tests/sample_errors/single_quoted_translated.blp
Normal file
5
tests/sample_errors/single_quoted_translated.blp
Normal file
|
@ -0,0 +1,5 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Label {
|
||||
label: _('Hello, World!');
|
||||
}
|
1
tests/sample_errors/single_quoted_translated.err
Normal file
1
tests/sample_errors/single_quoted_translated.err
Normal file
|
@ -0,0 +1 @@
|
|||
4,12,15,gettext may not recognize single-quoted strings
|
|
@ -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>
|
|
@ -143,9 +143,9 @@ class TestSamples(unittest.TestCase):
|
|||
]
|
||||
|
||||
def error_str(error: CompileError):
|
||||
line, col = utils.idx_to_pos(error.range.start + 1, blueprint)
|
||||
line, col = utils.idx_to_pos(error.range.start, blueprint)
|
||||
len = error.range.length
|
||||
return ",".join([str(line + 1), str(col), str(len), error.message])
|
||||
return ",".join([str(line + 1), str(col + 1), str(len), error.message])
|
||||
|
||||
actual = "\n".join([error_str(error) for error in errors])
|
||||
|
||||
|
@ -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