🐐 Escape sequences

This commit is contained in:
2026-04-22 11:27:19 +02:00
parent 8c69a300a5
commit 940f8d7311
4 changed files with 109 additions and 5 deletions

View File

@@ -343,10 +343,15 @@ class String(Node):
return f"String({self.value})"
def print(self):
v = (self.value
.replace('\\', '\\\\')
.replace('\n', '\\n')
.replace('\t', '\\t')
.replace('\r', '\\r'))
if self.quote == "'":
return f"'{self.value}'"
escaped = self.value.replace('{', '{{').replace('}', '}}')
return f'"{escaped}"'
return f"'{v}'"
v = v.replace('"', '\\"').replace('{', '{{').replace('}', '}}')
return f'"{v}"'
def _eval(self, vtable):
return vtable, ValStr(self.value)