UNPKG

parjs

Version:

A parser-combinator library for JavaScript.

121 lines (120 loc) 2.72 kB
import { 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. */ readonly isOk: boolean; } /** * Info about a success. */ export interface SuccessInfo<T> { kind: ResultKind.Ok; value: T; } /** * Info about a potential failure. */ export interface FailureInfo { kind: ResultKind.Fail; reason: string | object; } /** * 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<any>[]; input: string; } /** * A failure result from a Parjs parser. */ export declare class ParjsFailure implements FailureInfo { trace: Trace; constructor(trace: Trace); readonly value: never; readonly kind: ResultKind.Fail; readonly reason: string | object; toString(): string; /** * Whether this result is an OK. */ readonly isOk: boolean; } /** * A type that represents a ParjsSuccess or a ParjsFailure. Returned by parsers. */ export declare type ParjsResult<T> = (ParjsSuccess<T> | ParjsFailure); /** * Namespace that contains the different reply kinds/error levels. */ export declare namespace ResultKind { /** * An Unknown reply. Used internally. */ type Unknown = "Unknown"; /** * The OK reply type. */ type Ok = "OK"; /** * The soft failure type. */ type SoftFail = "Soft"; /** * The hard failure type. */ type HardFail = "Hard"; /** * The fatal failure type. */ type FatalFail = "Fatal"; /** * An Unknown reply. */ const Unknown: Unknown; /** * An OK reply. */ const Ok: Ok; /** * A soft failure reply. */ const SoftFail: SoftFail; /** * A hard failure reply. */ const HardFail: HardFail; /** * A fatal failure reply. */ const FatalFail: FatalFail; /** * Specifies any kind of failure. */ type Fail = HardFail | FatalFail | SoftFail; } /** * Specifies a reply kind, indicating success or failure, and the severity of the failure. */ export declare type ResultKind = ResultKind.Ok | ResultKind.Fail | ResultKind.Unknown;