parjs
Version:
A parser-combinator library for JavaScript.
35 lines (34 loc) • 1.06 kB
JavaScript
;
/**
* @module parjs/combinators
*/
/** */
Object.defineProperty(exports, "__esModule", { value: true });
const parser_1 = require("../parser");
const combinator_1 = require("./combinator");
/**
* Applies the source parser. If it succeeds, backtracks to the current position in the input
* and yields the result.
*/
function backtrack() {
return combinator_1.defineCombinator(source => {
return new class Backtrack extends parser_1.ParjserBase {
constructor() {
super(...arguments);
this.type = "backtrack";
this.expecting = source.expecting;
}
_apply(ps) {
let { position } = ps;
source.apply(ps);
if (ps.isOk) {
// if inner succeeded, we backtrack.
ps.position = position;
}
// whatever code ps had, we return it.
}
}();
});
}
exports.backtrack = backtrack;
//# sourceMappingURL=backtrack.js.map