Formatting & Linting
Content-addressed .lex files benefit from deterministic layout and early structural diagnostics. Both the formatter and static linter live in the freestanding lex:tools package with zero heap allocation and zero ambient I/O.
Canonical formatting (lex fmt)
lex fmt shares the scanner of lex:language so token boundaries match the parser on every string escape, ${...} interpolation, comment, hash literal, and unit suffix.
lex fmt lexicon.lex pins.lex
lex fmt --check lexicon.lex
- Strict idempotence:
lex_format(lex_format(x)) == lex_format(x)for every valid input. - Indentation: 2 spaces per multi-line nesting level (
{ ... },[ ... ],let ... in), plus one continuation indent for lines beginning with|>. - Source field order: record field order stays intact so comments and author grouping never shift. Canonical key sorting happens at evaluator output and in
pins.lex. - Multi-line blocks: a block expands across lines if it holds a comment, contains an existing newline and is non-empty, or exceeds the 100-byte width target. Empty containers collapse to
{},[], and(). - Trailing newline: trailing spaces on every line are stripped, consecutive blank lines collapse to one, and non-empty files end with one
\n.
let
host = "cache.modus.systems",
port = 5010
in
{ host = host, port = port, memory = 64 MiB }
=>
{ host = "cache.modus.systems", memory = 64 MiB, port = 5010 }Static linting (lex lint)
lex lint checks files without running effects and reports path:line:column: severity: kind: message diagnostics in two passes:
| Severity | Kind | Condition detected |
|---|---|---|
error | malformed_token | Unterminated strings, unknown bytes, or invalid blake3:... hashes. |
error | parse_error | Syntax errors reported by lex:parser. |
error | duplicate_record_field | Two fields with the same name in one record literal. |
error | empty_pipe_target | Missing or non-callable right stage after |>. |
warning | empty_expression | Empty or comment-only files. |
warning | unused_binding | let bindings never referenced by sibling bindings or body. |
warning | shadowed_binding | let bindings hiding an enclosing binding or lambda parameter. |
warning | redundant_parentheses | Double parentheses ((x)) or single-atom (atom). |
warning | empty_record, empty_list | Empty {} (except top-level empty pins.lex) or [] literals. |