Skip to content

Commit d40a9f1

Browse files
committed
Parse mutiline strings according to python rules, not Kotlin rules.
1 parent 098bcc0 commit d40a9f1

File tree

2 files changed

+7
-24
lines changed

2 files changed

+7
-24
lines changed

python/selfie-lib/selfie_lib/Literals.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -212,27 +212,10 @@ def _unescape_python(self, source: str) -> str:
212212
return value.getvalue()
213213

214214
def parseMultiPython(self, source_with_quotes: str) -> str:
215-
assert source_with_quotes.startswith(TRIPLE_QUOTE + "\n")
215+
assert source_with_quotes.startswith(TRIPLE_QUOTE)
216216
assert source_with_quotes.endswith(TRIPLE_QUOTE)
217-
218-
source = source_with_quotes[len(TRIPLE_QUOTE) + 1 : -len(TRIPLE_QUOTE)]
219-
lines = source.split("\n")
220-
221-
common_prefix = min(
222-
(line[: len(line) - len(line.lstrip())] for line in lines if line.strip()),
223-
default="",
224-
)
225-
226-
def remove_common_prefix(line: str) -> str:
227-
return line[len(common_prefix) :] if common_prefix else line
228-
229-
def handle_escape_sequences(line: str) -> str:
230-
return self._unescape_python(line.rstrip())
231-
232-
return "\n".join(
233-
handle_escape_sequences(remove_common_prefix(line))
234-
for line in lines
235-
if line.strip()
217+
return self._unescape_python(
218+
source_with_quotes[len(TRIPLE_QUOTE) : -len(TRIPLE_QUOTE)]
236219
)
237220

238221

python/selfie-lib/tests/LiteralString_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ def test_parse_single(self, value, expected):
5050
@pytest.mark.parametrize(
5151
("value", "expected"),
5252
[
53-
("\n123\nabc", "123\nabc"),
54-
("\n 123\n abc", "123\nabc"),
55-
("\n 123 \n abc\t", "123\nabc"),
56-
("\n 123 \\s\n abc\t\\s", "123 \nabc\t "),
53+
("\n123\nabc", "\n123\nabc"),
54+
("\n 123\n abc", "\n 123\n abc"),
55+
("\n 123 \n abc\t", "\n 123 \n abc\t"),
56+
(" 123 \n abc\t", " 123 \n abc\t"),
5757
],
5858
)
5959
def test_parse_multi(self, value, expected):

0 commit comments

Comments
 (0)