From 7e3d7944d6716721a3ac4a7902e20bb8f0473efd Mon Sep 17 00:00:00 2001 From: Ashish Mahendra Date: Wed, 11 Sep 2024 15:41:54 +0000 Subject: [PATCH 1/2] Fix: Comment placement with LBrace --- jac/jaclang/compiler/passes/tool/jac_formatter_pass.py | 8 ++++++++ .../tests/fixtures/general_format_checks/line_spacing.jac | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/jac/jaclang/compiler/passes/tool/jac_formatter_pass.py b/jac/jaclang/compiler/passes/tool/jac_formatter_pass.py index 31b71a092a..2432709e5c 100644 --- a/jac/jaclang/compiler/passes/tool/jac_formatter_pass.py +++ b/jac/jaclang/compiler/passes/tool/jac_formatter_pass.py @@ -282,6 +282,14 @@ def exit_sub_node_list(self, node: ast.SubNodeList) -> None: if prev_token and isinstance(prev_token, ast.Ability): self.emit(node, f"{stmt.gen.jac}") else: + token_before = self.token_before(stmt) + if ( + token_before is not None + and isinstance(token_before, ast.Token) + and token_before.name == Tok.LBRACE + and stmt.loc.first_line - token_before.loc.last_line > 1 + ): + self.emit_ln(node, "") self.emit(node, stmt.gen.jac) self.indent_level -= 1 self.emit_ln(stmt, "") diff --git a/jac/jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/line_spacing.jac b/jac/jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/line_spacing.jac index 46a54c3815..e04376b29a 100644 --- a/jac/jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/line_spacing.jac +++ b/jac/jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/line_spacing.jac @@ -1,9 +1,11 @@ import:py math; glob RAD = 5; + glob DIA = 10; # this comment is for walker + walker decorator_walk { can hash(func: Any) { can inner(a: Any) { @@ -39,6 +41,7 @@ walker decorator_walk { # Entry point for the walker can start with entry { + # Apply decorators to greeter decorated_greeter = hash(exclaim(tilde(greeter))); @@ -46,7 +49,6 @@ walker decorator_walk { decorated_greeter("World"); # this is another comment - } } From ab0d17884947f018cbdbd22131d355032855c40d Mon Sep 17 00:00:00 2001 From: Ashish Mahendra Date: Wed, 11 Sep 2024 15:53:27 +0000 Subject: [PATCH 2/2] Triming trailing space --- jac/jaclang/compiler/passes/tool/jac_formatter_pass.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jac/jaclang/compiler/passes/tool/jac_formatter_pass.py b/jac/jaclang/compiler/passes/tool/jac_formatter_pass.py index 2432709e5c..578c8778a2 100644 --- a/jac/jaclang/compiler/passes/tool/jac_formatter_pass.py +++ b/jac/jaclang/compiler/passes/tool/jac_formatter_pass.py @@ -289,7 +289,9 @@ def exit_sub_node_list(self, node: ast.SubNodeList) -> None: and token_before.name == Tok.LBRACE and stmt.loc.first_line - token_before.loc.last_line > 1 ): + self.indent_level -= 1 self.emit_ln(node, "") + self.indent_level += 1 self.emit(node, stmt.gen.jac) self.indent_level -= 1 self.emit_ln(stmt, "")