Expand description
sql-dialect-fmt-formatter — the formatting half of the toolchain.
Two layers:
doc— a grammar-agnostic pretty-printing engine (aDocIR + 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 intoDocs.
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
Docintermediate representation plus a width-awareprint()er; SQL-specific rules live in the formatter’s SQL lowering module and only ever buildDocs. - range
- Statement-level range formatting.
Structs§
- Format
Options - Options controlling formatting. Opinionated and intentionally small.
- Format
Result - Output plus parse diagnostics from a single formatter pass.
- Print
Options - 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.
- Keyword
Case - How SQL keywords should be cased in formatted output.
- Line
Ending - 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.
- Render
docto 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.