Initial Commit

This commit is contained in:
SoraKatadzuma committed 2026-12-06 13:12:06 -06:00
commit 5577896856
1624 files changed
+43436

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
# std::yaml
`std::yaml` reads and writes YAML for Sakura, as YAML 1.2.2 writes it, by its
core schema: a plain scalar is empty, a boolean, an integer, a float, or text by
how it is written, and a quoted or block scalar is always text. `yaml::parse`
reads a stream of documents into a `yaml::document`, keeping each value's line,
tag, and every key a mapping repeats; `yaml::reader` gives one event at a time,
and `yaml::writer` writes YAML in block style as it is given it. A value whose
type marks its fields with `@serial` is written as YAML and read back by those
marks, over `std::serial`. Limits on depth and aliases stop text written to
exhaust a reader.
## Using it
Require the standard library in your blossomfile, and name the module among a
target's `deps`, with the other modules of std it reads:
```yaml
requires:
- https://git.malunal.studio/sakura/std@v1.0.0
targets:
- name: app
type: program
deps: [std.yaml, std.io]
```
```sakura
import std::io;
import std::yaml;
def main(): void {
val read := yaml::parse("name: sakura\nstars: 5\n") else (_) {
io::println("That isn't YAML.");
return;
};
if read.root.get("name") is some(name) {
if name.as_text() is value(text) {
io::println(text);
}
}
}
```
## Testing
From the standard library's root, where the conformance test finds its suite,
`blossom test --suite std.yaml` runs them, or:
```sh
sakurac run --lib std=. tests/main.sakura tests/yaml/*.sakura
```
The conformance test reads the YAML test suite's cases, in `tests/yaml/suite`, under
its MIT license. The tests compare what YAML's documents hold with the JSON the suite
gives, so they read `std::json` too.