UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

48 lines 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseRequests = parseRequests; /** * 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 ctx = input.context; const loadingOrder = ctx.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, ctx); files.push({ parsed, filePath: req.path, '.parse-meta': typeof parsed === 'object' && 'rootNode' in parsed ? { tokenCount: parsed.rootNode.descendantCount, } : undefined }); } return { files }; } else { const p = input.parser; return { files: translatedRequests.map(r => { const withPath = r.r; withPath.filePath = r.path; const parsed = p.parse(withPath, ctx); return { parsed, filePath: r.path, '.parse-meta': typeof parsed === 'object' && 'rootNode' in parsed ? { tokenCount: parsed.rootNode?.descendantCount ?? 0, } : undefined }; }) }; } } //# sourceMappingURL=parser.js.map