@thi.ng/parse
Version:
Purely functional parser combinators & AST generation for generic inputs
18 lines (17 loc) • 384 B
JavaScript
import { xform } from "../combinators/xform.js";
const xfJoin = (scope) => {
if (!scope || !scope.children) return null;
const res = [];
for (let c of scope.children) {
xfJoin(c);
if (c.result) res.push(c.result);
}
scope.result = res.join("");
scope.children = null;
return scope;
};
const join = (parser) => xform(parser, xfJoin);
export {
join,
xfJoin
};