UNPKG

parjs

Version:

A parser-combinator library for JavaScript.

41 lines (40 loc) 1.4 kB
"use strict"; /** * @module parjs/combinators */ /** */ Object.defineProperty(exports, "__esModule", { value: true }); const result_1 = require("../result"); const combinator_1 = require("./combinator"); const parser_1 = require("../parser"); /** * Applies the source parser. Succeeds if if it fails softly, and fails otherwise. */ function not() { return combinator_1.defineCombinator(source => { return new class Not extends parser_1.ParjserBase { constructor() { super(...arguments); this.type = "not"; this.expecting = `not expecting: ${source.expecting}`; // TODO: better reason } _apply(ps) { let { position } = ps; 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. } }(); }); } exports.not = not; //# sourceMappingURL=not.js.map