UNPKG

parjs

Version:

A parser-combinator library for JavaScript.

36 lines (35 loc) 1.04 kB
"use strict"; /** * @module parjs */ /** */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const parser_1 = require("../parser"); const defaults_1 = __importDefault(require("lodash/defaults")); const defaultFailure = { kind: "Hard", reason: "The primitive fail parser has been applied." }; /** * Returns a parser that will always fail with the given failure info. * @param pFailure How the parser should fail. */ function fail(pFailure) { let failure = defaults_1.default(pFailure, defaultFailure); return new class Fail extends parser_1.ParjserBase { constructor() { super(...arguments); this.type = "fail"; this.expecting = failure.reason; } _apply(ps) { ps.kind = failure.kind; ps.reason = this.expecting; } }(); } exports.fail = fail; //# sourceMappingURL=fail.js.map