class

Sheety::CodeGenerator

Inherits Sheety::AST < Reference < Object

Generates Crystal code from Excel formula AST

The generated code is designed to be used in procs that:

  1. Read cell values from Croupier's k/v store
  2. Calculate the formula result
  3. Return the result as a string for storage

Instance methods

fetch_expression_for(param : ReferenceParam) : String

Render the concrete fetch expression for a reference parameter, suitable for a task's call site. Mirrors the concrete CellRef/RangeRef rendering.

Source
generate(node : Node, context : Context = Context.new) : String

Generate Crystal code for an AST node

Source
generate_parameterized(node : Node, sheet : String | Nil = nil) : String

Generate a parameterized expression where each reference leaf (CellRef, RangeRef, NamedRef) is replaced by a positional parameter (p0, p1, ...). Two formulas with the same structure but different cells produce identical parameterized expressions. Used to build shared helper bodies.

Source
param_declaration(param : ReferenceParam, index : Int32) : String

The Crystal parameter declaration (name + type) for a reference parameter, used in the shared helper's signature.

Source
reference_params(node : Node, sheet : String | Nil = nil) : Array(ReferenceParam)

The ordered list of reference leaves in the AST (CellRef / RangeRef / NamedRef), in the same left-to-right depth-first order the parameterized generator assigns parameter indices. Each entry carries enough info to build the concrete fetch call for a given cell's call site. The optional sheet is used to resolve bare references (those without an explicit sheet prefix), mirroring how the concrete generator and dependency extractor resolve them.

Source
shape_key(node : Node) : String

A stable structural key for a formula. Two formulas whose ASTs differ only in concrete cell/range/named references share the same key; differences in operators, function names, arity, or literal values produce different keys. Used to group formulas for shared-helper extraction. Returns a hex SHA1 of the canonical structural string.

Source

Nested types