Allow semicolons to separate statements - #30
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Statements in a block could only be separated by newlines. This accepts
;as an alternate separator so multiple statements can share a line.Implementation
One change in
parse_block(src/parser.rs): the loop now continues onToken::Semias well asToken::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}. Sinceparse_blockis shared, this covers function bodies,while/forbodies,if/elsebranches, 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 tob, exactly like{ a\n b\n }.Tests
tests/cases/semicolons.lyte— new golden test: multiple statements per line, trailing;, a one-linewhilebody, and semicolons inside a value-returning function. Verified on both the JIT and VM backends.test_parse_blockinsrc/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