UNPKG

rhombic

Version:

SQL parsing, lineage extraction and manipulation

43 lines 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getImageFromChildren = void 0; const isCstNode_1 = require("./isCstNode"); /** * Extract every `node.image` recursively into `image` * * @param children * @param image The textual representation of the Token as it appeared in the text. */ const extractImage = (children, image) => Object.values(children).forEach(tokens => { if (!Array.isArray(tokens)) return; tokens.forEach(token => { if (isCstNode_1.isCstNode(token)) { extractImage(token.children, image); return; } token.image.split("").forEach((char, i) => { if (token.startColumn) { image[token.startColumn + i] = char; } }); }); }); /** * Extract the `image` from a children dictionary. * * /!\ This function only deal with one line context /!\ * @param children */ const getImageFromChildren = (children) => { const image = []; extractImage(children, image); // This mutate `image` directly let output = ""; for (let i = 0; i < image.length; i++) { // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition output += image[i] === undefined ? " " : image[i]; } return output.trim(); }; exports.getImageFromChildren = getImageFromChildren; //# sourceMappingURL=getImageFromChildren.js.map