|
|
@@ -10,10 +10,11 @@ var fs = require("fs"); |
|
|
|
let fileSrc = process.argv[2]; |
|
|
|
let fileDst = process.argv[3]; |
|
|
|
|
|
|
|
let replacements = { |
|
|
|
let globalReplacements = { |
|
|
|
"function": "func", |
|
|
|
"number": "Float", |
|
|
|
"):": ") ->", |
|
|
|
"interface": "protocol", |
|
|
|
}; |
|
|
|
|
|
|
|
console.log(`Converting '${fileSrc}' to '${fileDst}'`); |
|
|
@@ -33,9 +34,44 @@ fs.writeFileSync(fileDst, contentsDst); |
|
|
|
|
|
|
|
function convert(line) { |
|
|
|
var result = line; |
|
|
|
for (let src in replacements) { |
|
|
|
let dst = replacements[src]; |
|
|
|
for (let src in globalReplacements) { |
|
|
|
let dst = globalReplacements[src]; |
|
|
|
result = result.replace(src, dst); |
|
|
|
} |
|
|
|
result = protocolReplace(result); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
var isProtocol = false; |
|
|
|
|
|
|
|
function protocolReplace(line) { |
|
|
|
if (line.includes("protocol")) { |
|
|
|
isProtocol = true; |
|
|
|
} |
|
|
|
if (line == "}") { |
|
|
|
isProtocol = false; |
|
|
|
} |
|
|
|
console.log("ИГР protocolR isP/line:", isProtocol, line); |
|
|
|
if (!isProtocol) { |
|
|
|
return line; |
|
|
|
} |
|
|
|
|
|
|
|
var result = line; |
|
|
|
if (isProtocol) { |
|
|
|
result = protocolReplaceVariable(result); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
function protocolReplaceVariable(line) { |
|
|
|
let parts = line.split(": "); |
|
|
|
if (parts.length == 2) { |
|
|
|
let type = parts[1]; |
|
|
|
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 }\n`; |
|
|
|
} |
|
|
|
return line; |
|
|
|
} |