diff --git a/coconut/compiler/compiler.py b/coconut/compiler/compiler.py index 9b555b5f..5a921e57 100644 --- a/coconut/compiler/compiler.py +++ b/coconut/compiler/compiler.py @@ -1512,10 +1512,7 @@ def str_proc(self, inputstring, **kwargs): # if we might be at the end of the string elif hold["stop"] is not None: - if c == "\\": - self.str_hold_contents(hold, append=hold["stop"] + c) - hold["stop"] = None - elif c == hold["start"][0]: + if c == hold["start"][0]: hold["stop"] += c elif len(hold["stop"]) > len(hold["start"]): raise self.make_err(CoconutSyntaxError, "invalid number of closing " + repr(hold["start"][0]) + "s", inputstring, i, reformat=False) @@ -1523,8 +1520,9 @@ def str_proc(self, inputstring, **kwargs): done = True rerun = True else: - self.str_hold_contents(hold, append=hold["stop"] + c) + self.str_hold_contents(hold, append=hold["stop"]) hold["stop"] = None + rerun = True # if we might be at the start of an f string expr elif hold.get("saw_brace", False): @@ -1539,15 +1537,16 @@ def str_proc(self, inputstring, **kwargs): hold["exprs"].append("") rerun = True + elif is_f and c == "{": + hold["saw_brace"] = True + self.str_hold_contents(hold, append=c) + # backslashes should escape quotes, but nothing else elif count_end(self.str_hold_contents(hold), "\\") % 2 == 1: self.str_hold_contents(hold, append=c) elif c == hold["start"]: done = True elif c == hold["start"][0]: hold["stop"] = c - elif is_f and c == "{": - hold["saw_brace"] = True - self.str_hold_contents(hold, append=c) else: self.str_hold_contents(hold, append=c) diff --git a/coconut/root.py b/coconut/root.py index dbb23838..3b7a1c2e 100644 --- a/coconut/root.py +++ b/coconut/root.py @@ -26,7 +26,7 @@ VERSION = "3.1.0" VERSION_NAME = None # False for release, int >= 1 for develop -DEVELOP = 14 +DEVELOP = 15 ALPHA = False # for pre releases rather than post releases assert DEVELOP is False or DEVELOP >= 1, "DEVELOP must be False or an int >= 1" diff --git a/coconut/tests/src/cocotest/agnostic/primary_2.coco b/coconut/tests/src/cocotest/agnostic/primary_2.coco index 0ad26de4..be581e69 100644 --- a/coconut/tests/src/cocotest/agnostic/primary_2.coco +++ b/coconut/tests/src/cocotest/agnostic/primary_2.coco @@ -461,6 +461,10 @@ def primary_test_2() -> bool: assert CoconutWarning `issubclass` Warning x = y = 2 assert f"{x + y = }" == "x + y = 4" + assert f""" +"{x}" +""" == '\n"2"\n' + assert f"\{1}" == "\\1" with process_map.multiple_sequential_calls(): # type: ignore assert map((+), range(3), range(4)$[:-1], strict=True) |> list == [0, 2, 4] == process_map((+), range(3), range(4)$[:-1], strict=True) |> list # type: ignore diff --git a/coconut/tests/src/cocotest/non_strict/non_strict_test.coco b/coconut/tests/src/cocotest/non_strict/non_strict_test.coco index 329a9e62..5338ea7e 100644 --- a/coconut/tests/src/cocotest/non_strict/non_strict_test.coco +++ b/coconut/tests/src/cocotest/non_strict/non_strict_test.coco @@ -113,6 +113,8 @@ def non_strict_test() -> bool: assert value == "123" "{" f"{key}" ": " + value + "}" = "{abc: aaa}" assert value == "aaa" + assert """ """\ + == " " return True if __name__ == "__main__":