6 releases
0.1.5 | Dec 14, 2020 |
---|---|
0.1.4 | Dec 12, 2020 |
0.1.2 | Jul 13, 2020 |
#1780 in Parser implementations
52KB
1.5K
SLoC
minimal-yaml
A minimalist, zero-copy parser for a strict subset of the YAML specification.
Motivation
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.
Use
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>>
Performance
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).
License
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.
Contribution
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