parjs
Version:
Library for building parsers using combinators.
74 lines • 2.69 kB
TypeScript
import type { Parjser } from "./parjser";
/** Indicates a success reply and contains the value and other information. */
export declare class ParjsSuccess<T> implements SuccessInfo<T> {
value: T;
/** The kind of the result: OK, Soft, Hard, Fatal. */
kind: "OK";
constructor(value: T);
toString(): string;
/** Whether this result is an OK. */
get isOk(): boolean;
}
/** Info about a success. */
export interface SuccessInfo<T> {
kind: ResultKindOk;
value: T;
}
/** Info about a potential failure. */
export interface FailureInfo {
kind: ResultKindFail;
reason: string;
}
/** The line and column of where a failure happened. */
export interface ErrorLocation {
line: number;
column: number;
}
/** An object indicating trace information about the state of parsing when it was stopped. */
export interface Trace extends FailureInfo {
userState: object;
position: number;
location: ErrorLocation;
stackTrace: Parjser<unknown>[];
input: string;
}
/** A failure result from a Parjs parser. */
export declare class ParjsFailure implements FailureInfo {
trace: Trace;
constructor(trace: Trace);
get value(): never;
get kind(): ResultKindFail;
get reason(): string;
toString(): string;
/** Whether this result is an OK. */
get isOk(): boolean;
}
export declare function isParjsSuccess<T>(x: unknown): x is ParjsSuccess<T>;
export declare function isParjsFailure(x: unknown): x is ParjsFailure;
export declare function isParjsResult<T>(x: unknown): x is ParjsResult<T>;
/** A type that represents a ParjsSuccess or a ParjsFailure. Returned by parsers. */
export type ParjsResult<T> = ParjsSuccess<T> | ParjsFailure;
/** Namespace that contains the different reply kinds/error levels. */
export declare const ResultKind: {
/** An OK reply. */
Ok: "OK";
/** A soft failure reply. */
SoftFail: "Soft";
/** A hard failure reply. */
HardFail: "Hard";
/** A fatal failure reply. */
FatalFail: "Fatal";
};
/** The OK reply type. */
export type ResultKindOk = typeof ResultKind.Ok;
/** The soft failure type. */
export type ResultKindSoftFail = typeof ResultKind.SoftFail;
/** The hard failure type. */
export type ResultKindHardFail = typeof ResultKind.HardFail;
/** The fatal failure type. */
export type ResultKindFatalFail = typeof ResultKind.FatalFail;
/** Specifies any kind of failure. */
export type ResultKindFail = ResultKindHardFail | ResultKindFatalFail | ResultKindSoftFail;
/** Specifies a reply kind, indicating success or failure, and the severity of the failure. */
export type ResultKind = ResultKindOk | ResultKindFail;
//# sourceMappingURL=result.d.ts.map