Lex
Menu
On this page

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
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:

SeverityKindCondition detected
errormalformed_tokenUnterminated strings, unknown bytes, or invalid blake3:... hashes.
errorparse_errorSyntax errors reported by lex:parser.
errorduplicate_record_fieldTwo fields with the same name in one record literal.
errorempty_pipe_targetMissing or non-callable right stage after |>.
warningempty_expressionEmpty or comment-only files.
warningunused_bindinglet bindings never referenced by sibling bindings or body.
warningshadowed_bindinglet bindings hiding an enclosing binding or lambda parameter.
warningredundant_parenthesesDouble parentheses ((x)) or single-atom (atom).
warningempty_record, empty_listEmpty {} (except top-level empty pins.lex) or [] literals.