UNPKG

@abaplint/transpiler

Version:
60 lines 3.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReplaceTranspiler = void 0; const abaplint = require("@abaplint/core"); const expressions_1 = require("../expressions"); const chunk_1 = require("../chunk"); class ReplaceTranspiler { transpile(node, traversal) { const sources = node.findDirectExpressions(abaplint.Expressions.Source); const target = traversal.traverse(node.findDirectExpression(abaplint.Expressions.Target)).getCode(); const concat = node.concatTokens().toUpperCase(); const all = concat.startsWith("REPLACE ALL"); const extra = []; const w = node.findExpressionAfterToken("WITH"); if (w) { extra.push("with: " + new expressions_1.SourceTranspiler().transpile(w, traversal).getCode()); } const o = node.findExpressionAfterToken("OF"); if (o && o.get() instanceof abaplint.Expressions.Source) { extra.push("of: " + new expressions_1.SourceTranspiler().transpile(o, traversal).getCode()); } const cnt = node.findExpressionAfterToken("COUNT"); if (cnt) { extra.push("replacementCount: " + new expressions_1.TargetTranspiler().transpile(cnt, traversal).getCode()); } const length = node.findExpressionAfterToken("LENGTH"); if (length) { if (length.get() instanceof abaplint.Expressions.Source) { extra.push("sectionLength: " + new expressions_1.SourceTranspiler().transpile(length, traversal).getCode()); } else if (length.get() instanceof abaplint.Expressions.Target) { extra.push("replacementLength: " + new expressions_1.TargetTranspiler().transpile(length, traversal).getCode()); } } const offset = node.findExpressionAfterToken("OFFSET"); if (offset && offset.get() instanceof abaplint.Expressions.Source) { extra.push("sectionOffset: " + new expressions_1.SourceTranspiler().transpile(offset, traversal).getCode()); } const r = node.findDirectExpression(abaplint.Expressions.FindType); const type = r?.concatTokens().toUpperCase(); if (type === "REGEX") { extra.push("regex: " + new expressions_1.SourceTranspiler().transpile(sources[0], traversal).getCode()); } else if (type === "PCRE") { extra.push("pcre: " + new expressions_1.SourceTranspiler().transpile(sources[0], traversal).getCode()); } if (o === undefined && o === undefined && type !== "REGEX" && type !== "PCRE") { extra.push("of: " + new expressions_1.SourceTranspiler().transpile(sources[0], traversal).getCode()); } if (concat.includes(" IGNORING CASE")) { extra.push("ignoringCase: true"); } return new chunk_1.Chunk() .append("abap.statements.replace({target: ", node, traversal) .appendString(target + ", all: " + all + ", " + extra.join(", ")) .append("});", node.getLastToken(), traversal); } } exports.ReplaceTranspiler = ReplaceTranspiler; //# sourceMappingURL=replace.js.map