TOML
Lake.Toml is commonly used for configuration files. Lean 4 provides a module for working with Lake.Toml. This chapter covers how to create, manipulate, and persist Lake.Toml data in Lean.
Working with TOML in Lean requires understanding two primary types:
-
Table: This is essentially a map (dictionary) of keys to values. When you parse a TOML string, you get a
Table. -
Value: This is an inductive type that can be a string, integer, boolean, array, or another table.
-
Why Value is important: A
Tablemaps keys to values, but those values could be of any type (a string, then a number, then a nested table). In Lean, a map must have a single type for its values.Valueacts as a "wrapper" or "box" that lets us store different types of data in the sameTable.
-
-
Syntax and .missing: Most TOML types in Lean carry a
Lean.Syntaxobject. This is used to track the exact location of the value in the source file for better error reporting.-
Why .missing is important: When we create TOML values programmatically (not from a file), there is no "source line" to point to. We use
Lean.Syntax.missing(or the shorthand .missing) to satisfy the type system without providing a fake source location.
-
Working with Lake.Toml is not as straightforward as working with Json, but the following sections provide the necessary tools to handle TOML data effectively.