Documentation
¶
Overview ¶
Package mfmt is m-cli's AST-preserving M source formatter (spec §3.1). It folds in vista-meta's mfmt as one formatter over the m-parse syntax tree.
Model: edits-over-source. Each rule emits byte-span Edits guided by the parse tree; the edits are applied to the original bytes. The default (no rules) is identity — unformatted input is returned byte-for-byte, so the round-trip is exact and formatting is opt-in (mirrors the Python m-cli's identity default + canonical layer). Rules are written to be AST-preserving; SameShape verifies that parse(format(src)) has the same tree shape as parse(src).
Index ¶
Constants ¶
This section is empty.
Variables ¶
Presets is the set of recognized preset names (for the CLI enum).
Functions ¶
func Format ¶
Format parses src, runs the rules, and applies their edits. With no rules it returns src unchanged (identity) without parsing.
func SameShape ¶
SameShape reports whether two trees have the same structure — same node types and named-ness, recursively, with the same child counts — ignoring byte positions and token text. It is the AST-preserving check: a formatting rule is safe iff parse(format(src)) is SameShape as parse(src).
Types ¶
type Preset ¶
type Preset string
Preset is a named bundle of rules. identity (default) is a no-op so formatting is opt-in; canonical is the SAC-leaning baseline. More presets (pythonic, pythonic-lower, compact, sac) follow as the rule set grows.
type Rule ¶
Rule is one formatting transform: given the source and its parsed root, it returns the byte-span edits it wants applied.
type UppercaseCommandKeywords ¶
type UppercaseCommandKeywords struct{}
UppercaseCommandKeywords uppercases every command keyword token (set→SET, w→W). AST-preserving: only the letters inside command_keyword tokens change, so the parse-tree shape is unaffected.
func (UppercaseCommandKeywords) Edits ¶
func (UppercaseCommandKeywords) Edits(src []byte, root parse.Node) []Edit
Edits implements Rule.
func (UppercaseCommandKeywords) Name ¶
func (UppercaseCommandKeywords) Name() string
Name implements Rule.