Skip to content

Allow semicolons to separate statements - #30

Merged
wtholliday merged 1 commit into
mainfrom
semicolon-statement-separators
Aug 8, 2026
Merged

Allow semicolons to separate statements#30
wtholliday merged 1 commit into
mainfrom
semicolon-statement-separators

Conversation

@wtholliday

Copy link
Copy Markdown
Collaborator

Statements in a block could only be separated by newlines. This accepts ; as an alternate separator so multiple statements can share a line.

main {
    var x = 1; var y = 2; var z = x + y
    while i < 3 { i = i + 1; x = x + i }
}

Implementation

One change in parse_block (src/parser.rs): the loop now continues on Token::Semi as well as Token::Endl.

The lexer already produced Token::Semi — it was used only for array types ([T; N]) and array repeat literals ([x; n]). Those are distinct contexts and are unaffected. A ; is now accepted anywhere a newline was accepted as a separator, including a trailing one before }. Since parse_block is shared, this covers function bodies, while/for bodies, if/else branches, and block expressions.

Semantics are otherwise unchanged: the semicolon is purely a separator, so unlike Rust a trailing one does not void the block's value — { a; b; } still evaluates to b, exactly like { a\n b\n }.

Tests

  • tests/cases/semicolons.lyte — new golden test: multiple statements per line, trailing ;, a one-line while body, and semicolons inside a value-returning function. Verified on both the JIT and VM backends.
  • test_parse_block in src/parser.rs — added { x; y }, { x; }, { x;\n y }, { x = y; z = w }, { var x = y; var z = w; f(x) }, { while x { y; z }; w }.

cargo test --workspace: 351 + 4 + 21 passed, 0 failed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QL98e281ffpSW7JKQyS87C

Statements in a block could only be separated by newlines. Accept `;` as
an alternate separator so multiple statements can share a line.

The lexer already produced Token::Semi for array types (`[T; N]`) and
array repeat literals (`[x; n]`); those are distinct contexts and are
unaffected. A semicolon is now accepted anywhere a newline was, including
trailing before the closing brace. Since parse_block is shared, this
covers function bodies, while/for bodies, if/else branches, and block
expressions.

The semicolon is purely a separator: unlike Rust, a trailing one does not
void the block's value, so `{ a; b; }` still evaluates to `b`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QL98e281ffpSW7JKQyS87C
@wtholliday
wtholliday merged commit e6a6da7 into main Aug 8, 2026
8 checks passed
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.

1 participant