Formatter
lucisv uses a Wadler/Prettier-style document model. Breakable constructs render on one line when they fit and expand predictably when they do not. Comments are attached as trivia and preserved through formatting.
Core style
Section titled “Core style”- 2-space indentation and 100-column lines by default.
- One port, parameter, or connection per line when a header breaks.
- Cuddled block transitions such as
end else begin. - Tight packed dimensions such as
[WIDTH-1:0]and[base+:8]. - At most one preserved blank line between adjacent items.
- Compiler directives, attributes, and supported verbatim constructs keep their source text.
Alignment is inferred
Section titled “Alignment is inferred”lucisv recognizes existing columnar intent in adjacent ANSI ports, named connections, and parameter declarations. If a group is already aligned—or uses four or more spaces where one would suffice—it is normalized as a table. Flush-left input stays flush-left.
Groups end at blank lines, standalone comments, attributes, or compiler directives. If the widest row exceeds the line limit, the entire group falls back to flush-left, never a half-aligned mixture.
Format fences
Section titled “Format fences”Use a standalone fence to protect hand-laid-out regions:
// verilog_format: offlocalparam int A = 1;localparam int LONGER = 22;// verilog_format: on// lucisv: off and // lucisv: on are aliases. Fences preserve exact bytes between items (including class members) and
between statements in blocks, forks, functions, tasks, and procedural bodies.
They also prevent lint fixes there. A fence must begin on its own line;
port/parameter lists, case-label lists, and property/sequence local declarations
do not have independent fence scopes. Fenced text must still parse.
Range formatting
Section titled “Range formatting”--lines selects 1-based inclusive ranges:
lucisv --lines 120-134 rtl/alu.svlucisv --lines 3-9,40 --check rtl/alu.svThe atomic unit is an item: selecting a statement formats its containing always block; selecting a declaration formats that declaration. Everything outside the selected items is emitted byte-for-byte. Ranges require explicit files or stdin, never directories or filelists, and bypass the cache.
Safety invariants
Section titled “Safety invariants”- Parse first. Whole-file formatting produces no output for a file that cannot be fully parsed.
- Preserve meaning. Verification re-lexes input and output and compares normalized tokens, including comments; it does not elaborate the design.
- Converge. Formatting twice reaches the same fixed point.
- Write atomically. An error leaves the affected file untouched.
- Stay deterministic. Parallel worker count changes performance, never output order or exit status.