Skip to main content

Crate rdlfmt

Crate rdlfmt 

Source
Expand description

A formatter for SystemRDL.

source text
    |
    v  syntax              lossless CST, comments and all
    v  rules               one function per node kind
    v  formatter           whitespace, then alignment
    v  String

§No document IR

Pretty-printers usually build a document IR (Wadler, Oppen) because their line breaks depend on rendered width. None here do: following the PeakRDL style guide, braces always break, statements are one per line, expressions never break, and a parameter list breaks when it holds more than one element. All of that is decidable from the tree alone. Only column alignment needs hindsight, and it runs once every line break is final.

§What the formatter will not do

Reformat a file the parser did not fully understand: format() returns FormatError when the parse reports errors, because rewriting a file whose structure was guessed at is how a formatter corrupts code.

Preprocessor directives, conditionals included, are trivia: each keeps its own line, and a conditional is flush left. A `ifdef whose branches trade a brace leaves the braces unbalanced, and so is refused like any other parse error. See crate::syntax::parser for why ignoring a conditional cannot corrupt the file.

Modules§

syntax
A lossless syntax tree for SystemRDL.

Enums§

FormatError
Why no formatted output was produced.

Functions§

format
Formats SystemRDL source.