8 releases (4 breaking)

0.5.2 Apr 13, 2024
0.5.1 Apr 13, 2024
0.4.0 Mar 26, 2024
0.3.0 Feb 7, 2024
0.1.0 Jan 31, 2020

#367 in Parser implementations

Download history 200/week @ 2024-01-08 180/week @ 2024-01-15 108/week @ 2024-01-22 63/week @ 2024-01-29 221/week @ 2024-02-05 129/week @ 2024-02-12 114/week @ 2024-02-19 156/week @ 2024-02-26 138/week @ 2024-03-04 57/week @ 2024-03-11 45/week @ 2024-03-18 83/week @ 2024-03-25 403/week @ 2024-04-01 45/week @ 2024-04-08

586 downloads per month
Used in 2 crates

MIT license

2.5K SLoC

Marked YAML

This library builds atop yaml-rust to provide a YAML AST which includes the marks for where the YAML data comes from. It explicitly operates at a low level, providing only the base safe YAML types (i.e. the vanilla tags tag:yaml.org,2002:seq, tag:yaml.org,2002:map, and tag:yaml.org,2002:str)

The subset of YAML which is supported is quite deliberately limited in order that users of this crate will implicitly discourage complex use of YAML which is harder to manage user expectations with. As an example, the mapping type in this crate explicitly only permits scalars as keys, and since all scalars are treated as strings, mappings always have string keys.

The primary value of this kind of representation of YAML data is to allow applications which want to be very explicit about where input came from an opportunity to do this in a way which normal YAML parsers do not allow.

Using Marked YAML

Currently this library only supports loading YAML from strings, but this is sufficient for most users' purposes. We would not recommend an un-streamed processing engine for massive data anyway.

To load some YAML you simply need to:

let node = marked_yaml::parse_yaml(0, r#"
toplevel: must be a mapping
 - it
 - may
 - contain lists
 mappings: are permitted
 as: sub-mappings

Parsing a valid YAML file may fail because marked_yaml adds some additional constraints:

  • The top level of the YAML MUST be a mapping.
  • Mapping keys MUST be scalars (strings).
  • Aliases and anchors MAY NOT be used (though this limit may be lifted in the future).

In addition, you can convert between marked_yaml::Node and yaml_rust::Yaml though doing so will not give you any useful markers.


~153K SLoC