Rust API reference

Feature flags

FeatureWhat it enables
fmtFormatter
validationSemantic analysis (unknown tables, columns, functions)
sqliteBuilt-in SQLite dialect (enabled by default)
lspLanguage server protocol implementation
serde-jsonJSON serialization for AST and diagnostics
dynloadLoad custom dialects from shared libraries at runtime

Formatter

Type / MethodDescription
Formatter::new()Create with SQLite dialect and default settings
Formatter::with_config(&FormatConfig)Create with custom config
fmt.format(sql) -> Result<String>Format SQL string
FormatConfigline_width, indent_width, keyword_case, semicolons
KeywordCaseUpper or Lower

The formatter is reusable — call format() repeatedly. Internal allocations are reused across calls. Defaults: 80-char lines, 2-space indent, uppercase keywords, semicolons on.

Parser

Type / MethodDescription
Parser::new()Create a parser for the SQLite grammar
parser.parse(sql) -> ParseSessionStart a parse session
session.next() -> ParseOutcomeYield next statement
ParseOutcome::Ok(stmt)Successfully parsed statement
ParseOutcome::Err(err)Parse error (parser recovers and continues)
ParseOutcome::DoneNo more statements

The parser yields statements one at a time, reusing internal allocations. It recovers from errors and continues parsing subsequent statements.

Tokenizer

Type / MethodDescription
Tokenizer::new()Create a tokenizer for the SQLite grammar
tokenizer.tokenize(sql) -> Result<Vec<Token>>Tokenize SQL string
Tokentoken_type, text, byte offsets into source

Zero-copy — tokens reference byte offsets into the source string.