Documentation
¶
Overview ¶
Package format re-indents SysML v2 / KerML source text.
The formatter works on the token stream rather than on the AST. Printing an AST back to text would drop everything the AST does not model — comments, notes, and any construct the parser records as an ErrorNode — so a formatter built that way cannot safely be pointed at a user's file. Working on tokens keeps every lexeme and only rewrites the whitespace between them.
The rules are deliberately conservative: line breaks the author wrote are preserved, so by default the formatter never joins or splits a line. It fixes indentation, trailing whitespace, runs of blank lines, and the padding just inside brackets and before separators. A line that continues the statement above it — the author broke a declaration or expression across lines — is indented one level deeper than that statement, so it still reads as a continuation rather than as a new statement. Line endings are emitted in the document's own dominant style, so a CRLF file stays CRLF throughout.
Options.BreakStatements adds line breaks (one statement per line) for text generated without them; even then no line is ever joined.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ConvertOptions = Options{IndentWidth: 4, BreakStatements: true}
ConvertOptions are DefaultOptions with BreakStatements: what a conversion to notation and the editor's formatting write, since their input may be generated text with no line breaks.
var DefaultOptions = Options{IndentWidth: 4}
DefaultOptions matches the indentation used by the models in examples/.
var ErrNotIdempotent = errors.New("format: rewrite would change the token stream")
ErrNotIdempotent reports that formatting would have changed the token stream. It signals a bug in the formatter, never bad input: callers should present the source unchanged rather than a mangled file.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// IndentWidth is the number of columns per nesting level (default 4).
IndentWidth int
// UseTabs indents with one tab per level instead of spaces.
UseTabs bool
// BreakStatements lays each statement of a body out on its own line; a body
// without statements, an expression body and an end-of-line note stay put.
BreakStatements bool
}
Options controls the emitted indentation.