class

Hecr::Compiler::Formatter

Inherits Reference < Object

Source formatter for the hecr dialect (hecr format).

The governing rule is HEEx's: NEVER change rendering. Children are re-indented ("reflowed") only when every sibling is block-safe — elements, components, EEx statements, comments, or whitespace-only text. Any non-blank text, {...} interpolation, or <%= %> among the children makes the whole group "tight": reproduced exactly as written (only the inside of tags — attribute spacing — is normalized, which HTML rendering cannot observe).

Normalizations (documented in docs/dialect.md §13): two-space indent; special attributes print first (:if, :for, :key, :let); void and self-closing tags print as <br />; default-slot content prints before named slot entries; multiple blank lines collapse to one.

Constants

INDENT = " "
INLINE_ELEMENTS = Set {"a", "abbr", "acronym", "audio", "b", "bdi", "bdo", "big", "br", "button", "canvas", "cite", "code", "content", "data", "datalist", "del", "dfn", "em", "embed", "i", "iframe", "img", "input", "ins", "kbd", "label", "map", "mark", "meter", "noscript", "object", "output", "picture", "progress", "q", "ruby", "s", "samp", "select", "slot", "small", "span", "strong", "sub", "sup", "svg", "template", "textarea", "time", "u", "tt", "var", "video", "wbr"}

HEEx's inline-element list (whitespace around these renders), plus the <content/> builtin whose substituted content is unknowable.

NO_FORMAT_ATTR = "hecr-no-format"
VERBATIM_ELEMENTS = Set {"pre", "textarea", "script", "style"}

Constructors

new(line_length : Int32)
Source

Class methods

format(source : String, file : String = "nofile", line_length : Int32 = 98) : String
Source

Instance methods

reflow(io, nodes : Array(AST::Node), indent : Int32) : Nil
Source
reflowable?(nodes : Array(AST::Node)) : Bool

Children may be re-indented only when doing so cannot change rendering: no non-blank text or output expressions among them, and any INLINE element is already whitespace-separated on both sides in the source (reflow only normalizes whitespace that is already there).

Source
tight(io, nodes : Array(AST::Node)) : Nil
Source