module /** */ import { FailureInfo , ResultKind } from "../result" ; import { ParsingState } from "../state" ; import { ParjsCombinator } from "../../index" ; import { defineCombinator } from "./combinator" ; import { ParjserBase } from "../parser" ; import defaults from "lodash/defaults" ; const defaultFailure = { reason : "succeeded without capturing input" , kind : "Hard" } ; param pFailure export function mustCapture < T > ( pFailure ? ) { let failure = defaults ( pFailure , defaultFailure ) ; return defineCombinator ( source => { return new class MustCapture extends ParjserBase { expecting = `expecting internal parser ${ source . type } to consume input` ; type = "mustCapture" ; _apply ( ps ) { let { position } = ps ; source . apply ( ps ) ; if ( ! ps . isOk ) { return ; } if ( position === ps . position ) { ps . kind = failure . kind ; ps . reason = failure . reason ; } } } ( ) ; } ) ; }