import type { ParserRuleContext } from "antlr4ng"; import type { Expr, Projection, QueryExpr } from "./ir/ir.js"; import type { SyntaxDiagnostic } from "./parse-diagnostics.js"; import { type Scope, type ScopeTree } from "./scope/scope.js"; import { type Qualification } from "./qualify/qualify.js"; import { type SchemaProvider } from "./qualify/schema-provider.js"; import type { Type } from "./infer/types.js"; import { type Nullability } from "./infer/nullability.js"; export type { Nullability } from "./infer/nullability.js"; import { originsOf as exprOriginsOf, type ColumnLineage, type Origin } from "./lineage/lineage.js"; import { type StarExpansion, type Sym } from "./symbols/symbols.js"; import type { Token } from "./token/token.js"; import type { Dialect } from "./dialect.js"; export type { Dialect } from "./dialect.js"; /** Options carrying the dialect, needed only when a lift helper enters from a raw string. */ export interface DialectOpts { dialect?: Dialect; } export interface ParseResultIR { /** The dialect-neutral IR — the documented "AST" consumers build on. Deep-frozen. */ ast: QueryExpr; /** Count of lexer + parser syntax errors (a valid parse is still returned). */ errors: number; /** Positioned syntax diagnostics (message + line/column/offset/length). */ diagnostics: SyntaxDiagnostic[]; /** The raw antlr CST root — the escape hatch for tokens/exact spans. */ cst: ParserRuleContext; /** Every lexer token (trivia included, EOF excluded), as neutral `Token`s with exact spans — * the always-available token stream for editor features, present even when `errors > 0`. */ tokens: Token[]; /** True when the two-stage parse fell back from fast SLL prediction to full LL. Same result * either way — this just says which path produced it, for perf profiling (tools/profile-sll.ts). */ sllFallback: boolean; } /** * Parse one statement (or a dialect's statement batch) and lower it to the IR. Dispatches on * `dialect`. `ast` is the IR, frozen so no later pass can write back into it; `cst` is the raw * parse tree for anyone who needs tokens or precise spans. A valid parse never throws — syntax * errors are reported in `errors`, not raised. */ export declare function parse(sql: string, dialect: Dialect): ParseResultIR; export interface Analysis { ast: QueryExpr; errors: number; /** The parse tier's positioned SYNTAX diagnostics (line/column/offset/length) — the same array * parse() returns; `diagnostics` (below) is the SEMANTIC set from qualify. Two tiers, two fields. */ syntaxDiagnostics: SyntaxDiagnostic[]; /** The parse tier's first-class token stream (always present, even on broken input). */ tokens: Token[]; /** Raw-CST escape hatch, same object parse() returns. */ cst: ParserRuleContext; scopes: ScopeTree; /** Schema-fed diagnostics (unknown table/column/field). Empty without a schema. */ diagnostics: Qualification["diagnostics"]; /** The full schema-fed resolution (star expansion + diagnostics) — `Qualification.columnsOf`. */ qualification: Qualification; /** Per-expression types — `TypeInfo.typeOf(expr, scope)`. */ types: TypeInfo; /** Base-table origins per output column — `Lineage.originsOf(column)` / `.all`. */ lineage: Lineage; /** The kind × modifier symbol model over the scope tree. */ symbols: Sym[]; } /** * Run the whole pipeline — parse → lower → resolveScopes → qualify → infer / lineage / symbols — * and return each tier as a first-class terminal value. With no schema the schema-fed tiers still * answer what they can (scopes, symbols) and stay empty/`unknown` where a catalog is required. */ export declare function analyze(sql: string, dialect: Dialect, opts?: { schema?: SchemaProvider; }): Analysis; /** Lift to the IR. A `QueryExpr` returns unchanged; a string is parsed + lowered. */ export declare function toAst(x: string | QueryExpr, dialect?: Dialect): QueryExpr; /** Lift to a ScopeTree. A ScopeTree returns unchanged; an IR is resolved; a string is parsed + * lowered + resolved. The dialect is required only when entering from a string, or a bare * hand-built IR that carries no `dialect` tag — an IR from a dialect's lower() needs nothing. */ export declare function toScopes(x: string | QueryExpr | ScopeTree, opts?: DialectOpts): ScopeTree; /** Schema-fed resolution. Accepts a ScopeTree (no rework), an IR, or a raw string. */ export declare function qualify(x: string | QueryExpr | ScopeTree, schema: SchemaProvider, opts?: DialectOpts): Qualification; /** Column lineage. Accepts a ScopeTree (no rework), an IR, or a raw string. */ export declare function lineage(x: string | QueryExpr | ScopeTree, schema: SchemaProvider, opts?: DialectOpts): Lineage; /** Symbol model. Accepts a ScopeTree (no rework), an IR, or a raw string. Schema is optional. * `expandStarOf` (typically the `expandStarOf` of a `Qualification` already built over the same * scopes) additionally expands a resolvable star projection into per-column Syms — a separate * trailing param, not folded into `opts`, since it is a resolved callback tied to a specific * schema-fed pass, not a static dialect option. */ export declare function deriveSymbols(x: string | QueryExpr | ScopeTree, schema?: SchemaProvider, opts?: DialectOpts, expandStarOf?: StarExpansion): Sym[]; /** Per-expression type access. `typeOf(expr, scope)` returns the inferred `Type` (a typed union; * `unknown` when undeterminable — no schema, or no rule), never a guess. */ export declare class TypeInfo { private readonly schema; constructor(schema: SchemaProvider); /** The inferred type of an expression evaluated in a scope. */ typeOf(expr: Expr, scope: Scope): Type; /** The inferred nullability of an expression evaluated in a scope — "notnull"/"nullable" only * when provable from expression shape + schema + join shape, else "unknown" (never guessed). */ nullabilityOf(expr: Expr, scope: Scope): Nullability; } /** Base-table origins for a query's output columns. `all` is the per-output list; `originsOf(col)` * looks an output column up by name. Hides the internal lookup behind a typed accessor. */ export declare class Lineage { /** Per output column: the base-table columns it derives from. */ readonly all: readonly ColumnLineage[]; private readonly byOutput; private readonly byNode; constructor(columns: ColumnLineage[]); /** The base-table origins of a named output column, or [] if there is no such output. */ originsOf(column: string): Origin[]; /** Origins keyed by the producing Projection node — unambiguous under duplicate output names. */ originsOfNode(projection: Projection): Origin[]; } export { exprOriginsOf as originsOfExpr }; export { lineageAt, lineageOf, type LineageHop, type ViaStep } from "./lineage/hops.js"; export { tokenize } from "./token/tokenize.js"; export type { Token, TokenRole } from "./token/token.js"; export { SqlDocument, type DocumentAnalysis, type StatementCell, type DocumentVariant, type UnionCte, } from "./document/document.js"; export { LineIndex } from "./document/line-index.js"; export type { StatementCellSpan } from "./document/split.js"; export { complete, completeAt, type Completion, type CompletionResult, type ReplaceRange, type CompleteOptions, type CandidateIdentity, type CandidateDecoration, type DecorateCandidate, } from "./completion/complete.js"; export { jinjaSlotAt, type JinjaSlot } from "./completion/jinja-slot.js"; export { signatureAt, type SignatureHelpInfo, type SignatureLabel } from "./signature/signature.js"; export { SIGNATURES, lookupSignature, hasSignature, type FnSignature, type ParamSig } from "./signature/signatures.js"; export { renderSignature, type RenderSignatureOptions } from "./signature/render.js"; export { FN_DOCS, lookupFnDoc, type FnDoc } from "./signature/docs.js"; export { referencesAt, type Occurrence, type Occurrences } from "./references/references.js"; export { frameAt, type Frame } from "./scope/frame.js"; export { clausesOf, type ClauseInfo, type ClauseKind } from "./scope/clauses.js"; export { setOpArmsOf, type SetOpArm, type SetOpArms } from "./scope/setop-arms.js"; export { dialectSymbols, dialectVocabulary, type DialectSymbols, type DialectVocabulary } from "./dialect-symbols.js"; export { reservedKeywords, type KeywordEntry, type KeywordReservation } from "./dialect-symbols.js"; export { CallbackSchema, type SchemaProvider, type TableResolver } from "./qualify/schema-provider.js"; export { DERIVED_DIALECTS, resolveDialect } from "./derived-dialects.js"; export { foldIdentifier, displayName } from "./dialect-behavior/public-fold.js"; export type { IdentKind } from "./ident/fold.js";