Skip to content

Allow blocks in interpolated string expressions#3503

Open
HABER7789 wants to merge 2 commits into
mainfrom
HABER7789/allow-blocks-in-interpolated-string-expr
Open

Allow blocks in interpolated string expressions#3503
HABER7789 wants to merge 2 commits into
mainfrom
HABER7789/allow-blocks-in-interpolated-string-expr

Conversation

@HABER7789

Copy link
Copy Markdown
Contributor

Allow blocks in interpolated string expressions

Previously the raw lexer tracked interpolation depth with a single u8 counter, which only balanced one level of braces and couldn't handle a { ... } block or a nested interpolation inside ${ ... }. As a result, expressions such as a for loop or a block inside an interpolated string failed to parse.

This change replaces that counter with a Vec<u32> stack that tracks brace depth per interpolation level: { increments the innermost level, } at depth greater than zero closes a block brace, and } at depth zero ends the interpolation. Blocks and nested interpolations now balance correctly, and the old 255-level u8 overflow panic risk is gone.

I also added lexer, parser, and evaluator tests covering blocks, nested blocks, for loops, and an unclosed block.

This PR Fixes #3463.

Example:

function Main() : String {
    let x = 5;
    $"result is { { let y = x + 1; y * 2 } }"   // -> "result is 12"
}

Track interpolation brace depth with a per-level Vec<u32> stack in the
raw lexer instead of a single u8 counter, so blocks and nested
interpolations inside ${ ... } balance correctly. Also removes the old
255-level u8 overflow panic risk.

Fixes #3463
@HABER7789
HABER7789 marked this pull request as ready for review July 22, 2026 22:00
@HABER7789 HABER7789 changed the title allow blocks in interpolated string expressions Allow blocks in interpolated string expressions Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow blocks in interpolated string expressions

1 participant