✓
Passing This code compiles and runs correctly.
Code
// ============================================================================
// TEST: Pattern Branches Parser Support
// ============================================================================
// Verifies that the parser correctly handles [...] pattern branch syntax.
// Pattern branches allow opaque expressions as branch names for DSL transforms.
//
// The [...] content is passed through as the branch name - transforms interpret it.
// ============================================================================
// Simple event to test pattern branches
~event test_patterns {}
| ok
~proc test_patterns {
return .{ .ok = .{} };
}
// Test that pattern branches parse correctly
// The branch names are [GET /users/:id] etc - opaque to the compiler
~test_patterns()
| [GET /users/:id] |> ok {}
| [POST /users] |> ok {}
| [nested [brackets] work] |> ok {}
| [* -> stopped] |> ok {} // State machine style
| ok |> _ // Normal branch still works
// Verify nested patterns work
~test_patterns()
| [/admin/*] |>
test_patterns()
| [GET /dashboard] |> ok {}
| ok |> _
| ok |> _
Error Verification
Expected Error Pattern
Pattern branches without a transform produce KORU021 errors.
This test verifies that pattern branch SYNTAX parses correctly.
The validation correctly rejects unknown branches like [GET /users/:id]
when the event only declares 'ok'.
Expected errors:
- KORU021: unknown branch '[GET /users/:id]'
- KORU021: unknown branch '[POST /users]'
- etc.Actual Compiler Output
error[KORU021]: event 'input:test_patterns' has no branch '[GET /users/:id]' (available: ok)
--> structural_check:21:0
error[KORU021]: event 'input:test_patterns' has no branch '[POST /users]' (available: ok)
--> structural_check:21:0
error[KORU021]: event 'input:test_patterns' has no branch '[nested [brackets] work]' (available: ok)
--> structural_check:21:0
error[KORU021]: event 'input:test_patterns' has no branch '[* -> stopped]' (available: ok)
--> structural_check:21:0
❌ Compiler coordination error: Incomplete branch coverage
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/200_COMPILER_FEATURES/210_PARSER/210_052_pattern_branches/backend.zig:9523:17: 0x1009fe4af in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/200_COMPILER_FEATURES/210_PARSER/210_052_pattern_branches/backend.zig:9607:28: 0x1009ff2b7 in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Test Configuration
MUST_FAIL