Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Comment placement with LBrace #1269

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions jac/jaclang/compiler/passes/tool/jac_formatter_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ 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.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, "")
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -39,14 +41,14 @@ walker decorator_walk {
# Entry point for the walker

can start with entry {

# Apply decorators to greeter
decorated_greeter = hash(exclaim(tilde(greeter)));

# Call the decorated greeter function
decorated_greeter("World");

# this is another comment

}
}

Expand Down
Loading