This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/17/2026.
Yaml
import std/yamlKoru Standard Library: std/yaml — YAML documents into the std/json
yaml.kz · 2 tors
Koru Standard Library: std/yaml — YAML documents into the std/json · 26 more lines
Koru Standard Library: std/yaml — YAML documents into the std/json
document model. Rides the libyaml lift: same `requires.system` +
`@cImport` + phantom-obligation shape libs/yaml proved (the
winnow/pcre2 precedent — a measured host library instead of a
hand-built parser).
`std/yaml:parse` streams libyaml's events and assembles each document
into `std.json.Value` nodes in an arena — the SAME node type
`std/json:dom` navigates. A parsed YAML document takes every `dom.*`
tor: `dom.root`, `dom.val` (typed descent), `dom.at`/`dom.idx`,
`dom.each` (`! field`/`! item`), `dom.len`, `dom.render` (→ `-o=json`
for free), `dom.free` (the arena obligation). Multi-document streams
fire `! doc` per document — each `<open!>` obligation is discharged
inside its arm.
CORE SCHEMA (the assay's bound): mapping keys arrive as plain text
(a non-scalar key is `malformed`), plain scalars resolve to
null/bool/int/float/string (quoted scalars stay string), standard
`!!` tags resolve, unknown tags keep raw text, anchors and aliases
REFUSE — `malformed` — rather than silently expanding a graph into
a tree.
`std/yaml:emit` serializes a node subtree to block YAML (2-space
indent, JSON-style double-quoting for strings that would re-resolve
otherwise), minting `string<emitted!>` discharged by
`std/json:emit.free`.
Phantom lifecycles
Derived from the phantom labels in the declarations below — state! issues an
obligation the compiler will chase, !state discharges it, a bare state holds it without moving it. Nothing here is hand-drawn.
string 3 states allocated!emitted!Document 1 state open!JsonNode carries the label <*> with no obligation attached — a dimension, not a lifecycle.
// Parse YAML text; each document in the stream fires `! doc` as an
// owned `*Document<open!>` — the identical handle `std/json:dom.parse`
// yields, discharged by `std/json:dom.free`. `malformed` carries an
// allocated diagnostic (libyaml's problem text + position), disposed
// by `std/io:free`.
~pub tor parse { input: string<*> }
! doc std/json:*Document<open!>
| done usize
| malformed string<std.io:allocated!>// Serialize a node subtree as block YAML — `string<emitted!>`, same
// obligation `std/json:dom.render` mints, discharged by
// `std/json:emit.free`.
~pub tor emit { n: std/json:*JsonNode<*> } -> string<std.json:emitted!>