https://github.com/poppa/pike-libyaml
Pike wrapper for libyaml
https://github.com/poppa/pike-libyaml
libyaml pike yaml
Last synced: about 1 year ago
JSON representation
Pike wrapper for libyaml
- Host: GitHub
- URL: https://github.com/poppa/pike-libyaml
- Owner: poppa
- License: other
- Created: 2017-07-27T18:47:34.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-05T08:16:23.000Z (almost 9 years ago)
- Last Synced: 2025-02-14T03:31:20.059Z (over 1 year ago)
- Topics: libyaml, pike, yaml
- Language: Pike
- Size: 123 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES
- License: LICENSE
Awesome Lists containing this project
README
# pike-libyaml
Pike wrapper for libyaml
## Installation
This module requires `libyaml` to compile. When/if that's installed just run
pike -x module
sudo pike -x module install
## Usage
```pike
mixed data = Parser.YAML.decode_file("path/to/file.yml");
```
Or
```pike
string yml = #"
name: John Doe
age: 42
retired: n
languages:
- Pike
- Python
- Rust
";
mapping data = Parser.YAML.decode(yml);
([ /* 4 elements */
"age": 42,
"languages": ({ /* 3 elements */
"Pike",
"Python",
"Rust"
}),
"name": "John Doe",
"retired": Val.false
])
```
You can also add tag callbacks for application (or generic) tags.
```pike
string yml = #"
key: !to-upper |
This string will be converted
to upper case.
";
mapping data = Parser.YAML.decode(yml, ([
"!to-upper" : lambda (Parser.YAML.EventData e) {
return upper_case(e->value);
}
]));
([ /* 1 element */
"key": "THIS STRING WILL BE CONVERTED\n"
"TO UPPER CASE"
])
```
At the moment the Emitter isn't implemented.