Lex
Menu
On this page

CLI & Embedding

The standalone lex binary evaluates, formats, lints, and checks .lex files directly from the command line, and every underlying package in src/ embeds cleanly without external dependencies.

Command-line reference

CommandAction
lex eval <file> [field_path] [--json]Evaluates a .lex file in pure declaration mode; prints Lex notation or lossless JSON projection.
lex eval -e <expr> [field_path] [--json]Evaluates an inline Lex expression without creating a temporary file.
lex fmt [--check] <file>...Formats files canonically in place, or exits with status 1 under --check if any file differs.
lex lint <file>...Runs static token and AST diagnostics and exits with status 1 on any finding.
lex check <file>...Runs fmt --check, lint, and pure declaration evaluation on each file.
lex versionPrints the lex version.
lex --helpDisplays usage and command summary.

Global styling option --color=auto|always|never controls semantic ANSI output; auto emits plain text when piped or when NO_COLOR is set.

Lossless JSON projection (--json)

Host tools such as jq read evaluated Lex values through lex eval --json. The projection is total and injective: records, lists, strings, booleans, and IEEE-754 exact integers within ±(253 - 1) map to native JSON, while every other kind uses a single $-prefixed tag key that no Lex field name can collide with.

{
  host   = "cache.modus.systems",
  memory = 64 MiB,
  mode   = .Verify,
  limit  = 9007199254740992,
}
json =>{"host":"cache.modus.systems","limit":{"$integer":"9007199254740992"},"memory":{"$integer":"64","$unit":"MiB"},"mode":{"$member":"Verify"}}
Lex valueJSON form
Record, List, Text, BooleanNative JSON object (keys sorted by UTF-8 bytes), array, string, boolean
Integer within ±9007199254740991Native JSON number
Integer past ±9007199254740991{"$integer":"<decimal>"}
Integer with unit{"$integer":"<decimal>","$unit":"<unit>"}
Member / Flag set{"$member":"Name"} / {"$flag_set":["Read","Write"]}
Hash / Module / Tree{"$hash":"blake3:..."} / {"$module":"blake3:..."} / {"$tree":"blake3:..."}
Store / Recipe / Described{"$store":...} / {"$recipe":...} / {"$described":{"value":...,"description":...}}
Plan / Lexicon{"$plan":{...}} / {"$lexicon":{...}}

Embedding the freestanding packages

Pass -collection:lex=src to Odin to import any standalone package directly: