rlsp-fmt
A reusable Wadler-Lindig pretty-printing engine for the rlsp language server project.
Overview
rlsp-fmt provides a document IR (Doc) and a width-aware printer. You describe your output as a tree of Doc nodes — text, groups, indentation, soft/hard line breaks — and the printer decides where to break lines to fit within a configurable width.
Usage
use ;
let doc = group;
// Fits on one line at width 80
assert_eq!;
// Breaks across lines at width 10
let narrow = FormatOptions ;
assert_eq!;
Doc Nodes
| Node | Description |
|---|---|
Text(String) |
Literal text (must not contain newlines) |
HardLine |
Mandatory line break regardless of mode |
Line |
Space in flat mode, newline + indent in break mode |
Indent(Doc) |
Increases indentation level for the child |
Group(Doc) |
Tries flat mode first; breaks if content exceeds width |
Concat(Vec<Doc>) |
Sequential composition of documents |
FlatAlt { flat, break_ } |
Different content depending on flat/break mode |
Builder Functions
text(s)— create aTextnodehard_line()— create aHardLinenodeline()— create aLinenode (soft break)indent(doc)— wrap inIndentgroup(doc)— wrap inGroupconcat(docs)— combine intoConcatflat_alt(flat, break_)— mode-dependent contentjoin(separator, docs)— intersperse a separator between documents
FormatOptions
| Option | Default | Description |
|---|---|---|
print_width |
80 | Maximum line width before breaking groups |
tab_width |
2 | Spaces per indentation level (ignored when use_tabs is true) |
use_tabs |
false | Use tab characters instead of spaces |
Documentation
- Feature Log — implemented capabilities and design decisions
Building
License
MIT — Christoph Dalski
AI Note
Every line of source in this crate was authored, reviewed, and committed by AI agents working through a multi-agent pipeline (planning, implementation, independent review, and test/security advisors for high-risk tasks). The human role is designing the architecture, rules, and review process; agents execute them. Conformance against the YAML Test Suite is a measured acceptance criterion — not an aspiration — and any change touching parser behaviour or untrusted input passes through formal test and security advisor review before being merged.