✓
Passing This code compiles and runs correctly.
Code
// Test: AST dump to JSON
//
// Parses Koru source code and dumps the AST as JSON.
// This enables tools to inspect parsed structure.
//
// Pure Koru - no Zig procs needed!
~import "$std/parser"
~import "$std/io"
const std = @import("std");
// Sample code to parse
const SAMPLE =
\\~event hello {}
\\| done {}
;
// Flow: parse → dump → print (pure Koru!)
~std.parser:parse.source(source: SAMPLE, file_name: "test.kz", allocator: std.heap.page_allocator)
| parsed p |> std.parser:dump.ast(ast: p.ast, allocator: std.heap.page_allocator)
| dumped d |> std.io:print.ln("{{d.json:s}}")
| dump_error e |> std.io:print.ln("Dump error: {{e.message}}")
| parse_error e |> std.io:print.ln("Parse error: {{e.message}}")
Expected Output
{
"module_annotations": [
],
"items": [
{
"type": "event_decl",
"name": "hello",
"path": ["hello"],
"module": "test",
"input": {
"fields": [
]
},
"branches": [
{
"name": "done",
"payload": {
"fields": [
]
}
}
],
"location": {
"file": "test.kz",
"line": 2,
"col": 0
}
}
]
}
Test Configuration
MUST_RUN