UNPKG

parjs

Version:

Library for building parsers using combinators.

32 lines 963 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.backtrack = void 0; const combinated_1 = require("../combinated"); const combinator_1 = require("./combinator"); class Backtrack extends combinated_1.Combinated { constructor() { super(...arguments); this.type = "backtrack"; this.expecting = this.source.expecting; } _apply(ps) { const { position } = ps; this.source.apply(ps); if (ps.isOk) { // if inner succeeded, we backtrack. ps.position = position; } // whatever code ps had, we return it. } } /** * Applies the source parser. If it succeeds, backtracks to the current position in the input and * yields the result. */ function backtrack() { return (0, combinator_1.defineCombinator)(source => { return new Backtrack(source); }); } exports.backtrack = backtrack; //# sourceMappingURL=backtrack.js.map