parjs
Version:
A parser-combinator library for JavaScript.
35 lines (34 loc) • 1.1 kB
TypeScript
/**
* @module parjs/combinators
*/
/** */
import { UserState } from "../state";
import { FailureInfo, ResultKind, SuccessInfo } from "../result";
import { ParjsCombinator } from "../../";
/**
* 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: ResultKind.Fail;
}
/**
* 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 declare 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<any, T>;