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 … := …, anddeclare_syntax_catdeclarations; - terms,
doblocks andcalc; - tactics, including
convandgrindsequences; - 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):
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, orelab_rulesdeclarations, 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… incommand 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 versois 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
.oleanfiles, so Canolean is not a sandbox for untrusted Lean. See SECURITY.md.