parjs
Version:
Library for building parsers using combinators.
21 lines • 1.06 kB
TypeScript
import type { ParjsCombinator } from "../../";
import type { FailureInfo, ResultKindFail, SuccessInfo } from "../result";
import type { UserState } from "../state";
/** Information about the failure. */
export interface ParserFailureState {
/** The parser's user state at the moment of failure. */
readonly userState: UserState;
/** The reason reported by the failure. */
readonly reason: string | object;
/** The severity of the failure. */
readonly kind: ResultKindFail;
}
/**
* Function used to recover from a failure. The `kind`, `reason`, and `value` fields of the result
* are used to determine the new parser success state. You can return a falsy value to indicate
* nothing should change.
*/
export type RecoveryFunction<T> = (failure: ParserFailureState) => SuccessInfo<T> | Partial<FailureInfo> | null;
/** Reduces Hard failures to Soft ones and behaves in the same way on success. */
export declare function recover<T>(recoverFunction: RecoveryFunction<T>): ParjsCombinator<T, T>;
//# sourceMappingURL=recover.d.ts.map