UNPKG

parjs

Version:

Library for building parsers using combinators.

50 lines 2.22 kB
import type { ParjsCombinator, Parjser } from "./parjser"; import type { ParjsResult } from "./result"; import type { ParsingState, UserState } from "./state"; /** A marker class used for storing the parser's user state. */ export declare class ParserUserState implements UserState { [key: string]: unknown; } export type ParjserDebugFunction = <T>(ps: ParsingState, current: Parjser<T>, startingPosition: number) => void; export declare const defaultDebugFunction: ParjserDebugFunction; /** * Returns a parser that will parse the string `str` and yield the text that was parsed. If it * can't, it will fail softly without consuming input. * * @param str The string to parse. */ export declare function string<T extends string>(str: T): Parjser<T>; /** * The internal base Parjs parser class, which supports only basic parsing operations. Should not be * used in user code. */ export declare abstract class ParjserBase<TValue> implements Parjser<TValue> { abstract type: string; abstract expecting: string; private debugFunction?; expects(expecting: string): Parjser<TValue>; debug(fn?: ParjserDebugFunction): Parjser<TValue>; /** * Apply the parser to the given state. * * @param ps The parsing state. */ apply(ps: ParsingState): void; /** * The internal operation performed by the PARSER. This will be overriden by derived classes. * * @param ps */ protected abstract _apply(ps: ParsingState): void; parse(input: string, initialState?: UserState): ParjsResult<TValue>; pipe<T, T1, T2 = T1, T3 = T2, T4 = T3, T5 = T4, T6 = T5>(cmb1?: ParjsCombinator<T, T1>, cmb2?: ParjsCombinator<T1, T2>, cmb3?: ParjsCombinator<T2, T3>, cmb4?: ParjsCombinator<T3, T4>, cmb5?: ParjsCombinator<T4, T5>, cmb6?: ParjsCombinator<T5, T6>): Parjser<T6>; } /** * Returns a parser that will try to match the regular expression at the current position and yield * the result set. If it can't, the parser will fail softly. The match must start at the current * position. It can't skip any part of the input. * * @param origRegexp */ export declare function regexp(origRegexp: RegExp): Parjser<string[]>; //# sourceMappingURL=parser.d.ts.map