module

Slang::CrystalScanner

Crystal-aware byte scanner for finding the end of a Crystal expression embedded in Slang source.

The scanner does not parse Crystal -- it tracks bracket nesting and string/char/percent-literal/comment state so the caller can locate a depth-zero terminator. The Crystal compiler validates the resulting expression later.

Used by the Slang lexer at every site that switches into Crystal-expression mode.

Instance methods

scan(source : String, pos : Int32, terminators : String) : Int32

Scans source starting at byte index pos.

Returns the byte index of the first depth-zero occurrence of any byte in terminators, or source.bytesize if no terminator is found.

"Depth zero" means: not inside any string literal, char literal, percent literal, line comment, or bracket nesting.

The returned position points at the terminator byte (the byte is not consumed).

terminators must be ASCII. Newline bytes (0x0A) terminate only if included in terminators.

Source