YAML
Module yaml
import yaml
| Module | yaml |
| Source | yaml/attributes.zirr, yaml/module-docs.zirr, yaml/yaml.zirr |
YAML over the same value tree as JSON.
yaml reads and writes the same native tree json does — prelude.Dict, prelude.Array, String, Int, Float, Bool and void — so the two formats are interchangeable as far as your own types are concerned.
parseAll is the one addition: a YAML file may hold several documents separated by ---, and it returns all of them.
Pass this module to coding to encode and decode your own data types through it; the attributes below override @coding’s for YAML only.
Contents
- Attributes —
Decode,Default,Encode,Ignore,Name - Functions —
format,formatIndented,parse,parseAll
Attributes
Decode
`yaml/attributes.zirr:20`
attr Decode {
parse
}
Decodes a field from its raw YAML tree, overriding @coding.Decode.
Fields
| Field | Description |
|---|---|
parse |
fn(raw: Any) -> Result. |
Default
`yaml/attributes.zirr:14`
attr Default {
value
}
The value a field takes when its YAML key is absent, overriding @coding.Default.
Fields
| Field | Description |
|---|---|
value |
The value to use. |
Encode
`yaml/attributes.zirr:26`
attr Encode {
format
}
Encodes a field to a YAML tree, overriding @coding.Encode.
Fields
| Field | Description |
|---|---|
format |
fn(value: Any) -> Result. |
Ignore
`yaml/attributes.zirr:11`
attr Ignore
Marks a field as one that does not travel as YAML, overriding @coding.Ignore.
Name
`yaml/attributes.zirr:5`
attr Name {
text
}
The YAML key a field is read and written under, overriding @coding.Name for YAML only.
coding finds these by name, so declaring them here is all it takes for them to win.
Fields
| Field | Description |
|---|---|
text |
The key to use. |
Functions
format
`yaml/yaml.zirr:11`
extern fn format(value: Any) -> Result
Renders a native tree as YAML text, indented by two spaces.
formatIndented
`yaml/yaml.zirr:14`
extern fn formatIndented(value: Any, indent: Int) -> Result
As format, indented by a given number of spaces.
parse
`yaml/yaml.zirr:5`
extern fn parse(text: String) -> Result
Reads one YAML document into the native tree: a mapping is a Dict, a sequence an Array, and null is void.
A stream holding several documents is an Err, since that is not one value; use parseAll for those.
parseAll
`yaml/yaml.zirr:8`
extern fn parseAll(text: String) -> Result
Reads every document in a stream, in order.