This commit is contained in:
Михаил Капелько
2023-06-09 20:11:31 +03:00
parent 68b366065a
commit 0966feb3f8
8 changed files with 62 additions and 18 deletions

23
toSwift
View File

@@ -15,6 +15,7 @@ let globalReplacements = {
"number": "Float",
"):": ") ->",
"interface": "protocol",
"})": "}", // forEach
};
console.log(`Converting '${fileSrc}' to '${fileDst}'`);
@@ -40,11 +41,31 @@ function convert(line) {
}
result = protocolReplace(result);
result = typeArrayReplace(result);
result = forEachReplace(result);
return result;
}
var isProtocol = false;
// x.forEach(y => { -> x.forEach { y in
function forEachReplace(line) {
if (!line.includes("forEach")) {
return line;
}
let partsFE = line.split("forEach");
let identifier = partsFE[0];
let closure = partsFE[1];
let partsC = closure.split(" => ");
let bracketAndVar = partsC[0];
let bracket = partsC[1];
let variable = bracketAndVar.substring(1);
let result = `${identifier}forEach { ${variable} in`;
return result;
}
var isProtocol = false;
// interface -> protocol
function protocolReplace(line) {
if (line.includes("protocol")) {