Formatter.Logical
The logical stage's entry point: build the Logical Printing Tree from a
parsed module. The AST walk itself lives in Formatter.Logical.MakeLogical
(lptFromAst); this module runs it and applies the finishing passes.
makeLogicalPrintingTree :
Module -> Context -> Result String LPNode
Build the Logical Printing Tree for a parsed module.
The pipeline runs in five stages:
lptFromAst(inFormatter.Logical.MakeLogical) walks theSrc.Moduleand emits oneOriginalRowschild per top-level declaration, in source order.Formatter.Logical.Comments.lptAddCommentsweaves in comment nodes from the parseCtx.Context, as siblings of the declarations they belong to.Formatter.Logical.SortSymbols.sortSymbolsreorders the symbols inside everyexposing ( ... )list into elm-format's three groups -- operators, then types/unions, then plain values, alphabetically within each -- carrying each symbol's attached comments along with it.importstatements themselves are left in source order. Runs after comments are attached, never before -- see that module's docs for why.Formatter.Logical.VerticalSpace.insertFlowBlankLineswalks the whole tree once, insertingEmptyLinesiblings betweenletbindings, beforeelse/else if, and before a comment betweenwhencases.Formatter.Logical.VerticalSpace.insertEmptyLinesinsertsEmptyLinesiblings to normalise blank-line spacing between top-level declarations.
Only stage 1 can fail; the later stages are total. An Err from lptFromAst
comes back wrapped in "Failed to create intermediate representation for pretty
printing: ", so the caller can tell which stage produced it. The resulting
LPNode is the input to Formatter.Render.