import { ExecutionContext } from "./execution"; import { SourceFile } from "./tree"; import { ParseError } from "./parse-error"; export type SourcePath = string; export type ParserInput = SourcePath | { text: string; sourcePath: string; }; export declare function parserInputRead(input: ParserInput): string; export declare function parserInputFile(input: ParserInput): string; export interface ParserOptions { ctx?: ExecutionContext; relativeTo?: string; } export declare abstract class Parser { constructor({ ctx, relativeTo }?: ParserOptions); protected ctx: ExecutionContext; protected readonly relativeTo?: string; abstract parse(...sourcePaths: ParserInput[]): AsyncGenerator; /** * Parses a single input and returns the first source file. * This is a convenience method for when you know you're parsing exactly one input. * * @param input The input to parse * @returns The parsed source file * @throws Error if the parser produces no results */ parseOne(input: ParserInput): Promise; protected relativePath(sourcePath: ParserInput): string; protected error(input: ParserInput, e: Error): ParseError; } /** * A source reader that can be used by parsers to incrementally parse a source, keeping * track of the position of the parsing. */ export declare class ParserSourceReader { readonly sourcePath: ParserInput; readonly source: string; cursor: number; constructor(sourcePath: ParserInput); whitespace(): string; sourceBefore(token: string): string; /** * Used in debugging parsers during development to see where the * cursor is in the source. */ get afterCursor(): string; } export declare function readSourceSync(sourcePath: ParserInput): string; type ParserConstructor = new (options?: ParserOptions) => T; export type ParserType = "javascript" | "packageJson" | "json" | "yaml" | "plainText"; export declare class Parsers { private static registry; static registerParser(name: ParserType, parserClass: ParserConstructor): void; static createParser(name: ParserType, options?: ParserOptions): Parser; } export {}; //# sourceMappingURL=parser.d.ts.map