@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
41 lines • 2.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseLog = void 0;
exports.normalize = normalize;
exports.normalizeButNotDecorated = normalizeButNotDecorated;
exports.normalizeTreeSitter = normalizeTreeSitter;
const format_1 = require("./format");
const log_1 = require("../../../../../util/log");
const decorate_1 = require("../../model/processing/decorate");
const normalize_root_1 = require("../main/internal/structure/normalize-root");
const tree_sitter_normalize_1 = require("../../../tree-sitter/tree-sitter-normalize");
const config_1 = require("../../../../../config");
const r_project_1 = require("../../model/nodes/r-project");
exports.parseLog = log_1.log.getSubLogger({ name: 'ast-parser' });
/**
* Take the output as produced by the parse step and normalize the AST from the R parser.
* @see {@link normalizeButNotDecorated} - for a version that does not decorate the AST
* @see {@link normalizeTreeSitter} - for a version that normalizes the AST from the TreeSitter parser
*/
function normalize(parsed, getId = (0, decorate_1.deterministicCountingIdGenerator)(0)) {
return (0, decorate_1.decorateAst)(r_project_1.RProject.merge(parsed.files.map(normalizeButNotDecorated)), { getId });
}
/**
* Take the output as produced by the parse step and normalize the AST from the R parser.
* For additional decoration with {@link decorateAst} use {@link normalize}.
*/
function normalizeButNotDecorated({ parsed, filePath }) {
const data = { currentRange: undefined, currentLexeme: undefined };
const object = (0, format_1.convertPreparedParsedData)((0, format_1.prepareParsedData)(parsed));
return (0, normalize_root_1.normalizeRootObjToAst)(data, object, filePath);
}
/**
* Tree-Sitter pendant to {@link normalize}.
*/
function normalizeTreeSitter(parsed, getId = (0, decorate_1.deterministicCountingIdGenerator)(0), config = config_1.FlowrConfig.default()) {
const lax = config_1.FlowrConfig.getForEngine(config, 'tree-sitter')?.lax;
const result = (0, decorate_1.decorateAst)((0, tree_sitter_normalize_1.normalizeTreeSitterTreeToAst)(parsed.files, lax), { getId });
result.hasError = parsed.files.some(p => p.parsed.rootNode.hasError);
return result;
}
//# sourceMappingURL=parser.js.map