Scope and limits

Supported syntax

Most built-in Lean 4 syntax:

  • module headers and imports;
  • declarations (def, theorem, inductive, structure, class, instance, mutual, …);
  • in-file infix/prefix/postfix/notation, syntax, syntax … := …, and declare_syntax_cat declarations;
  • terms, do blocks and calc;
  • tactics, including conv and grind sequences;
  • comments;
  • project-imported syntax via --lean-path / --lake, with on-demand grammar extraction;
  • Verso documentation comments via --ext verso.

Coverage

This is enough to format the specification itself, all 159 Lean files of a pinned microsoft/CCF snapshot, and 81.6% of Lean 4.36.0’s own sources in core mode (83.8% with --ext verso, including 96.8% of Std and 92.7% of Init):

Certified coverage across corpora: microsoft/CCF 100.0% (159/159), Std 95.4% core / 96.8% with --ext verso (482/498), Init 87.1% core / 92.7% with --ext verso (618/667), Lake 82.5% core / 86.7% with --ext verso (144/166), Lean 73.0% core / 73.6% with --ext verso (921/1,251), Lean 4.36.0 total 81.6% core / 83.8% with --ext verso (2,165/2,582) Certified coverage across corpora: microsoft/CCF 100.0% (159/159), Std 95.4% core / 96.8% with --ext verso (482/498), Init 87.1% core / 92.7% with --ext verso (618/667), Lake 82.5% core / 86.7% with --ext verso (144/166), Lean 73.0% core / 73.6% with --ext verso (921/1,251), Lean 4.36.0 total 81.6% core / 83.8% with --ext verso (2,165/2,582)

With --ext verso, every remaining refused file in Std (16) and Init (49) is a metaprogramming file (macro, macro_rules, syntax quotations/antiquotations, dynamicQuot, or command-generating macros).

Not supported

  • macro, macro_rules, elab, or elab_rules declarations, syntax quotations and antiquotations, and calling custom commands declared earlier in the same file. If any active syntax rule in scope can’t be extracted into a supported grammar skeleton, the file is refused even if it never uses that syntax.
  • Lake or project-local imports unless you pass --lean-path, --lake, or --bundled-only.
  • set_option, attribute, some … in command forms, and executable commands like #eval (unless you pass --bundled-only, which parses them without running them).
  • Verso documentation comments under doc.verso, unless --ext verso is enabled.
  • Inputs or formatted outputs larger than 1,048,576 UTF-8 bytes.
  • Any syntax whose layout rules can’t be derived or verified — for example, where the grammar doesn’t explain why Lean parsed the input the way it did. The error message names the failing rule.

Refusals

Files outside the supported syntax fail with exit status 2 and no output:

$ printf '#eval 1 + 1\n' | canolean
canolean: unsupported: unsupported command Lean.Parser.Command.eval; grammar-changing and executable commands are not admitted
Error message How to handle it
parse: … unknown module prefix … Pass --lake or --lean-path to load the import, or --bundled-only to skip loading it.
unsupported command Lean.Parser.Command.set_option, …eval, or other executable commands Pass --bundled-only.
syntax node Lean.Parser.Command.versoCommentBody Pass --ext verso.
unsupported command Lean.Parser.Command.macro or other metaprogramming declarations Not supported.

Options

Canolean sees Lean’s default options and any set_option commands inside the file itself. Options set on the Lean command line or in a lakefile are not seen. In particular, doc.verso changes how Lean parses documentation comments (making them column-sensitive markup), so files that enable it need --ext verso.

Untrusted input

Warning: Loading imports runs module initialization code in those .olean files, so Canolean is not a sandbox for untrusted Lean. See SECURITY.md.