This commit is contained in:
Михаил Капелько
2024-04-25 22:49:22 +03:00
parent fc82f332ed
commit 5fe21fe872
4 changed files with 22 additions and 12 deletions

View File

@@ -10,12 +10,15 @@ def includes():
def replaceAnd(s):
return s.replace("and", "&&")
def replaceAppend(s):
return s.replace(".append(", ".push_back(")
def replaceComment(s):
return s.replace("#", "//")
def replaceLen(s):
posLen = s.find("len(")
posEnd = s.find(")")
posEnd = s.find(")", posLen)
if (
posLen == -1 or
posEnd == -1
@@ -26,6 +29,9 @@ def replaceLen(s):
after = s[posEnd + len(")"):]
return f"{before}{name}.size(){after}"
def replaceTrue(s):
return s.replace("True", "true")
def translateParameter(s):
# name: type -> type name
parts = s.split(": ")
@@ -147,7 +153,11 @@ class CPP:
for i in range(0, len(self.fn.statements)):
s = translateStatement(self.fn.statements[i], self)
s = replaceAnd(s)
s = replaceAppend(s)
# Replace len twice to account for double invocation.
s = replaceLen(s)
s = replaceLen(s)
s = replaceTrue(s)
sts.append(s)
strstatements = "\n".join(sts)