UNPKG

@thi.ng/parse

Version:

Purely functional parser combinators & AST generation for generic inputs

66 lines 2.35 kB
import type { ICopy, Nullable } from "@thi.ng/api"; import type { ContextOpts, IReader } from "./api.js"; export declare class ParseState<T> implements ICopy<ParseState<T>> { p: number; l: number; c: number; done?: boolean | undefined; constructor(p: number, l: number, c: number, done?: boolean | undefined); copy(): ParseState<T>; } export declare class ParseScope<T> implements ICopy<ParseScope<T>> { id: string; state?: Nullable<ParseState<T>>; children?: Nullable<ParseScope<T>[]>; result?: any | undefined; constructor(id: string, state?: Nullable<ParseState<T>>, children?: Nullable<ParseScope<T>[]>, result?: any | undefined); copy(): ParseScope<T>; } export declare class ParseContext<T> { reader: IReader<T>; opts: ContextOpts; protected _scopes: ParseScope<T>[]; protected _curr: ParseScope<T>; protected _maxDepth: number; protected _peakDepth: number; protected _debug: boolean; protected _retain: boolean; constructor(reader: IReader<T>, opts?: Partial<ContextOpts>); reset(): this; start(id: string): ParseScope<T>; discard(): boolean; end(): boolean; addChild(id: string, result?: any, newState?: ParseState<T> | boolean): boolean; get scope(): ParseScope<T>; get state(): ParseState<T>; set state(state: ParseState<T>); get done(): boolean | undefined; /** * Returns root node. */ get root(): ParseScope<T>; /** * Returns root node's `result` or `undefined`. */ get result(): any; /** * Returns root node's children or `undefined`. */ get children(): Nullable<ParseScope<T>[]>; /** * Returns max. recursion depth which was actually reached. Will always be * less or equal configured {@link ContextOpts.maxDepth}. */ get peakDepth(): number; } /** * Creates new {@link ParseContext} for given input string, array or * reader and context options. * * @param input - * @param opts - */ export declare function defContext(input: string, opts?: Partial<ContextOpts>): ParseContext<string>; export declare function defContext<T>(input: ArrayLike<T>, opts?: Partial<ContextOpts>): ParseContext<T>; export declare function defContext<T>(input: IReader<T>, opts?: Partial<ContextOpts>): ParseContext<T>; //# sourceMappingURL=context.d.ts.map