UNPKG

parjs

Version:

A parser-combinator library for JavaScript.

37 lines (36 loc) 1.01 kB
"use strict"; /** * @module parjs/combinators */ /** */ Object.defineProperty(exports, "__esModule", { value: true }); const combinator_1 = require("./combinator"); const parser_1 = require("../parser"); function map(projection) { return combinator_1.defineCombinator(source => { return new class Map extends parser_1.ParjserBase { constructor() { super(...arguments); this.type = "map"; this.expecting = source.expecting; } _apply(ps) { source.apply(ps); if (!ps.isOk) { return; } ps.value = projection(ps.value, ps.userState); } }(); }); } exports.map = map; /** * Applies the source parser and yields the constant value `result`. * @param result The constant value to yield. */ function mapConst(result) { return map(() => result); } exports.mapConst = mapConst; //# sourceMappingURL=map.js.map