This commit is contained in:
Михаил Капелько
2023-06-08 20:00:04 +03:00
parent e79ea66ad4
commit 1bc0a11aeb
8 changed files with 86 additions and 42 deletions

23
toSwift
View File

@@ -39,6 +39,7 @@ function convert(line) {
result = result.replace(src, dst);
}
result = protocolReplace(result);
result = typeArrayReplace(result);
return result;
}
@@ -51,7 +52,6 @@ function protocolReplace(line) {
if (line == "}") {
isProtocol = false;
}
console.log("ИГР protocolR-1 isP/line:", isProtocol, line);
if (!isProtocol) {
return line;
}
@@ -60,7 +60,6 @@ function protocolReplace(line) {
if (isProtocol) {
result = protocolReplaceVariable(result);
}
console.log("ИГР protocolR-2 isP/line:", isProtocol, line);
return result;
}
@@ -71,8 +70,26 @@ function protocolReplaceVariable(line) {
let name = parts[0].trim();
let spaceLength = parts[0].length - name.length;
let spaces = " ".repeat(spaceLength);
//console.log("Variable. name/spaceL/parts:", name, spaceLength, parts);
return `${spaces}var ${name}: ${type} { get }`;
}
return line;
}
// func memoryItemPositions(c: Context) -> Position[] {
// var pos: Position[] = []
function typeArrayReplace(line) {
let parts = line.split(" ");
for (var i in parts) {
let part = parts[i];
if (
part != "[]" &&
part.endsWith("[]")
) {
let type = part.substring(0, part.length - 2)
let swiftType = `[${type}]`;
return line.replace(part, swiftType);
}
}
return line;
}