module /** */ import { ParsingState } from "../state" ; import { ResultKind } from "../result" ; import { ParjsCombinator } from "../../index" ; import { defineCombinator } from "./combinator" ; import { ParjserBase } from "../parser" ; param count export function exactly < T > ( count ) ; export function exactly ( count ) { return defineCombinator ( source => { return new class Exactly extends ParjserBase { type = "exactly" ; expecting = source . expecting ; _apply ( ps ) { let arr = [ ] as any [ ] ; for ( let i = 0 ; i < count ; i ++ ) { source . apply ( ps ) ; if ( ! ps . isOk ) { if ( ps . kind === ResultKind . SoftFail && i > 0 ) { ps . kind = ResultKind . HardFail ; } return ; } arr . push ( ps . value ) ; } ps . value = arr ; } } ( ) ; } ) ; }