@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
39 lines • 1.98 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");
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), file) {
return (0, decorate_1.decorateAst)(normalizeButNotDecorated(parsed), { getId, file });
}
/**
* 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 }) {
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);
}
/**
* Tree-Sitter pendant to {@link normalize}.
*/
function normalizeTreeSitter({ parsed }, getId = (0, decorate_1.deterministicCountingIdGenerator)(0), file) {
const result = (0, decorate_1.decorateAst)((0, tree_sitter_normalize_1.normalizeTreeSitterTreeToAst)(parsed), { getId, file });
result.hasError = parsed.rootNode.hasError;
return result;
}
//# sourceMappingURL=parser.js.map