009 source with scope capture

✓ Passing This code compiles and runs correctly.

Code

// ============================================================================
// VERIFIED REGRESSION TEST - DO NOT MODIFY WITHOUT DISCUSSION
// ============================================================================
// Test: Source with Captured Continuation Bindings
// Feature: Source parameters capture continuation bindings in their scope
// Verifies: Scope capture for template metaprogramming
// ============================================================================

~import "$std/io"

// Event that provides user data
~event getUserData { }
| data { name: []const u8, age: i32 }

~proc getUserData {
    return .{ .data = .{ .name = "Alice", .age = 42 } };
}

// Event that takes Source parameter for HTML rendering
~event renderHTML { source: Source[HTML] }
| rendered { html: []const u8 }

// Comptime proc that receives Source with captured scope
~proc renderHTML {
    // For now, just verify syntax works and return hardcoded HTML
    // In the future, source.scope.bindings will contain the captured 'u' binding
    return .{ .rendered = .{ .html = "<div>Captured binding in scope!</div>" } };
}

// Test: Source block with new syntax
// NOTE: Continuation pipeline Source blocks (| data u |> renderHTML [HTML]{ })
// are not yet supported - that requires extending parsePipelineSteps to handle [Type]{ } syntax
// For now, test that the new syntax works at module level
~renderHTML [HTML]{
    <div>
        <h1>Module-level test</h1>
        <p>Syntax validated</p>
    </div>
}
| rendered h |> std.io:println(text: h.html)
input.kz

Expected AST

{
  "module_annotations": [],
  "items": [
    {
      "type": "import_decl",
      "path": "$std/compiler",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 2,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 2,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 3,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 4,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 5,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 6,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 7,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 8,
        "col": 0
      }
    },
    {
      "type": "import_decl",
      "path": "$std/io",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 11,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 12,
        "col": 0
      }
    },
    {
      "type": "event_decl",
      "name": "getUserData",
      "path": [
        "getUserData"
      ],
      "module": "input",
      "input": {
        "fields": []
      },
      "branches": [
        {
          "name": "data",
          "payload": {
            "fields": [
              {
                "name": "name",
                "type": "[]const u8",
                "is_source": false,
                "is_file": false,
                "is_embed_file": false,
                "is_expression": false,
                "is_invocation_meta": false
              },
              {
                "name": "age",
                "type": "i32",
                "is_source": false,
                "is_file": false,
                "is_embed_file": false,
                "is_expression": false,
                "is_invocation_meta": false
              }
            ]
          }
        }
      ],
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 15,
        "col": 0
      }
    },
    {
      "type": "proc_decl",
      "event_name": "getUserData",
      "path": [
        "getUserData"
      ],
      "module": "input",
      "target": "zig",
      "inline_flows": [],
      "is_pure": false,
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 19,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 20,
        "col": 0
      }
    },
    {
      "type": "event_decl",
      "name": "renderHTML",
      "path": [
        "renderHTML"
      ],
      "module": "input",
      "input": {
        "fields": [
          {
            "name": "source",
            "type": "Source[HTML]",
            "is_source": true,
            "is_file": false,
            "is_embed_file": false,
            "is_expression": false,
            "is_invocation_meta": false
          }
        ]
      },
      "branches": [
        {
          "name": "rendered",
          "payload": {
            "fields": [
              {
                "name": "html",
                "type": "[]const u8",
                "is_source": false,
                "is_file": false,
                "is_embed_file": false,
                "is_expression": false,
                "is_invocation_meta": false
              }
            ]
          }
        }
      ],
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 23,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 24,
        "col": 0
      }
    },
    {
      "type": "proc_decl",
      "event_name": "renderHTML",
      "path": [
        "renderHTML"
      ],
      "module": "input",
      "target": "zig",
      "inline_flows": [],
      "is_pure": false,
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 30,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 31,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 32,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 33,
        "col": 0
      }
    },
    {
      "type": "host_line",
      "module": "input",
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 34,
        "col": 0
      }
    },
    {
      "type": "flow",
      "invocation": {
        "event": [
          "renderHTML"
        ],
        "args": [
          {
            "name": "source",
            "value": "<div>\n    <h1>Module-level test</h1>\n    <p>Syntax validated</p>\n</div>\n",
            "source_value": {
              "text": "<div>\n    <h1>Module-level test</h1>\n    <p>Syntax validated</p>\n</div>\n",
              "location": {
                "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
                "line": 42,
                "col": 0
              },
              "scope": {
                "bindings": []
              },
              "phantom_type": "HTML"
            }
          }
        ],
        "variant": null
      },
      "continuations": [
        {
          "branch": "rendered",
          "binding": "h",
          "binding_type": "branch_payload",
          "step": {
            "type": "invocation",
            "invocation": {
              "event": [
                "println"
              ],
              "args": [
                {
                  "name": "text",
                  "value": "h.html"
                }
              ],
              "variant": null
            }
          },
          "continuations": []
        }
      ],
      "pre_label": null,
      "post_label": null,
      "location": {
        "file": "tests/regression/200_COMPILER_FEATURES/210_PARSER/210_009_source_with_scope_capture/input.kz",
        "line": 35,
        "col": 0
      }
    }
  ]
}

Test Configuration

PARSER_TEST