diff --git a/jaclang/compiler/passes/tool/jac_formatter_pass.py b/jaclang/compiler/passes/tool/jac_formatter_pass.py index fe32ed102..5cfd58970 100644 --- a/jaclang/compiler/passes/tool/jac_formatter_pass.py +++ b/jaclang/compiler/passes/tool/jac_formatter_pass.py @@ -2458,7 +2458,11 @@ def exit_string(self, node: ast.String) -> None: pos_end: int, """ # if string is in docstring format and spans multiple lines turn into the multiple single quoted strings - if "\n" in node.value and node.parent and isinstance(node.parent, ast.Expr): + if "\n" in node.value and ( + node.parent + and isinstance(node.parent, ast.Expr) + and not isinstance(node.parent, ast.MultiString) + ): string_type = node.value[0:3] pure_string = node.value[3:-3] lines = pure_string.split("\n") @@ -2476,10 +2480,10 @@ def exit_string(self, node: ast.String) -> None: string_type = node.value[0:3] pure_string = node.value[3:-3] lines = pure_string.split("\n") - self.emit(node, string_type) - for line in lines[:-1]: - self.emit_ln(node, line) - self.emit_ln(node, f"{lines[-1]}{string_type}") + self.emit_ln(node, f"{string_type}{lines[0].lstrip()}") + for line in lines[1:-1]: + self.emit_ln(node, line.lstrip()) + self.emit(node, f"{lines[-1].lstrip()}{string_type}") else: self.emit(node, node.value) diff --git a/jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac b/jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac new file mode 100644 index 000000000..13e963519 --- /dev/null +++ b/jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac @@ -0,0 +1,6 @@ +with entry { + triple_quoted_string = """This is a triple quoted string. + It can span multiple lines. + It can contain any number of quotes or apostrophes. + """; +} diff --git a/jaclang/tests/fixtures/chandra_bugs2.jac b/jaclang/tests/fixtures/chandra_bugs2.jac index ee2f2fda0..81a652e77 100644 --- a/jaclang/tests/fixtures/chandra_bugs2.jac +++ b/jaclang/tests/fixtures/chandra_bugs2.jac @@ -1,10 +1,13 @@ import:py re; -glob a: int=5; +glob a: int = 5; with entry { - arguments = {x:None for x in re.findall(r'\{([A-Za-z0-9_]+)\}', "Apple {apple} pineapple {pineapple}")}; - a: int=5; + arguments = {x: None for x in re.findall( + r'\{([A-Za-z0-9_]+)\}', + "Apple {apple} pineapple {pineapple}" + )}; + a: int = 5; if False { with open(f"Apple{apple}.txt") as f { # Fix syntax highlighting @@ -12,15 +15,13 @@ with entry { } } print(arguments); - print( - """This is a long - line of code.""" - ); + print("""This is a long + line of code."""); } -with entry{ - a={"a":"apple", "b":"ball", "c":"cat"}; - y={**a, "d":"dog", "e":"elephant"}; +with entry { + a = {"a": "apple", "b": "ball", "c": "cat"}; + y = {**a, "d": "dog", "e": "elephant"}; print(y); } # Use before def error would be nice diff --git a/jaclang/tests/test_language.py b/jaclang/tests/test_language.py index 10b3b1883..3be22663e 100644 --- a/jaclang/tests/test_language.py +++ b/jaclang/tests/test_language.py @@ -107,7 +107,7 @@ def test_chandra_bugs2(self) -> None: stdout_value, "{'apple': None, 'pineapple': None}\n" "This is a long\n" - " line of code.\n" + " line of code.\n" "{'a': 'apple', 'b': 'ball', 'c': 'cat', 'd': 'dog', 'e': 'elephant'}\n", )