UNPKG

parjs

Version:

Library for building parsers using combinators.

38 lines 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.thenPick = void 0; const combinated_1 = require("../combinated"); const wrap_implicit_1 = require("../wrap-implicit"); class ThenPick extends combinated_1.Combinated { constructor(source, _ctor) { super(source); this._ctor = _ctor; this.type = "then-pick"; this.expecting = `${this.source.expecting} then <dynamic>`; } _apply(ps) { this.source.apply(ps); if (!ps.isOk) { return; } const nextParser = (0, wrap_implicit_1.wrapImplicit)(this._ctor(ps.value, ps.userState)); nextParser.apply(ps); if (ps.isOk) { return; } if (ps.isSoft) { ps.kind = "Hard"; } } } /** * Applies the source parser, and then applies a selector on the source parser's result and user * state to choose or create the parser to apply next. * * @param selector */ function thenPick(selector) { return source => new ThenPick((0, wrap_implicit_1.wrapImplicit)(source), selector); } exports.thenPick = thenPick; //# sourceMappingURL=then-pick.js.map