import { Token as AntlrToken } from "antlr4ng"; import type { TemplateProvider } from "../qualify/template-provider.js"; export type Segment = { kind: "sql"; start: number; end: number; } | { kind: "tag"; tagKind: "expr" | "stmt" | "comment"; start: number; end: number; text: string; }; export interface SegmentResult { /** Source order, tiling (contiguous, cover [0, text.length)). */ segments: Segment[]; /** Same length + same newline positions as the input. */ placeholder: string; /** * Pipeline-internal (parse.ts consumes it; NOT part of the placeholder/segments public * contract — the golden gate only serializes `segments`/`placeholder`). Every tag segment's * FULL token slice from the one whole-document tokenization: the OPEN token, every token * between it and the CLOSE (ALL channels, hidden JWS included), and the CLOSE token when * present (absent on an unterminated tag). Keyed by tag segment object IDENTITY, same pattern * as the internal `leadingByTag` map. Lets parse.ts build each tag's channel-2 token stream and * parse tree directly from this slice — already in document coordinates, no re-lex. */ tagTokens: ReadonlyMap; } export { NO_OUTPUT_BUILTINS } from "../qualify/template-provider.js"; /** * Segment raw jinja-SQL over the outer jinja language and build the length- and * newline-preserving placeholder. Total: never throws on any input. * * Driven by ONE whole-document tokenization from the minijinja island lexer * (`grammars/minijinja/MinijinjaLexer.g4`): every RAW_TEXT/STRAY/RAW_BODY/RAW_BODY_STRAY token outside * a tag accumulates into the current sql run; an OPEN token starts a tag that runs to its matching * CLOSE token (or to `text.length` on EOF — unterminated-tag totality); `{% raw %}` raw-block spanning * is the lexer's own `RawBody` mode (grammar-level), so this function does no raw-specific scanning at * all — it just walks whatever tokens the lexer produced. * * Every expr tag consults `provider.expansion(call)` (the call extracted lexically * by `tagCall`): shape `"nothing"` → whitespace fill; a fragment shape → the * shape-valid fragment (fit- and slot-guarded); `"expr"` / no answer → the * positional identifier fill. The provider states WHAT a call produces; every * fill decision here is the engine's own (non-overridable) machinery. */ export declare function segment(text: string, provider: TemplateProvider): SegmentResult;