Skip to content

`bynk-fmt`

Bynk’s formatter. There is one implementation, in bynkc::fmt; the bynk-fmt crate is a thin re-export of it so other tools (the CLI, the LSP) can share it. You invoke it as bynkc fmt — see the how-to Format your code with bynk-fmt for usage.

format_source(source, &FormatOptions) tokenises and parses the source, then re-prints the AST in canonical form. It is idempotent — formatting formatted code is a no-op — and it returns a FormatError (carrying the parse diagnostics) if the source does not parse.

FormatOptions controls the output:

FieldTypeDefault
indentIndentStyle (Tab or Spaces(n))Tab
max_line_widthu32100
trailing_commabooltrue

The CLI uses the defaults; a project can set [fmt] keys in bynk.toml (indent, max_line_width).

  • Tab indentation, one tab per nesting level.
  • K&R braces — the opening brace stays on the construct’s line.
  • Trailing commas in multi-line lists (records, sums, parameters).
  • One blank line between top-level declarations; none inside record/sum/parameter lists or between match arms.
  • A doc block sits directly above its declaration, with no blank line between.
  • One space around binary operators and after commas; no padding inside parentheses.
  • A soft 100-column width guides parameter wrapping.
use bynk_fmt::{format_source, FormatOptions};
let formatted = format_source(source, &FormatOptions::default())?;

This is exactly what bynkc fmt and the language server’s formatting requests call, so editor format-on-save and CLI formatting always agree.