pdn
Version:
POSIX-friendly Data Notation
27 lines (19 loc) • 709 B
JavaScript
const emitters = require('./emitters');
const builtInReaders = require('./readers');
const { GenSym } = require('./name');
function Emitter({ readers:customReaders = {}, genSym = GenSym() } = {}) {
const readers = { ...builtInReaders, ...customReaders };
async function* emit(results) {
for await (const ast of results) {
if (ast == null) continue;
function emitter(node) {
if (emitters[node.type] == null) throw SyntaxError(node.type);
return emitters[node.type]({ node, emitter, readers, genSym });
}
yield emitter(ast);
}
}
return { emit };
}
module.exports = { Emitter };
;