UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

57 lines (48 loc) 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.printNormalizedAst = printNormalizedAst; exports.printNormalizedAstForCode = printNormalizedAstForCode; const default_pipelines_1 = require("../../core/steps/pipeline/default-pipelines"); const ast_1 = require("../../util/mermaid/ast"); const time_1 = require("../../util/text/time"); const doc_files_1 = require("./doc-files"); const flowr_analyzer_context_1 = require("../../project/context/flowr-analyzer-context"); /** * Visualizes the normalized AST using mermaid syntax. * This is mainly intended for documentation purposes. */ function printNormalizedAst(ast, prefix = 'flowchart TD\n') { return ` \`\`\`mermaid ${(0, ast_1.normalizedAstToMermaid)(ast, { prefix })} \`\`\` `; } /** * Generates and prints the normalized AST for the given code, along with optional metadata and the original code. * This is intended for documentation purposes. */ async function printNormalizedAstForCode(parser, code, { showCode = true, prefix = 'flowchart TD\n' } = {}) { const now = performance.now(); const result = await (0, default_pipelines_1.createNormalizePipeline)(parser, { context: (0, flowr_analyzer_context_1.contextFromInput)(code) }).allRemainingSteps(); const duration = performance.now() - now; const metaInfo = `The analysis required _${(0, time_1.printAsMs)(duration)}_ (including parsing with the [${parser.name}](${doc_files_1.FlowrWikiBaseRef}/Engines) engine) within the generation environment.`; return '\n\n' + printNormalizedAst(result.normalize.ast, prefix) + (showCode ? ` <details> <summary style="color:gray">R Code of the Normalized AST</summary> ${metaInfo} \`\`\`r ${code} \`\`\` <details> <summary style="color:gray">Mermaid Code</summary> \`\`\` ${(0, ast_1.normalizedAstToMermaid)(result.normalize.ast, { prefix })} \`\`\` </details> </details> ` : '\n(' + metaInfo + ')\n\n'); } //# sourceMappingURL=doc-normalized-ast.js.map