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 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.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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.