import { Result } from './result'; declare type ParseResult = Result<{ output: T; rest: string; }, E>; declare type EvalResult = Result; export declare type Pos = { /** How long is the input string at the start of parsing? */ startLen: number; /** How long is the input string at the end of parsing? */ endLen: number; }; declare type Pattern = string | RegExp; /** Internal, low level parse errors */ export declare type LibParseError = LibParseErrorMatchString | LibParseErrorMustTakeWhile | LibParseErrorMustSepBy | LibParseErrorEndOfString | LibParseErrorNotANumber; declare type LibParseErrorNotANumber = { kind: 'NOT_A_NUMBER'; input: string; }; declare type LibParseErrorEndOfString = { kind: 'EXPECTS_A_CHAR'; input: ""; expects?: string; }; declare type LibParseErrorMatchString = { kind: 'EXPECTS_A_STRING'; expectedOneOf: string[]; input: string; }; declare type LibParseErrorMustTakeWhile = { kind: 'EXPECTS_PATTERN'; expectedPattern: RegExp | String; input: string; }; declare type LibParseErrorMustSepBy = { kind: 'EXPECTS_A_SEPARATOR'; input: string; }; export declare class Parser { readonly _fn_: (input: string) => ParseResult; private constructor(); eval(input: string): EvalResult; parse(input: string): ParseResult; /** A parser that does nothing */ static ok(val: T): Parser; /** Any one character. Only fails on an empty string */ static anyChar(): Parser; /** * Parse a string. * Expects strings to be surrounded in single or double quotes. * backslash to escape; anything can be escaped. */ static string(): Parser; /** Parse a number as a string */ static numberStr(): Parser; /** A convenience function to turn a function scope into a parser to avoid reuse of vars */ static lazy(fn: () => Parser): Parser; /** Return a parser that matches a given string */ static matchString(...strings: string[]): Parser; /** Take characters while the fn provided matches them to a max of n */ static takeWhileN(n: number, pat: Pattern): Parser; static takeWhile(pat: Pattern): Parser; /** Take characters while the fn provided matches them to a max of n */ static mustTakeWhileN(n: number, pat: Pattern): Parser; static mustTakeWhile(pat: Pattern): Parser; /** Run this on a parser to peek at the available position information (distances from end) */ mapWithPosition(fn: (res: T, pos: Pos) => T2): Parser; /** Make the success of this parser optional */ optional(): Parser, E>; /** Map this parser result into something else */ map(fn: (result: T) => T2): Parser; mapErr(fn: (err: E) => E2): Parser; /** Succeeds if the current parser or the one provided succeeds */ or(other: Parser): Parser; /** Pass the result of the this parser to a function which returns the next parser */ andThen(next: (result: T) => Parser): Parser; sepBy(sep: Parser): Parser<{ results: T[]; separators: S[]; }, E>; mustSepBy(sep: Parser): Parser<{ results: T[]; separators: S[]; }, E | LibParseError>; } export {};