import { TextAst, TextAstArticle, TextAstText, TextAstTextInfos, TextInfosByWordsTree } from './ast.js'; import { FragmentPosition } from './fragments.js'; export type TextInfosConverter = (infos: TextAstTextInfos, context: TextParserContext) => TextAst | undefined; export type RegExpConverter = (match: RegExpExecArray, context: TextParserContext) => TextAst | undefined; export type TextAstConverter = (ast: T, context: TextParserContext) => TextAst | undefined; export type TextParser = { (context: TextParserContext): T | undefined; extract?: (context: TextParserContext, options?: { jumpExact?: boolean; globalRegExpFlags?: string; overlapWindow?: number; overlapWindowForCandidate?: (anchor: string) => number; }) => Generator; }; export declare class TextParserContext { input: string; offset: number; currentArticle: TextAstArticle | undefined; currentText: TextAstText | undefined; length: number; usedInputs: TextTree | undefined; variables: Record; constructor(input: string, offset?: number); position(): FragmentPosition; remaining(): string; text(position?: FragmentPosition): string; textFromResults(results: TextAst[] | undefined): string; } type TextTree = string | null | Array; export declare const alternatives: (...alternatives: Array) => TextParser; export declare const chain: (sequence: Array, { exportVariables, value, }?: { exportVariables?: boolean; value?: TextAst | TextAstConverter; }) => TextParser; export declare const convert: (parser: TextParser | TextParser[], { value }: { value: TextAst | TextAstConverter; }) => TextParser; /** * Executes a parser only if a fast-path regular expression matches ahead in the text. * It checks if the `fastRegExp` pattern exists within a short window ahead of `context.offset`. * If not, it skips evaluating the inner combinator tree, saving massive amounts of operations. */ export declare const fastPath: (fastRegExpContent: string, parser: TextParser | TextParser[], windowSize?: number, globalRegExpContent?: string) => TextParser; export declare const lookBehind: (parser: TextParser | TextParser[], { lookbackLength, value, }?: { lookbackLength?: number; value?: TextAst | TextAstConverter; }) => TextParser; export declare const optional: (parser: TextParser | TextParser[], { default: defaultValue, value, }: { default: TextAst | TextParser; value?: TextAst | TextAstConverter; }) => TextParser; export declare const parseText: (input: string, parser: TextParser | TextParser[]) => TextAst | undefined; export declare const regExp: (regExpContent: string, { flags, value, }?: { flags?: "d" | "di" | "dim" | "dimv" | "div" | "dm" | "dmv" | "dv" | "i" | "im" | "imv" | "iv" | "m" | "mv" | "v" | null; value?: TextAst | RegExpConverter; }) => TextParser; export declare const repeat: (parser: TextParser | TextParser[], { max, min, separator, value, }?: { max?: number; min?: number; separator?: TextParser; value?: TextAst | TextAstConverter; }) => TextParser; export declare const variable: (name: string, parser: TextParser | TextParser[], { value }?: { value?: TextAst | TextAstConverter; }) => TextParser; export declare const wordsTree: (tree: TextInfosByWordsTree, { value, }?: { value?: TextAst | TextInfosConverter; }) => TextParser; export {};