parjs
Version:
A parser-combinator library for JavaScript.
42 lines (41 loc) • 1.26 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, and then applies a selector on the source parser's
* result and user state to choose or create the parser to apply next.
* @param selector
*/
function thenPick(selector) {
return combinator_1.defineCombinator(source => {
return new class ThenPick extends parser_1.ParjserBase {
constructor() {
super(...arguments);
this.expecting = source.expecting;
this.type = "then-pick";
}
_apply(ps) {
source.apply(ps);
if (!ps.isOk) {
return;
}
let firstVal = ps.value;
let nextParser = selector(ps.value, ps.userState);
nextParser.apply(ps);
if (ps.isOk) {
return;
}
if (ps.isSoft) {
ps.kind = "Hard";
}
}
}();
});
}
exports.thenPick = thenPick;
//# sourceMappingURL=then-pick.js.map