// SafeC Standard Library — YAML serialization (block style subset), built
// on std/serial/value.h the same way json.h/csv.h/xml.h/html.h are.
//
// Supported: block scalars (plain, single-quoted '...' with '' escaping,
// double-quoted "..." with \" \\ \n \t \r \t escapes), block sequences
// ('- item' per line, including the compact '- key: value' list-of-maps
// shorthand), block mappings ('key: value' per line, indentation-nested),
// flow collections on one line ('[a, b]', '{k: v, n: [1, 2]}', nested,
// with quoted or plain items), literal and folded block scalars ('|' / '>',
// with '-' strip / '+' keep chomping), '#' comments (at the line start or
// after whitespace, outside quotes — 'a#b' is a plain scalar), and the
// null/bool/int/float scalar forms YAML 1.1 core schema recognizes
// (~/null, true/false, plain integers and floats).
//
// NOT supported (out of scope for this module — a full YAML 1.2 processor
// is a much larger undertaking): flow collections spanning several lines,
// anchors & aliases ('&name' / '*name'), tags ('!!str'), multi-document
// streams ('---' separators), and merge keys ('<<:'). A document using any
// of these either parses as plain scalar text (least-surprise fallback —
// an unterminated '[...' stays a string) or fails — see yaml_parse's 'ok'
// contract.
#pragma once
#include <std/serial/value.h>
#include <std/collections/string.h>
namespace std {
// Appends v's YAML text representation to 'out' (does not clear 'out'
// first). Only VAL_NULL/VAL_BOOL/VAL_INT/VAL_FLOAT/VAL_STRING/VAL_ARRAY/
// VAL_OBJECT are meaningful — same value tree json_write accepts.
void yaml_write(const &Value v, &String out);
// Convenience wrapper: a fresh String holding just v's YAML text.
struct String value_to_yaml(const &Value v);
// Parses a block-style YAML document (see the file-level comment for the
// supported subset). On success, '*ok' (if non-NULL) is set to 1; on a
// structural error (inconsistent indentation, unterminated quoted scalar,
// a line that's neither a valid sequence/mapping entry nor a bare scalar
// where one is expected), '*ok' is set to 0 and the return value is
// whatever was parsed before the error.
struct Value yaml_parse(const &char text, ?&int ok);
// The YAML backend as a Format (see value.h): v.encode(Yaml::new()),
// Value::decode(Yaml::new(), text, &ok) — the same as yaml_write / yaml_parse.
struct Yaml {
int unused_;
static struct Yaml new();
void write(const &Value v, &String out) const;
struct Value parse(const &char text, ?&int ok) const;
};
} // namespace std