Skip to content

feat(compiler): support continue statement in while and for loops (#39) - #48

Merged
sql-hkr merged 1 commit into
mainfrom
feat/continue-statement
Oct 27, 2026
Merged

sql-hkr merged 1 commit into
mainfrom
feat/continue-statement

Conversation

@sql-hkr

@sql-hkr sql-hkr commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Closes #39

What changed

  • Lexer: Added continue keyword to Lexer.TOKEN_SPEC.
  • AST: Added ContinueStmt(ASTNode) node.
  • Parser: Added parsing for continue; in Parser.parse_stmt.
  • CodeGenerator:
    • Maintained loop_continue_stack: list[str] to track continuation targets.
    • For while loops: target the condition evaluation label (while_start_*).
    • For for loops: create and target a dedicated post-step label (for_post_*) before jumping back to condition evaluation.
    • Supported nested loops cleanly using the label stack.

How tested

  • Added unit tests in tests/test_compiler.py:
    • test_compiler_while_loop_continue: verify continue skips the rest of the loop body and re-evaluates the condition.
    • test_compiler_for_loop_continue: verify continue jumps to the post-step expression (e.g. i++) before re-evaluating the condition.
    • test_compiler_nested_loops_continue_and_break: verify continue and break in nested loops resolve to the correct inner/outer targets.
    • test_compiler_continue_ast_and_lexer: verify tokenization and AST construction of ContinueStmt.
  • uv run pytest: 302 passed (all tests passed).
  • uv run ruff check src/tiny8/compiler.py tests/test_compiler.py: passed.
  • uv run ruff format --check src/tiny8/compiler.py tests/test_compiler.py: passed.

- Add continue keyword to Lexer.TOKEN_SPEC and Parser.parse_stmt
- Add ContinueStmt AST node
- Maintain loop_continue_stack in CodeGenerator
- In while loops, route continue to loop condition evaluation label
- In for loops, route continue to dedicated post-step label before jumping to condition
- Support nested loops cleanly using continue stack
- Add unit tests for while, for, and nested loops continue statements

Closes #39
@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sql-hkr
sql-hkr merged commit 3aa6f4f into main Oct 27, 2026
5 checks passed
@sql-hkr
sql-hkr deleted the feat/continue-statement branch October 27, 2026 15:30
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.

feat(compiler): support continue statement in while and for loops

1 participant