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
| Command | Action |
|---|---|
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 version | Prints the lex version. |
lex --help | Displays 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 value | JSON form |
|---|---|
| Record, List, Text, Boolean | Native JSON object (keys sorted by UTF-8 bytes), array, string, boolean |
Integer within ±9007199254740991 | Native 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:
lex:parser— compact 16-byte SoA syntax tree and interner (parse_console,parse_declaration).lex:evaluator— bytecode compiler, lazy thunk-graph VM, query cache, and canonical serializer.lex:tools— caller-buffered canonical formatter (lex_format) and static linter (lex_lint_with_storage).lex:metadata— offline SPDX license expression parser and lexicon metadata validator.lex:pins— canonicalpins.lexreader and sorted text writer.lex:output— canonical binary declaration output reader/writer and domain-separated recipe hasher.