@abaplint/runtime
Version:
Transpiler - Runtime
84 lines • 3.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.expandDynamic = expandDynamic;
const expand_in_1 = require("./expand_in");
const types_1 = require("./types");
function expandDynamic(input, evaluate) {
// console.dir(code);
let code;
if (input instanceof types_1.Table || input instanceof types_1.HashedTable) {
code = input.array().map(row => row.get()).join(" ");
}
else if (typeof input === "string") {
code = input;
}
else {
code = input.get();
}
if (code === "") {
return "1 = 1";
}
else {
// yea, this is also wrong,
code = code.replace(/ EQ /g, " = ");
// todo more here, this is just one simple case,
let regex = /(\w+) IN @?<(\w+)>-(\w+)/;
while (true) {
const match = code.match(regex);
if (match && match[1] && match[2] && match[3]) {
let name = "fs_" + match[2] + "_";
name = name.toLowerCase();
let found = evaluate(name);
if (found instanceof types_1.FieldSymbol) {
found = found.get()[match[3].toLowerCase()];
if (found === undefined) {
throw new Error(`expandDynamic: Field symbol ${name} does not have field ${match[2]}`);
}
code = code.replace(regex, (0, expand_in_1.expandIN)(match[1].toLowerCase(), found));
}
}
else {
break;
}
}
// todo more here, this is just one simple case,
regex = / @?<(\w+)>-(\w+)/;
while (true) {
const match = code.match(regex);
if (match && match[1] && match[2]) {
let name = "fs_" + match[1] + "_";
name = name.toLowerCase();
let found = evaluate(name);
if (found instanceof types_1.FieldSymbol) {
found = found.get()[match[2].toLowerCase()];
if (found === undefined) {
throw new Error(`expandDynamic: Field symbol ${name} does not have field ${match[2]}`);
}
code = code.replace(regex, " '" + found.get() + "'");
}
}
else {
break;
}
}
// todo more here, this is just one simple case,
regex = / @?<(\w+)>/;
while (true) {
const match = code.match(regex);
if (match && match[1]) {
let name = "fs_" + match[1] + "_";
name = name.toLowerCase();
const found = evaluate(name);
if (found instanceof types_1.FieldSymbol) {
code = code.replace(regex, " '" + found.get() + "'");
}
}
else {
break;
}
}
// console.dir(code);
return code;
}
}
//# sourceMappingURL=expand_dynamic.js.map