UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

52 lines 2.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseRequests = parseRequests; function countChildren(node) { let ret = 1; for (const child of node.children) { ret += countChildren(child); } return ret; } /** * Takes an input program and parses it using the given parser. * @param _results - just a proxy for the pipeline, signifies that this function does not need prior knowledge of the pipeline * @param input - the input to the parse step * @returns The parsed AST per request in the loading order obtained from the {@link FlowrAnalyzerFilesContext|files context} of the given {@link FlowrAnalyzerContext}. */ async function parseRequests(_results, input) { const loadingOrder = input.context.files.loadingOrder.getLoadingOrder(); /* in the future, we want to expose all cases */ const translatedRequests = loadingOrder.map(r => input.context.files.resolveRequest(r)); if (input.parser?.async) { /* sadly we cannot Promise.all with the Rshell as it has to process commands in order and is not thread safe */ const files = []; for (const req of translatedRequests) { const parsed = await (input.parser).parse(req.r); files.push({ parsed, filePath: req.path, '.parse-meta': typeof parsed === 'object' && 'rootNode' in parsed ? { tokenCount: countChildren(parsed.rootNode), } : undefined }); } return { files }; } else { const p = input.parser; return { files: translatedRequests.map(r => { const parsed = p.parse(r.r); return { parsed, filePath: r.path, '.parse-meta': typeof parsed === 'object' && 'rootNode' in parsed ? { tokenCount: countChildren(parsed.rootNode), } : undefined }; }) }; } } //# sourceMappingURL=parser.js.map