#formatter #tla #plus

libtlafmt

A formatter library for TLA+ specs, core of tlafmt

7 unstable releases (3 breaking)

new 0.4.0 Mar 24, 2025
0.3.2 Mar 17, 2025
0.2.1 Mar 7, 2025
0.2.0 Feb 26, 2025
0.1.0 Feb 23, 2025

#681 in Development tools

Download history 251/week @ 2025-02-23 142/week @ 2025-03-02 259/week @ 2025-03-09 155/week @ 2025-03-16 132/week @ 2025-03-23

702 downloads per month
Used in tlafmt

Apache-2.0

685KB
2.5K SLoC

crates.io docs.rs

A library crate for formatting TLA+ specs.

This crate is the formatter implementation for tlafmt.

Inner Workings

Formatting a TLA file occurs in three phases within this crate:

  1. The input file is parsed into an abstract syntax tree.
  2. The AST is then lowered into a formatter-specific representation.
  3. The format representation is rendered into output text.

Step (1) is performed when calling [ParsedFile::new()] to initialise a new instance, and steps (2) and (3) are performed when [ParsedFile::format()] is called, writing the output to a provided std::io::Write sink.

Testing

Run the tests with:

% cargo test --workspace

Some tests make use of cargo-insta.

In addition to unit tests, a corpus of example TLA specs[^corpus] are formatted and a snapshot of their output generated[^snapshots] after each test run. These snapshots have to be "accepted" using cargo-insta (if their change is desirable) to cause future tests runs to pass.

[^corpus]: A majority sample of the official TLA examples repo - see libtlafmt/tests/corpus/ in the code repo. [^snapshots]: See libtlafmt/tests/snapshots/ in the code repo.

Dependencies

~42MB
~1M SLoC