class

Hecr::Compiler::Codegen

Inherits Reference < Object

Generates Crystal code from a template AST. The emitted code appends to an IO variable; expressions are wrapped in #<loc:...> pragmas so compile errors and runtime backtraces point into the template (spike 02 / D9).

Constants

APPEND_OP = " <" + "< "

The append operator as a constant: a literal " << " inside a << chain trips a crystal-tool-format lexing bug, so it is assembled here.

CONTENT_ELEMENT = "content"

Reserved built-in element: <content/> renders the default slot (yield); <content {value}/> passes values to the caller's :let.

IO_NAME = "__hecr_io__"
METHOD_TOKEN = /\A[a-z_][a-zA-Z0-9_]*\z/
NON_METHOD_TOKENS = Set {"abstract", "alias", "annotation", "as", "asm", "begin", "break", "case", "class", "def", "do", "else", "elsif", "end", "ensure", "enum", "extend", "false", "for", "fun", "if", "in", "include", "instance_sizeof", "is_a", "lib", "macro", "module", "next", "nil", "of", "offsetof", "out", "pointerof", "private", "protected", "require", "rescue", "responds_to", "return", "select", "self", "sizeof", "struct", "super", "then", "true", "type", "typeof", "uninitialized", "union", "unless", "until", "verbatim", "when", "while", "with", "yield", "to_h"}

Tokens whose mangled name the styles modules expose only via ["name"]: Crystal keywords plus the conventional to_h.

Constructors

new(source : String, file : String, loc_file : String, line_offset : Int32, annotate : Bool = false, component_name : Nil | String = nil, styles_const : Nil | String = nil)
Source

Class methods

embed_body(source : String, file : String, loc_file : String, line_offset : Int32, io_name : String, annotate : Bool = false, styles_const : String | Nil = nil) : String

Statements appending to an existing IO variable (Hecr.embed).

Source
render_expression(source : String, file : String, loc_file : String, line_offset : Int32, annotate : Bool = false, component_name : String | Nil = nil, styles_const : String | Nil = nil) : String

A single expression evaluating to Hecr::Safe (used by Hecr.render and Hecr.template, and as the body of embed_templates defs).

Source

Instance methods

generate(io_name : String) : String

When -Dhecr_annotate is set (spike 10), rendered output gains HTML comments marking template boundaries and component call sites, like HEEx's debug_heex_annotations — but switched by a compile flag instead of config + forced recompile (decision D11).

Source
static_bytes
Source