UNPKG

parjs

Version:

Library for building parsers using combinators.

34 lines 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.not = void 0; const combinated_1 = require("../combinated"); const result_1 = require("../result"); const wrap_implicit_1 = require("../wrap-implicit"); class Not extends combinated_1.Combinated { constructor() { super(...arguments); this.type = "not"; this.expecting = `not expecting: ${this.source.expecting}`; // TODO: better reason } _apply(ps) { const { position } = ps; this.source.apply(ps); if (ps.isOk) { ps.position = position; ps.kind = result_1.ResultKind.SoftFail; } else if (ps.kind === result_1.ResultKind.HardFail || ps.kind === result_1.ResultKind.SoftFail) { // hard fails are okay here ps.kind = result_1.ResultKind.Ok; ps.position = position; return; } // the remaining case is a fatal failure that isn't recovered from. } } /** Applies the source parser. Succeeds if if it fails softly, and fails otherwise. */ function not() { return source => new Not((0, wrap_implicit_1.wrapImplicit)(source)); } exports.not = not; //# sourceMappingURL=not.js.map