@thi.ng/parse
Version:
Purely functional parser combinators & AST generation for generic inputs
19 lines (18 loc) • 384 B
JavaScript
const xform = (parser, xf, user) => (ctx) => {
if (parser(ctx)) {
const children = ctx.scope.children;
const scope = children[children.length - 1];
if (xf(scope, ctx, user)) {
if (scope.children && !scope.children.length) {
scope.children = null;
}
} else {
children.pop();
}
return true;
}
return false;
};
export {
xform
};