parjs
Version:
Library for building parsers using combinators.
39 lines • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mapConst = exports.map = void 0;
const combinated_1 = require("../combinated");
const wrap_implicit_1 = require("../wrap-implicit");
class Map extends combinated_1.Combinated {
constructor(source, _projection) {
super(source);
this._projection = _projection;
this.type = "map";
this.expecting = this.source.expecting;
}
_apply(ps) {
this.source.apply(ps);
if (!ps.isOk) {
return;
}
ps.value = this._projection(ps.value, ps.userState);
}
}
/**
* Applies the source parser and projects its result with `projection`.
*
* @param projection The projection to apply.
*/
function map(projection) {
return source => new Map((0, wrap_implicit_1.wrapImplicit)(source), projection);
}
exports.map = map;
/**
* Applies the source parser and yields the constant value `result`.
*
* @param result The constant value to yield.
*/
function mapConst(result) {
return map(() => result);
}
exports.mapConst = mapConst;
//# sourceMappingURL=map.js.map