UNPKG

parjs

Version:

Library for building parsers using combinators.

34 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reason = void 0; const combinated_1 = require("../combinated"); const wrap_implicit_1 = require("../wrap-implicit"); class Expects extends combinated_1.Combinated { constructor(source, messageOrFunction) { super(source); this.messageOrFunction = messageOrFunction; this.type = "expects"; this.expecting = typeof this.messageOrFunction === "string" ? this.messageOrFunction : "<dynamic>"; } _apply(ps) { const { position } = ps; const { messageOrFunction } = this; this.source.apply(ps); if (ps.kind !== "OK") { ps.reason = typeof messageOrFunction === "string" ? messageOrFunction : messageOrFunction({ kind: ps.kind, reason: ps.reason // the error is guaranteed to be non-null }); return; } ps.position = position; } } function reason(messageOrFunction) { return (source) => new Expects((0, wrap_implicit_1.wrapImplicit)(source), messageOrFunction); } exports.reason = reason; //# sourceMappingURL=reason.js.map