UNPKG

parjs

Version:

Library for building parsers using combinators.

40 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mustCapture = void 0; const utils_1 = require("../../utils"); const combinated_1 = require("../combinated"); const wrap_implicit_1 = require("../wrap-implicit"); const defaultFailure = { reason: "succeeded without capturing input", kind: "Hard" }; class MustCapture extends combinated_1.Combinated { constructor(source, _failure) { super(source); this._failure = _failure; this.type = "mustCapture"; this.expecting = `expecting internal parser ${this.source.type} to consume input`; } _apply(ps) { const { position } = ps; this.source.apply(ps); if (!ps.isOk) { return; } if (position === ps.position) { ps.kind = this._failure.kind; ps.reason = this._failure.reason; } } } /** * Applies the source parser and makes sure it captured some input. * * @param pFailure The failure info. */ function mustCapture(pFailure) { const failure = (0, utils_1.defaults)(pFailure, defaultFailure); return source => new MustCapture((0, wrap_implicit_1.wrapImplicit)(source), failure); } exports.mustCapture = mustCapture; //# sourceMappingURL=must-capture.js.map