module /** */ import { ParsingState } from "../state" ; import { FailureInfo } from "../result" ; import { ParjsValidator } from "../parjser" ; import { ParjsCombinator } from "../../" ; import { defineCombinator } from "./combinator" ; import { ParjserBase } from "../parser" ; import defaults from "lodash/defaults" ; param predicate export function must < T > ( predicate ) { return defineCombinator ( source => { return new class Must extends ParjserBase { type = "must" ; expecting = `internal parser ${ source . type } yielding a result satisfying condition` ; _apply ( ps ) { source . apply ( ps ) ; if ( ! ps . isOk ) { return ; } let result = predicate ( ps . value , ps . userState ) ; if ( result === true ) return ; ps . kind = result . kind || "Soft" ; ps . reason = result . reason || "failed to fulfill a predicate" ; } } ( ) ; } ) ; }