@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
62 lines • 3.51 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocationMapQueryDefinition = exports.LocationMapSpan = void 0;
const location_map_query_executor_1 = require("./location-map-query-executor");
const ansi_1 = require("../../../util/text/ansi");
const time_1 = require("../../../util/text/time");
const joi_1 = __importDefault(require("joi"));
const query_print_1 = require("../../query-print");
const slice_query_parser_1 = require("../../../cli/repl/parser/slice-query-parser");
/**
* How much of the source an entry of the {@link LocationMapQueryResult} covers: the `<-` of a multi-line
* assignment is a single `token`, while its subtree (`full`) is the whole assignment.
*/
var LocationMapSpan;
(function (LocationMapSpan) {
/** the location of the node itself, which for an operator or a call name is just that token */
LocationMapSpan["Token"] = "token";
/** the range the whole subtree of the node covers, see {@link RNode.span} */
LocationMapSpan["Full"] = "full";
/** the {@link Full} range of the top-level statement the node belongs to, see {@link RNode.topLevelStatement} */
LocationMapSpan["Statement"] = "statement";
})(LocationMapSpan || (exports.LocationMapSpan = LocationMapSpan = {}));
function locationMapLineParser(_output, line, _config) {
const criteria = (0, slice_query_parser_1.sliceCriteriaParser)(line[0]);
const rest = criteria ? line.slice(1) : line;
const span = Object.values(LocationMapSpan).includes(rest[0]) ? rest[0] : undefined;
return {
query: {
type: 'location-map',
ids: criteria,
...(span ? { span } : {})
},
rCode: (0, slice_query_parser_1.queryLineCode)(rest, span ? 1 : 0)
};
}
exports.LocationMapQueryDefinition = {
title: 'Location Map Query',
executor: location_map_query_executor_1.executeLocationMapQuery,
asciiSummarizer: (formatter, _analyzer, queryResults, result) => {
const out = queryResults;
result.push(`Query: ${(0, ansi_1.bold)('location-map', formatter)} (${(0, time_1.printAsMs)(out['.meta'].timing, 0)})`);
result.push(' ╰ File List:');
for (const [id, file] of Object.entries(out.map.files)) {
result.push(` ╰ ${id}: \`${file}\``);
}
result.push(` ╰ Id List: {${(0, query_print_1.summarizeIdsIfTooLong)(formatter, Object.keys(out.map.ids))}}`);
return true;
},
fromLine: locationMapLineParser,
completer: slice_query_parser_1.criteriaQueryCompleter,
syntax: '@location-map [(<crit>;...)] [token|full|statement] <code | file://path>',
schema: joi_1.default.object({
type: joi_1.default.string().valid('location-map').required().description('The type of the query.'),
ids: joi_1.default.array().items(joi_1.default.string()).optional().description('Optional list of ids to filter the results by.'),
span: joi_1.default.string().valid(...Object.values(LocationMapSpan)).optional().description('How much of the source the reported range covers: the token itself (default), the whole subtree of the node, or the top-level statement it belongs to.')
}).description('The location map query retrieves the location of every id in the ast.'),
flattenInvolvedNodes: () => []
};
//# sourceMappingURL=location-map-query-format.js.map