module

Hecr::Compiler::ExprScanner

Boundary detection and validation for Crystal expressions embedded in templates, built on Crystal's OWN lexer/parser (spike 05). Brace matching is therefore correct for all of Crystal's syntax: strings containing braces, string interpolation, %-literals, char literals, nested braces. (HEEx uses naive depth counting and breaks on {"}"}.)

Instance methods

find_closing_brace(source : String) : Int32

source begins right AFTER the opening {. Returns the byte offset (within source) of the matching }.

Source
split_generator(code : String) : Tuple(String, String) | Nil

Splits a :for value of the form pattern <- enumerable at the first top-level <-. Returns {pattern, enumerable} or nil when there is no generator arrow. <- is hecr dialect syntax (not Crystal), so the split happens token-wise: an OP < immediately followed (byte-adjacent) by an OP - at bracket depth zero.

Source
validate(code : String) : Crystal::SyntaxException | Nil

Validates that code is syntactically valid Crystal. Returns nil when valid, or the SyntaxException (with line/column relative to code).

Source

Nested types