pegisland
Version:
General PEG-based parser supporting island grammars with lake symbols
26 lines • 906 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.genDot = void 0;
// Copyright (C) 2022- Katsumi Okuda. All rights reserved.
const ts_graphviz_1 = require("ts-graphviz");
function genDot(peg, parentsMap) {
const g = (0, ts_graphviz_1.digraph)('G');
const nodes = new Map();
[...peg.rules.values()].forEach((rule) => {
const node = g.createNode(rule.symbol);
nodes.set(rule, node);
});
[...peg.rules.values()].forEach((rule) => {
if (parentsMap.has(rule)) {
const parents = [...parentsMap.get(rule)];
const to = nodes.get(rule);
parents.forEach((parent) => {
const from = nodes.get(parent);
g.createEdge([from, to]);
});
}
});
return (0, ts_graphviz_1.toDot)(g);
}
exports.genDot = genDot;
//# sourceMappingURL=GraphPrinter.js.map