UNPKG

rawsql-ts

Version:

High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.

62 lines (61 loc) 2.22 kB
import { SqlComponent } from "../models/SqlComponent"; /** * Source span for a comment when parser metadata is available. * * @remarks The current parser stores comment text on AST nodes but does not * retain reliable per-comment source spans, so extractors usually omit this. */ export interface AstCommentSourceRange { start: number; end: number; } /** * Conservatively describes where an AST comment fact appears relative to syntax. */ export type AstCommentPlacement = "leading" | "trailing" | "inner" | "detached"; /** * Generic comment fact extracted from SQL AST comment metadata. * * @remarks `targetNode` is optional because SQL comments do not always have a * strict syntactic owner. Ambiguous legacy buckets are emitted as detached. */ export interface AstCommentAttachment { text: string; sourceOrder: number; placement: AstCommentPlacement; targetNode?: SqlComponent; range?: AstCommentSourceRange; } /** * Extracts comment attachment facts already represented in the SQL AST. * * @remarks This API does not infer product-specific meanings or rewrite * comments. It returns a deterministic flat list without mutating the input AST. */ export declare class AstCommentAttachmentExtractor { private readonly attachments; private readonly visited; private readonly suppressedDetachedCommentArrays; /** * Extract comment attachment facts from a SQL AST component. */ static extract(input: SqlComponent | null | undefined): AstCommentAttachment[]; private visit; private visitSqlComponent; private visitFallbackProperties; private shouldSkipProperty; private emitHeaderComments; private emitLegacyComments; private emitPositionedComments; private emitSelectItemKeywordComments; private emitKeywordPositionedComments; private emitDetachedComments; private emitComments; private isSelectQuery; private suppressWithClauseTrailingCommentsAlreadyCopiedToQuery; private containsCommentSequence; } /** * Extract comment attachment facts from a SQL AST component. */ export declare function extractAstCommentAttachments(input: SqlComponent | null | undefined): AstCommentAttachment[];