A minimalist, zero-copy parser for a strict subset of the YAML specification.
The full YAML specification is quite complex and includes features such as aliases, anchors, and type inference which are non-trivial to parse and resolve. For some use cases, those features are overkill and the associated overhead is undesirable. In its barest form, YAML (arguably) boils down to a clean way to represent a structure of sequences and mappings. This crate aims to support this simple use-case.
Supports YAML input consisting of only sequences and mappings. No type inference is performed, with all literal values being captured as string slices. Sequences may be in flow style
[such, as, this, sequence]
or in block style
- laid
- out
- like
- this
Similarly, mappings may be in flow style
{with : the, mapping : inline}
or in block style
spread : across
multiple : lines
Of course, sequences and mappings may be nested, and any valid YAML element can be a key or value, so for example
[this, is] :
-
- totally
- valid
- input
- {to : the parser}
In accordance with the crate's goal of minimalism, the public API consists of one main structure: enum Yaml<'a>
and one main function: pub fn parse<'a>(input: &'a str) -> Result<Yaml<'a>>
Caveat: The following is based on fairly limited benchmarking performed on a single machine using inputs of various sizes
A side benefit of keeping the parser as simple as possible is that minimal-yaml performs better than existing, full-featured parsers. In comparison with the fully spec compliant parser yaml-rust, minimal-yaml consistently performs 3-5x better (i.e. parsing takes 1/3 to 1/5 of the time of yaml-rust).
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted 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