import type { DocumentLocation, DocumentPosition, DocumentReference, ImportLocation, ModelDef, NamedModelObject, SourceDef, SQLSourceDef, DependencyTree, DocumentRange } from '../model/malloy_types'; import type { LogMessage, LogMessageOptions, MessageCode, MessageParameterType } from './parse-log'; import { BaseMessageLogger } from './parse-log'; import type { ZoneData } from './zone'; import { Zone } from './zone'; import { ReferenceList } from './reference-list'; import type { ResponseBase, ASTResponse, CompletionsResponse, DataRequestResponse, ProblemResponse, FatalResponse, FinalResponse, HelpContextResponse, MetadataResponse, ModelDataRequest, NeedURLData, TranslateResponse, ModelAnnotationResponse, TablePathResponse } from './translate-response'; import { Tag } from '@malloydata/malloy-tag'; import type { MalloyParseInfo } from './malloy-parse-info'; import type { EventStream } from '../runtime_types'; import type { ParserRuleContext } from 'antlr4ts'; export type StepResponses = DataRequestResponse | ASTResponse | TranslateResponse | ParseResponse | MetadataResponse | PretranslatedResponse; /** * A Translation is a series of translation steps. Each step can depend * on other steps, in which case the preceeding steps will be passed * to the constructor. The translator methods will then ask the final * step for the answer, and it will call up the chain asking all the * steps that it depends on for their answers. * * Any step can return a result which will be ... * "I had errors, go no further" * "I hit a spot where I need more data before I can continue" * "I am done, here is the result of this step" */ interface TranslationStep { step(that: MalloyTranslation): StepResponses; } interface ParseData extends ResponseBase, ProblemResponse, NeedURLData, FinalResponse { parse: MalloyParseInfo; } export type ParseResponse = Partial; interface PretranslatedData { translation: ModelDef; } export type PretranslatedResponse = PretranslatedData | null; /** * ParseStep -- Parse the source URL */ interface SourceInfo { lines: string[]; at: { begin: number; end: number; }[]; length: number; } declare class ParseStep implements TranslationStep { response?: ParseResponse; sourceInfo?: SourceInfo; step(that: MalloyTranslation): ParseResponse; private runParser; } declare class ImportsAndTablesStep implements TranslationStep { readonly parseStep: ParseStep; private parseReferences; constructor(parseStep: ParseStep); step(that: MalloyTranslation): DataRequestResponse | ParseResponse; } declare class ASTStep implements TranslationStep { readonly importStep: ImportsAndTablesStep; response?: ASTResponse; private walked; constructor(importStep: ImportsAndTablesStep); step(that: MalloyTranslation): ASTResponse; } declare class MetadataStep implements TranslationStep { readonly parseStep: ParseStep; response?: MetadataResponse; constructor(parseStep: ParseStep); step(that: MalloyTranslation): MetadataResponse; } declare class CompletionsStep implements TranslationStep { readonly parseStep: ParseStep; constructor(parseStep: ParseStep); step(that: MalloyTranslation, position?: { line: number; character: number; }): CompletionsResponse; } declare class HelpContextStep implements TranslationStep { readonly parseStep: ParseStep; constructor(parseStep: ParseStep); step(that: MalloyTranslation, position?: { line: number; character: number; }): HelpContextResponse; } declare class ModelAnnotationStep implements TranslationStep { readonly parseStep: ParseStep; response?: ModelAnnotationResponse; constructor(parseStep: ParseStep); step(that: MalloyTranslation, extendingModel?: ModelDef): ModelAnnotationResponse; } declare class TablePathInfoStep implements TranslationStep { readonly parseStep: ParseStep; response?: TablePathResponse; constructor(parseStep: ParseStep); step(that: MalloyTranslation): TablePathResponse; } declare class TranslateStep implements TranslationStep { readonly astStep: ASTStep; response?: TranslateResponse; importedAnnotations: boolean; constructor(astStep: ASTStep); step(that: MalloyTranslation, extendingModel?: ModelDef): TranslateResponse; } export declare abstract class MalloyTranslation { readonly sourceURL: string; readonly importBaseURL: string | null; grammarRule: string; abstract root: MalloyTranslator; childTranslators: Map; sqlSources: SQLSourceDef[]; modelDef: ModelDef; imports: ImportLocation[]; compilerFlags: Tag; readonly parseStep: ParseStep; readonly modelAnnotationStep: ModelAnnotationStep; readonly importsAndTablesStep: ImportsAndTablesStep; readonly astStep: ASTStep; readonly metadataStep: MetadataStep; readonly completionsStep: CompletionsStep; readonly helpContextStep: HelpContextStep; readonly tablePathInfoStep: TablePathInfoStep; readonly translateStep: TranslateStep; readonly references: ReferenceList; constructor(sourceURL: string, importBaseURL?: string | null, grammarRule?: string); _urlIsFullPath: boolean | undefined; get urlIsFullPath(): boolean; addChild(url: string): void; getDependencies(): string[]; getDependencyTree(): DependencyTree; newlyTranslatedDependencies(): { url: string; modelDef: ModelDef; }[]; addReference(reference: DocumentReference): void; referenceAt(position: DocumentPosition): DocumentReference | undefined; /** * This returns a *final* response containing all problems, for when there are * errors and the translation needs to stop and report errors. When doing so, * it also reports warnings. */ fatalResponse(): FatalResponse; /** * The problem log can grow as progressively deeper questions are asked. * When returning "problems so far", make a snapshot. */ problemResponse(): ProblemResponse; problems(): LogMessage[]; getLineMap(url: string): string[] | undefined; codeAtLocation(location: DocumentLocation): string; prettyErrors(): string; childRequest(importURL: string): ModelDataRequest; getChildExports(importURL: string): Record; private finalAnswer?; translate(extendingModel?: ModelDef): TranslateResponse; translatorForDependency(url: string): MalloyTranslation | undefined; importAt(position: DocumentPosition): ImportLocation | undefined; metadata(): MetadataResponse; modelAnnotation(extendingModel?: ModelDef): ModelAnnotationResponse; tablePathInfo(): TablePathResponse; completions(position: { line: number; character: number; }): CompletionsResponse; helpContext(position: { line: number; character: number; }): HelpContextResponse; defaultLocation(): DocumentLocation; rangeFromContext(pcx: ParserRuleContext): DocumentRange; private dialectAlreadyChecked; firstReferenceToDialect(dialect: string): boolean; allDialectsEnabled: boolean; experimentalDialectEnabled(dialect: string): boolean; } export declare class MalloyChildTranslator extends MalloyTranslation { readonly root: MalloyTranslator; constructor(rootURL: string, root: MalloyTranslator); } /** * The main interface to Malloy translation. It has a call pattern * similar to a server. Once a translator is instantiated * you can request translations repeatedly. Responses to that request * will either be "NeedResponse" or "TranslateResponse" objects. The * correct pattern is to call "translation" in a loop, calling * "update" in response to each "NeedResponse" until a "TranslateResponse" * is returned. If you get a response with "final:true", there is * no need to call again, the translation is finished or error'd. */ export declare class MalloyTranslator extends MalloyTranslation { private readonly eventStream; schemaZone: Zone; importZone: Zone; pretranslatedModels: Map; sqlQueryZone: Zone; logger: BaseMessageLogger; readonly root: MalloyTranslator; constructor(rootURL: string, importURL?: string | null, preload?: ParseUpdate | null, eventStream?: EventStream | null); update(dd: ParseUpdate): void; logError(code: T, parameters: MessageParameterType, options?: Omit): T; } interface ErrorData { tables: Record; urls: Record; compileSQL: Record; translations: Record; } export interface URLData { urls: ZoneData; } export interface ModelData { translations: ZoneData; } export interface SchemaData { tables: ZoneData; } export interface SQLSources { compileSQL: ZoneData; } export interface UpdateData extends URLData, SchemaData, SQLSources, ModelData { errors: Partial; } export type ParseUpdate = Partial; export {};