diff --git a/blueprintcompiler/decompiler.py b/blueprintcompiler/decompiler.py index 850b6d8..072aa89 100644 --- a/blueprintcompiler/decompiler.py +++ b/blueprintcompiler/decompiler.py @@ -375,7 +375,7 @@ def decompile_translatable( comments = "" else: comments = comments.replace("/*", " ").replace("*/", " ") - comments = f"/* Translators: {comments} */" + comments = f"\n/* Translators: {comments} */" if context is not None: return comments, f"C_({escape_quote(context)}, {escape_quote(string)})" diff --git a/blueprintcompiler/formatter.py b/blueprintcompiler/formatter.py index f438675..aebcace 100644 --- a/blueprintcompiler/formatter.py +++ b/blueprintcompiler/formatter.py @@ -179,24 +179,26 @@ def format(data, tab_size=2, insert_space=True): ) single_line_comment = str_item.startswith("//") + if single_line_comment and not str_item.startswith("// "): + current_line = f"// {current_line[2:]}" + + inline_comment = not last_whitespace_contains_newline + line_type = LineType.COMMENT newlines = 1 - if single_line_comment: - if not str_item.startswith("// "): - current_line = f"// {current_line[2:]}" - - if not last_whitespace_contains_newline: - current_line = " " + current_line - newlines = 0 - elif prev_line_type == LineType.BLOCK_CLOSE: + if inline_comment: + current_line = " " + current_line + line_type = prev_line_type + newlines = 0 + elif single_line_comment: + if prev_line_type == LineType.BLOCK_CLOSE: newlines = 2 - elif prev_line_type in require_extra_newline: newlines = 2 current_line = "\n".join( [line.rstrip() for line in current_line.split("\n")] ) - commit_current_line(LineType.COMMENT, newlines_before=newlines) + commit_current_line(line_type, newlines_before=newlines) else: # pragma: no cover raise CompilerBugError() diff --git a/blueprintcompiler/language/gtk_scale.py b/blueprintcompiler/language/gtk_scale.py index 1fd5ac3..77166b8 100644 --- a/blueprintcompiler/language/gtk_scale.py +++ b/blueprintcompiler/language/gtk_scale.py @@ -167,8 +167,11 @@ def decompile_mark( comments=None, context=None, ): + comments, translatable = decompile_translatable( + cdata, translatable, context, comments + ) if comments is not None: - ctx.print(f"/* Translators: {comments} */") + ctx.print(comments) text = f"mark ({value}" @@ -177,10 +180,7 @@ def decompile_mark( elif cdata: text += f", bottom" - if truthy(translatable): - comments, translatable = decompile_translatable( - cdata, translatable, context, comments - ) + if cdata: text += f", {translatable}" text += ")," diff --git a/tests/formatting/correct1.blp b/tests/formatting/correct1.blp index aedc38a..56286b4 100644 --- a/tests/formatting/correct1.blp +++ b/tests/formatting/correct1.blp @@ -46,7 +46,7 @@ menu menu { item ("test") item { - label: "test"; + label: "test"; /* Different inline comment style */ } item ("test") @@ -59,7 +59,7 @@ Adw.MessageDialog { } Adw.Breakpoint { - condition ("width < 100") + condition ("width < 100") // Another inline comment setters { label2.label: _("Hello, world!"); diff --git a/tests/samples/scale_marks.blp b/tests/samples/scale_marks.blp index a766cfa..7b0c573 100644 --- a/tests/samples/scale_marks.blp +++ b/tests/samples/scale_marks.blp @@ -4,6 +4,7 @@ Scale { marks [ mark (-1, bottom), mark (0, top, _("Hello, world!")), + mark (1, bottom, "1"), mark (2), ] } diff --git a/tests/samples/scale_marks.ui b/tests/samples/scale_marks.ui index c08afb4..f50443a 100644 --- a/tests/samples/scale_marks.ui +++ b/tests/samples/scale_marks.ui @@ -10,6 +10,7 @@ corresponding .blp file and regenerate this file with blueprint-compiler. Hello, world! + 1