Skip to main content

Crate sql_dialect_fmt_formatter

Crate sql_dialect_fmt_formatter 

Source
Expand description

sql-dialect-fmt-formatter — the formatting half of the toolchain.

Two layers:

  • doc — a grammar-agnostic pretty-printing engine (a Doc IR + width-aware printer) in the Wadler → Prettier → biome/ruff lineage. Depends on nothing SQL-specific.
  • sql — the Snowflake SQL rules that lower the parser’s lossless CST into Docs.

format() ties them together: parse → lower → print. Like the parser, it never panics; input it cannot model structurally is preserved verbatim, so formatting is always content-preserving.

use sql_dialect_fmt_formatter::{format, FormatOptions};
let out = format("select a,b from t", &FormatOptions::default());
assert_eq!(out, "SELECT a, b\nFROM t;\n");

§Public API stability

FormatOptions is the configuration entry point and is #[non_exhaustive]: build it from FormatOptions::default and refine it with the with_* methods so adding future knobs stays backwards compatible.

Re-exports§

pub use range::format_range;
pub use range::RangeEdit;

Modules§

doc
A small, self-contained pretty-printing engine in the Wadler → Prettier → rome/biome → ruff lineage. The grammar-agnostic core is a Doc intermediate representation plus a width-aware print()er; SQL-specific rules live in the formatter’s SQL lowering module and only ever build Docs.
range
Statement-level range formatting.

Structs§

FormatOptions
Options controlling formatting. Opinionated and intentionally small.
FormatResult
Output plus parse diagnostics from a single formatter pass.
PrintOptions
Knobs for the printer. Opinionated by design: just a target width and an indent step.

Enums§

Dialect
The SQL dialect a lex/parse/format request targets.
Doc
The pretty-printer intermediate representation.
KeywordCase
How SQL keywords should be cased in formatted output.
LineEnding
Output line-ending policy.

Functions§

format
Format Snowflake SQL source text. Never panics; never drops content.
format_with_diagnostics
Format SQL and return parse diagnostics from the same lex/parse pass.
print
Render doc to a string. Trailing whitespace is trimmed from every line and the result ends with exactly one newline (or is empty), so the output is stable under re-formatting.