parjs
Version:
Library for building parsers using combinators.
30 lines • 859 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.each = void 0;
const combinated_1 = require("../combinated");
const wrap_implicit_1 = require("../wrap-implicit");
class Each extends combinated_1.Combinated {
constructor(source, _action) {
super(source);
this._action = _action;
this.type = "each";
this.expecting = this.source.expecting;
}
_apply(ps) {
this.source.apply(ps);
if (!ps.isOk) {
return;
}
this._action(ps.value, ps.userState);
}
}
/**
* Applies `action` to each result emitted by the source parser and emits its results unchanged.
*
* @param action
*/
function each(action) {
return source => new Each((0, wrap_implicit_1.wrapImplicit)(source), action);
}
exports.each = each;
//# sourceMappingURL=each.js.map