This library contains language-agnostic formatting capabilities, including representations useful for formatting algorithms.
PreFormatToken is a markup layer over a token stream that annotates each token with InterTokenInfo that influences formatting (e.g. minimum spacing between tokens).
FormattedToken is similar, but represents the result of formatting, after analysis and transformations have completed and decisions have been bound.
FormatTokenRange is an iterator range over an array of PreFormatTokens.
UnwrappedLine represents an indentable unit of formatting and contains a FormatTokenRange and indentation information.
TokenPartitionTree is a language-agnostic hierarchical representation of subranges of tokens and text. The data nodes of this tree are UnwrappedLines. From any language-specific text and structural representation, producing a language-agnostic TokenPartitionTree will gain access to a wide variety of formatting functions.
Don't mutate text/syntax tree data structures, present a form that looks like a mutation and render it. What the formatting functions do is produce annotated scaffoling over the original representation that, when printed to stream, produces the same effect as having mutated the original form. By treating the orignal representation as read-only, this strategy allows one to easily explore multiple formatting subsolutions.