derw-lang/js/unparser.mjs
2024-11-29 20:09:54 -05:00

19 lines
No EOL
491 B
JavaScript

import { openers } from "./parser.mjs";
function unparser(data) {
if (data.str) return data.str;
let output = data.args.map(x => unparser(x, false)).join('\n');
let ctx = data.context;
if (data.op != '[') output = output.replaceAll(/^/gm,' ');
let context = (ctx) ? `${ctx.trim()} ` : '';
if (data.op == '[') return `${context}${data.op}${output}${openers[data.op]}`;
return `${context}${data.op}\n${output}\n${openers[data.op]}`;
}
export {
unparser
};