021 if arg inspection

✓ Passing This code compiles and runs correctly.

Code

// Test: Inspect ~if argument structure
// Check what fields are populated when parsing ~if(expr)

~import "$std/runtime"


const std = @import("std");

fn inspectFlow(source: []const u8, label: []const u8) void {
    const koru_parser = @import("koru_parser");
    const koru_errors = @import("koru_errors");

    std.debug.print("  Source: {s}\n", .{label});

    var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
    defer arena.deinit();
    const allocator = arena.allocator();

    var reporter = koru_errors.ErrorReporter.init(allocator, "test", source) catch return;
    defer reporter.deinit();

    var parser = koru_parser.Parser.init(allocator, source, "test", &[_][]const u8{}, null) catch return;
    defer parser.deinit();

    const parse_result = parser.parse() catch |err| {
        std.debug.print("  Parse error: {}\n", .{err});
        return;
    };

    for (parse_result.source_file.items) |item| {
        if (item == .flow) {
            const flow = &item.flow;
            const inv = &flow.invocation;

            std.debug.print("  Path: {s}\n", .{inv.path.segments[0]});
            std.debug.print("  Args count: {d}\n", .{inv.args.len});

            for (inv.args, 0..) |arg, i| {
                std.debug.print("  Arg[{d}]:\n", .{i});
                std.debug.print("    .name = '{s}'\n", .{arg.name});
                std.debug.print("    .value = '{s}'\n", .{arg.value});

                if (arg.expression_value) |expr_val| {
                    std.debug.print("    .expression_value = PRESENT\n", .{});
                    std.debug.print("      .text = '{s}'\n", .{expr_val.text});
                } else {
                    std.debug.print("    .expression_value = null\n", .{});
                }
            }
            break;
        }
    }
    std.debug.print("\n", .{});
}

pub fn main() void {
    std.debug.print("\n", .{});
    std.debug.print("╔══════════════════════════════════════════════════════════════╗\n", .{});
    std.debug.print("║     ~if ARGUMENT INSPECTION TEST                             ║\n", .{});
    std.debug.print("╚══════════════════════════════════════════════════════════════╝\n\n", .{});

    // Test 1: Simple boolean
    std.debug.print("Test 1: ~if(true)\n", .{});
    inspectFlow("~if(true)\n| then |> _\n| else |> _", "~if(true)");

    // Test 2: Simple boolean false
    std.debug.print("Test 2: ~if(false)\n", .{});
    inspectFlow("~if(false)\n| then |> _\n| else |> _", "~if(false)");

    // Test 3: Identifier
    std.debug.print("Test 3: ~if(active)\n", .{});
    inspectFlow("~if(active)\n| then |> _\n| else |> _", "~if(active)");

    // Test 4: Comparison expression
    std.debug.print("Test 4: ~if(score > 50)\n", .{});
    inspectFlow("~if(score > 50)\n| then |> _\n| else |> _", "~if(score > 50)");

    // Test 5: Complex expression
    std.debug.print("Test 5: ~if(user.role == \"admin\")\n", .{});
    inspectFlow("~if(user.role == \"admin\")\n| then |> _\n| else |> _", "~if(user.role == \"admin\")");

    std.debug.print("╔══════════════════════════════════════════════════════════════╗\n", .{});
    std.debug.print("║     INSPECTION COMPLETE                                      ║\n", .{});
    std.debug.print("╚══════════════════════════════════════════════════════════════╝\n", .{});
}
input.kz

Test Configuration

MUST_RUN