2024-12-25 02:47:09 +00:00
|
|
|
# NOTICE
|
|
|
|
|
|
|
|
this repository is a rebase of the `master` branch onto the `serde` branch of the saphyr rust crate.
|
|
|
|
|
|
|
|
nothing novel has been added to this repository. all updates and actual value can be found at its [actual home](https://github.com/saphyr-rs/saphyr).
|
|
|
|
|
|
|
|
this repository will remain available until the serde functionality is merged into master upstream.
|
|
|
|
|
|
|
|
the original readme follows this notice. the license claims below are as such for this repository as well.
|
|
|
|
|
2024-10-12 14:29:33 +00:00
|
|
|
# Saphyr libraries
|
2015-05-28 17:56:03 +00:00
|
|
|
|
2024-10-12 14:29:33 +00:00
|
|
|
This repository is home to `saphyr-parser`, `saphyr` and soon-to-be
|
|
|
|
`saphyr-serde`. These crates provide fully YAML 1.2 compliant parsing and
|
|
|
|
manipulation, with a focus on correctness, performance and API friendliness (in that order).
|
2024-03-25 00:00:19 +00:00
|
|
|
|
2024-10-12 14:29:33 +00:00
|
|
|
[`saphyr`](https://docs.rs/saphyr/latest/saphyr/) is the most user-friendly and
|
|
|
|
high-level crate, providing quick-and-easy YAML importing, exporting and object
|
|
|
|
manipulation.
|
2015-05-28 17:56:03 +00:00
|
|
|
|
2024-10-12 14:29:33 +00:00
|
|
|
```rs
|
2024-12-08 09:21:26 +00:00
|
|
|
use saphyr::{Yaml, YamlEmitter};
|
2015-05-30 17:58:39 +00:00
|
|
|
|
2024-12-08 09:21:26 +00:00
|
|
|
let docs = Yaml::load_from_str("[1, 2, 3]").unwrap();
|
2024-10-12 14:29:33 +00:00
|
|
|
let doc = &docs[0]; // select the first YAML document
|
|
|
|
assert_eq!(doc[0].as_i64().unwrap(), 1); // access elements by index
|
2015-05-30 17:58:39 +00:00
|
|
|
|
2024-10-12 14:29:33 +00:00
|
|
|
let mut out_str = String::new();
|
|
|
|
let mut emitter = YamlEmitter::new(&mut out_str);
|
|
|
|
emitter.dump(doc).unwrap(); // dump the YAML object to a String
|
2015-06-04 08:39:53 +00:00
|
|
|
```
|
|
|
|
|
2024-10-12 14:29:33 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
[`saphyr-parser`](https://docs.rs/saphyr-parser/latest/saphyr_parser/) is the
|
|
|
|
parser behind `saphyr`. It provides direct access to the parsing process by
|
|
|
|
emitting [YAML
|
|
|
|
events](https://docs.rs/saphyr-parser/latest/saphyr_parser/parser/enum.Event.html).
|
|
|
|
It does not include YAML to object mapping, but is a lightweight alternative to
|
|
|
|
`saphyr` for those interested in building directly atop the parser, without
|
|
|
|
having an intermediate conversion to a Rust object. More details on where to
|
|
|
|
start are available [on
|
|
|
|
doc.rs](https://docs.rs/saphyr-parser/latest/saphyr_parser/parser/trait.EventReceiver.html).
|
|
|
|
|
|
|
|
```rs
|
|
|
|
/// Sink of events. Collects them into an array.
|
|
|
|
struct EventSink {
|
|
|
|
events: Vec<Event>,
|
2015-05-30 17:58:39 +00:00
|
|
|
}
|
|
|
|
|
2024-10-12 14:29:33 +00:00
|
|
|
/// Implement `on_event`, pushing into `self.events`.
|
|
|
|
impl EventReceiver for EventSink {
|
|
|
|
fn on_event(&mut self, ev: Event) {
|
|
|
|
self.events.push(ev);
|
|
|
|
}
|
|
|
|
}
|
2023-08-19 14:41:51 +00:00
|
|
|
|
2024-10-12 14:29:33 +00:00
|
|
|
/// Load events from a yaml string.
|
|
|
|
fn str_to_events(yaml: &str) -> Vec<Event> {
|
|
|
|
let mut sink = EventSink { events: Vec::new() };
|
|
|
|
let mut parser = Parser::new_from_str(yaml);
|
|
|
|
// Load events using our sink as the receiver.
|
|
|
|
parser.load(&mut sink, true).unwrap();
|
|
|
|
sink.events
|
|
|
|
}
|
|
|
|
```
|
2023-08-19 14:41:51 +00:00
|
|
|
|
2015-05-28 17:56:03 +00:00
|
|
|
## Specification Compliance
|
|
|
|
|
2024-10-12 14:29:33 +00:00
|
|
|
This implementation is fully compatible with the YAML 1.2 specification.
|
|
|
|
`saphyr-parser`) tests against (and passes) the [YAML test
|
|
|
|
suite](https://github.com/yaml/yaml-test-suite/).
|
2024-03-20 06:34:17 +00:00
|
|
|
|
2016-01-11 04:53:19 +00:00
|
|
|
## License
|
|
|
|
|
2024-10-12 14:29:33 +00:00
|
|
|
Sets of licences are available for each of the crates. Due to this project
|
|
|
|
being based on a fork of [chyh1990's
|
|
|
|
`yaml-rust`](https://github.com/chyh1990/yaml-rust), there are 2 licenses to be
|
|
|
|
included if using `saphyr` or `saphyr-parser`. Refer to the projects' READMEs
|
|
|
|
for details.
|
2024-02-08 06:12:14 +00:00
|
|
|
|
2015-05-30 17:58:39 +00:00
|
|
|
## Contribution
|
|
|
|
|
2024-04-02 16:49:52 +00:00
|
|
|
[Fork this repository](https://github.com/saphyr-rs/saphyr/fork) and
|
|
|
|
[Create a Pull Request on Github](https://github.com/saphyr-rs/saphyr/compare/master...saphyr-rs:saphyr:master).
|
2024-03-25 00:00:19 +00:00
|
|
|
You may need to click on "compare across forks" and select your fork's branch.
|
2016-01-11 04:53:19 +00:00
|
|
|
|
|
|
|
Unless you explicitly state otherwise, any contribution intentionally submitted
|
2024-02-08 06:12:14 +00:00
|
|
|
for inclusion in the work by you, as defined in the Apache-2.0 license, shall
|
|
|
|
be dual licensed as above, without any additional terms or conditions.
|
2024-03-25 00:00:19 +00:00
|
|
|
|
|
|
|
## Links
|
2024-10-12 14:29:33 +00:00
|
|
|
### `saphyr`
|
|
|
|
* [saphyr source code repository](https://github.com/saphyr-rs/saphyr/tree/master/saphyr)
|
2024-04-02 16:49:52 +00:00
|
|
|
* [saphyr releases on crates.io](https://crates.io/crates/saphyr)
|
|
|
|
* [saphyr documentation on docs.rs](https://docs.rs/saphyr/latest/saphyr/)
|
2024-03-25 00:00:19 +00:00
|
|
|
|
2024-10-12 14:29:33 +00:00
|
|
|
### `saphyr-parser`
|
|
|
|
* [saphyr-parser source code repository](https://github.com/saphyr-rs/saphyr/tree/master/parser)
|
2024-04-02 16:49:52 +00:00
|
|
|
* [saphyr-parser releases on crates.io](https://crates.io/crates/saphyr-parser)
|
2024-10-12 14:29:33 +00:00
|
|
|
* [saphyr-parser documentation on docs.rs](https://docs.rs/saphyr-parser/latest/saphyr-parser/)
|
2024-03-25 00:00:19 +00:00
|
|
|
|
2024-10-12 14:29:33 +00:00
|
|
|
### Other links
|
2024-03-25 00:00:19 +00:00
|
|
|
* [yaml-test-suite](https://github.com/yaml/yaml-test-suite)
|
2024-10-12 14:29:33 +00:00
|
|
|
* [YAML 1.2 specification](https://yaml.org/spec/1.2.2/)
|