Mold is a pure Rust PostgreSQL SQL parser and formatter built for editor tooling. It is part of the OctoFHIR ecosystem. It provides a lossless CST parser, semantic analysis helpers, and a completion engine.
- Lossless CST with recovery for partial or invalid SQL
- PostgreSQL-oriented grammar and JSONB/JSONPath support
- Formatter aligned with sqlstyle.guide
- Completion engine decoupled from LSP types
The project is split into focused crates under crates/:
mold_lexer: tokenizes SQL inputmold_parser: builds a CST with errorsmold_syntax: syntax kinds andParsecontainermold_hir: semantic analysis and name resolutionmold_completion: completion logic and providersmold_format: SQL formattingmold: facade crate and CLI entry point
For a deeper design walkthrough, see ARCHITECTURE.md.
let parse = mold::parser::parse("SELECT * FROM users");
if !parse.errors().is_empty() {
eprintln!("parse errors: {:?}", parse.errors());
}
let formatted = mold_format::format_sqlstyle("select * from users");
println!("{formatted}");Run from the repository root:
cargo run --example parse_and_formatcargo run --example completioncargo run --example custom_provider
cargo test --allcargo bench -p moldjust fmt
MIT