@yar.ua/numerals
Version:
Number to text - Inflector for Ukrainian numerals
26 lines (25 loc) • 815 B
JavaScript
import { toString } from "./grammar.js";
export function to_mermaid(root) {
const ids = new WeakMap();
var counter = 0;
function id(l) {
if (ids.has(l)) {
return ids.get(l);
}
let newId = `o_${counter++}`;
ids.set(l, newId);
return `${newId}["${l.value} ${toString(l.form())}"]`;
}
const result = ["graph TD"];
function build_tree_recursive(root) {
root.edges.reverse().forEach(edge => {
const parent = id(edge.parent.lexeme);
const connection = `--> |${edge.rel}|`;
const child = id(edge.child.lexeme);
result.push(` ${parent} ${connection} ${child}`);
build_tree_recursive(edge.child);
});
}
build_tree_recursive(root);
return result.join("\n");
}