Skip to main content

bynk_fmt/
lib.rs

1//! `bynk-fmt` — the Bynk formatter.
2//!
3//! A real leaf crate: the formatter is an AST-walk over the `bynk-syntax`
4//! types, so it depends on `bynk-syntax` only and never links the compiler
5//! (resolver/checker/emitter). Slice 2 of the crate-decomposition track moved
6//! the implementation down here from `bynkc::fmt` and re-pointed it onto the
7//! `bynk-syntax` leaf, turning the former cosmetic façade into the home of the
8//! formatter itself. `bynk`'s own `bynk fmt` command reaches it via
9//! `bynk-driver::run_fmt` (R10.4 residue, #1048: `bynkc` no longer re-exports
10//! this crate as `bynkc::fmt`).
11
12// The README's `rust` examples are compiled (and, unless marked `no_run`, run)
13// as doctests, so they cannot rot (#1645). `cfg(doctest)` keeps this item out of
14// every build and out of the docs.rs front page, which the `//!` docs above own.
15#[cfg(doctest)]
16#[doc = include_str!("../README.md")]
17struct ReadmeDoctests;
18
19mod config;
20mod fmt;
21
22pub use fmt::{FormatError, FormatOptions, IndentStyle, format_source, normalize_line_endings};
23// v0.123 (editor-currency slice 2): the surface renderers for an expression and
24// a refinement, exposed so `bynk-lsp` hover renders predicates / `where`
25// clauses through the formatter's own logic rather than a copy that could drift.
26pub use bynk_syntax::print::{expr_to_string, refinement_to_string};
27// v0.137.0 (ADR 0161): the storage-annotation renderer, exposed so `bynk-lsp`
28// agent-state hover renders a `store` field's `@indexed`/`@bounded`/… through
29// the formatter's own logic rather than a drift-prone copy.
30pub use fmt::annotation_to_string;
31// v0.166 (#616): the string-literal escaper, exposed for the same reason — an
32// actor's `auth = Scheme(secret = "…")` config holds the *unescaped* value (the
33// parser resolves escapes at lex time), so `bynk-lsp` hover must re-escape it to
34// render valid Bynk, exactly as `format_actor` does. Without it the two renderers
35// agree until the value contains a `"` or a `\`.
36pub use bynk_syntax::print::escape_string;
37
38// #972: the `[fmt]` section of a project's `bynk.toml`, layered under the CLI's
39// own flags by `bynk fmt` and read directly by `bynk-lsp` for
40// format-on-save. One reader for one section — the two front-ends previously
41// had only the language server reading it at all, so a project that set a style
42// there saw the editor and the command line disagree.
43#[cfg(feature = "schema")]
44pub use config::fmt_table_schema;
45pub use config::{ConfigError, FmtConfig, MANIFEST, find_manifest};