@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
38 lines • 1.33 kB
JavaScript
;
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
*/
async function parseRequests(_results, input) {
/* in the future, we want to expose all cases */
const request = (Array.isArray(input.request) ? input.request[0] : input.request);
if (input.parser?.async) {
const parsed = await input.parser.parse(request);
return {
parsed,
'.parse-meta': typeof parsed === 'object' && 'rootNode' in parsed ? {
tokenCount: countChildren(parsed.rootNode),
} : undefined
};
}
else {
const parsed = input.parser.parse(request);
return {
parsed,
'.parse-meta': typeof parsed === 'object' && 'rootNode' in parsed ? {
tokenCount: countChildren(parsed.rootNode),
} : undefined
};
}
}
//# sourceMappingURL=parser.js.map