Skip to content
achamayouPublic

About

Canonical Lean source formatting in Rust with frontend-relative Aeneas proofs

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Canolean: canonical Lean 4 formatter

A canonical source formatter for Lean 4, written in Rust with no external dependencies and verified with Aeneas against Canolean/CanonicalLeanSource.lean. Given the same imports and syntax, two files with the same tokens and comments always format to the exact same output, regardless of how they were originally laid out.

Canolean only formats syntax it can handle safely. If a file uses unsupported syntax, it fails with an error instead of guessing.

Note

Canolean is experimental (0.x). While formatting is canonical within a release, the canonical format itself may still change before 1.0, and across future major releases.

Build and run

Requires Rust 1.88+ and Lean 4.36.0 (pinned in lean-toolchain, providing lean and leanc).

cargo build --offline --release
cargo install --offline --path .
canolean examples/Basic.lean
printf 'def  answer:=42' | canolean
canolean --check --bundled-only path/to/lean
canolean --in-place --bundled-only --ext verso path/to/lean

Output of canolean examples/Basic.lean:

/-- A binary tree carrying values at its leaves. -/
inductive Tree (α : Type) where
  | leaf (value : α)
  | node (left right : Tree α)
deriving Repr

def Tree.size : Tree α → Nat
  | .leaf _ => 1
  | .node l r => l.size + r.size

def Tree.mirror : Tree α → Tree α
  | .leaf x => .leaf x
  | .node l r => .node r.mirror l.mirror

theorem Tree.size_mirror (t : Tree α) : t.mirror.size = t.size := by
  induction t with
    | leaf x =>
      rfl
    | node l r ihl ihr =>
      simp [mirror, size, ihl, ihr]
      exact Nat.add_comm r.size l.size

Documentation

  • Getting started: requirements, build and first runs.
  • Command line: modes, options, imports, exit status, errors and runtime lookup.
  • Scope and limits: supported syntax, coverage of Lean 4.36.0 and microsoft/CCF, and refusals.
  • Extensions: the Extension trait and the built-in Verso extension.
  • Performance: benchmarks against leanfmt and memory use.
  • How it works: the steps from parsing to layout choice, and the terms they use.
  • Verification: the theorem, the verified code and its assumptions.
  • Tests: the test suites, the corpus checks, and what CI enforces.

Contributing

See CONTRIBUTING.md for development setup, test commands, and proof verification instructions.

License

Licensed under the MIT License.

About

Canonical Lean source formatting in Rust with frontend-relative Aeneas proofs

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages