UNPKG

parjs

Version:

Library for building parsers using combinators.

66 lines 2.51 kB
import { ResultKind } from "./result"; /** Container type for user state data. */ export interface UserState { [key: string]: unknown; } /** Maintains progress for parsing a single input. */ export interface ParsingState { /** The original string input on which parsing is performed. Should not be mutated while parsing. */ readonly input: string; /** The next character waiting to be parsed. */ position: number; /** The value from the last parser action performed on this state. */ value: unknown; /** Additional state data. */ userState: UserState; /** Initial user state. */ readonly initialUserState: UserState | undefined; /** A stack that indicates entered parsers. Should not be modified by user code. */ stack: { type: string; expecting: string; }[]; /** * If the result is a failure, this field will indicate the reason for the failure. If the * result is OK, this must be undefined. */ reason: string | undefined; /** The result of the last parser action: OK, SoftFailure, HardFailure, FatalFailure. */ kind: ResultKind; /** Shorthand for this.result == Okay */ readonly isOk: boolean; /** Shorthand for this.result == SoftFailure */ readonly isSoft: boolean; /** Shorthand for this.result == HardFailure */ readonly isHard: boolean; /** Shorthand for this.result == FatalFailure */ readonly isFatal: boolean; atLeast(kind: ResultKind): boolean | undefined; atMost(kind: ResultKind): boolean | undefined; } /** Basic implementation of the ParsingState interface. */ export declare class BasicParsingState<TValue> implements ParsingState { input: string; userState: UserState; position: number; stack: never[]; initialUserState: UserState | undefined; value: TValue | undefined; kind: ResultKind; reason: string; constructor(input: string, userState: UserState); get isOk(): boolean; get isSoft(): boolean; get isHard(): boolean; get isFatal(): boolean; atLeast(kind: ResultKind): boolean | undefined; atMost(kind: ResultKind): boolean | undefined; } /** A unique object value indicating the reuslt of a failed parser. */ export declare const FAIL_RESULT: any; /** * A unique object value indicating that a parser did not initialize the ParsingState's value * property before terminating, which is an error. */ export declare const UNINITIALIZED_RESULT: any; //# sourceMappingURL=state.d.ts.map