@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
32 lines • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizedAstToMermaid = normalizedAstToMermaid;
exports.normalizedAstToMermaidUrl = normalizedAstToMermaidUrl;
const mermaid_1 = require("./mermaid");
const visitor_1 = require("../../r-bridge/lang-4.x/ast/model/processing/visitor");
const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
function normalizedAstToMermaid(ast, prefix = 'flowchart TD\n') {
let output = prefix;
(0, visitor_1.visitAst)(ast, n => {
const name = `${n.type} (${n.info.id})\\n${n.lexeme ?? ' '}`;
output += ` n${n.info.id}(["${(0, mermaid_1.escapeMarkdown)(name)}"])\n`;
if (n.info.parent !== undefined) {
const context = n.info;
const roleSuffix = context.role === "expr-list-child" /* RoleInParent.ExpressionListChild */ || context.role === "call-argument" /* RoleInParent.FunctionCallArgument */ || context.role === "function-def-param" /* RoleInParent.FunctionDefinitionParameter */ ? `-${context.index}` : '';
output += ` n${n.info.parent} -->|"${context.role}${roleSuffix}"| n${n.info.id}\n`;
}
if (n.type === type_1.RType.ExpressionList && n.grouping !== undefined) {
output += ` n${n.info.id} -.-|"group-open"| n${n.grouping[0].info.id}\n`;
output += ` n${n.info.id} -.-|"group-close"| n${n.grouping[1].info.id}\n`;
}
return false;
});
return output;
}
/**
* Use mermaid to visualize the normalized AST.
*/
function normalizedAstToMermaidUrl(ast, prefix = 'flowchart TD\n') {
return (0, mermaid_1.mermaidCodeToUrl)(normalizedAstToMermaid(ast, prefix));
}
//# sourceMappingURL=ast.js.map