Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #527 from Jaseci-Labs/comment_format_bug
Browse files Browse the repository at this point in the history
test: comment file needs fixing
  • Loading branch information
marsninja authored Jul 30, 2024
2 parents 67857c8 + b4b48bd commit b51ef88
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion jaclang/compiler/passes/tool/jac_formatter_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def indent_str(self) -> str:

def emit(self, node: ast.AstNode, s: str, strip_mode: bool = True) -> None:
"""Emit code to node."""
node.gen.jac += self.indent_str() + s.replace("\n", "\n" + self.indent_str())
indented_str = re.sub(r"\n(?!\n)", f"\n{self.indent_str()}", s)
node.gen.jac += self.indent_str() + indented_str
if "\n" in node.gen.jac:
if strip_mode:
node.gen.jac = node.gen.jac.rstrip(" ")
Expand Down Expand Up @@ -1098,6 +1099,9 @@ def exit_expr_stmt(self, node: ast.ExprStmt) -> None:
if isinstance(i, ast.CommentToken):
if i.is_inline:
self.emit(node, f" {i.gen.jac}")
elif (tok := self.token_before(i)) and (i.line_no - tok.line_no == 1):
self.emit_ln(node, "")
self.emit(node, i.gen.jac)
else:
self.emit_ln(node, "")
self.emit_ln(node, "")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
with entry:__main__ {
app = App();
app.run();
# ray.init_window(800, 450, "Hello");
# while not ray.window_should_close() {
# ray.begin_drawing();
# ray.clear_background(ray.WHITE);
# ray.draw_text("Hello world", 190, 200, 20, ray.VIOLET);
# ray.end_drawing();
# }

# ray.close_window();
}

0 comments on commit b51ef88

Please sign in to comment.