uce/site/doc/pages/yaml_decode.txt

58 lines
1.5 KiB
Plaintext

:sig
DTree yaml_decode(String s)
:params
s : YAML source string
return value : decoded DTree
:see
>markup
yaml_encode
json_decode
xml_decode
0_DTree
:content
Parses a practical YAML subset into a `DTree`.
`yaml_decode()` is designed for concise UCE config files. It intentionally avoids full YAML schema behavior and does not support anchors, aliases, tags, directives, or complex inline collection syntax.
Try the live example in the [YAML demo](../demo/yaml.uce).
Example:
```uce
String source = "app:\n"
" name: UCE Starter\n"
" debug: true\n"
" port: 8080\n"
" paths:\n"
" - site\n"
" - cache\n";
DTree cfg = yaml_decode(source);
cfg["app"]["name"].to_string(); // UCE Starter
cfg["app"]["debug"].to_bool(); // true
cfg["app"]["port"].to_s64(); // 8080
cfg["app"]["paths"]["1"].to_string(); // cache
```
Supported syntax:
- indentation-based maps
- indentation-based lists
- `key: value` map entries
- list entries with `- value`
- quoted strings with single or double quotes
- booleans `true` and `false`
- empty/null-ish values as empty strings
- comments beginning with `#` outside quoted strings
- literal block strings with `|`
- folded block strings with `>`
- optional `---` and `...` document markers
Numeric-looking values are stored as strings, matching `json_decode()`'s current behavior. Use `to_s64()`, `to_u64()`, or `to_f64()` when reading numeric config values.
Malformed input raises a request-visible `yaml_decode(): ...` runtime error.