Expand description
§Lossless YAML Parser and Editor
A Rust library for parsing and editing YAML files while preserving all whitespace, comments, and formatting. Built with the rowan library for lossless syntax trees.
§Features
- Lossless parsing: Preserves all whitespace, comments, and original formatting
- Editing support: Modify YAML structures while maintaining formatting
- Error recovery: Continues parsing even with syntax errors
- Position tracking: Detailed error locations for debugging
§Example
use yaml_edit::Yaml;
use std::str::FromStr;
let input = r#"
name: my-project
version: 1.0.0
dependencies:
- serde
- tokio
features:
default: []
full:
- "serde"
- "tokio"
"#;
let mut yaml = Yaml::from_str(input).unwrap();
// Access documents
if let Some(doc) = yaml.document() {
if let Some(mapping) = doc.as_mapping() {
// Get values while preserving structure
if let Some(name_node) = mapping.get("name") {
println!("Project name: {}", name_node.text());
}
}
}
// The original formatting is preserved
println!("{}", yaml);A lossless YAML parser and editor.
This library provides a lossless parser for YAML files, preserving all whitespace, comments, and formatting. It is based on the rowan library.
Structs§
- Document
- A single YAML document
- Mapping
- A YAML mapping (key-value pairs)
- Parse
- The result of a parse operation.
- Parse
Error - List of encountered syntax errors.
- Positioned
Parse Error - A positioned parse error containing location information.
- Scalar
- A YAML scalar value
- Scalar
Value - A scalar value with metadata about its style and content
- Sequence
- A YAML sequence (list)
- Text
Range - A range in text, represented as a pair of
TextSize. - Yaml
- A YAML document containing one or more documents
Enums§
- Error
- Error parsing YAML files
- Indentation
- The indentation to use when writing a YAML file.
- Lang
- YAML language type for rowan.
- Scalar
Style - Style of scalar representation in YAML
- Yaml
Value - Represents any YAML value - scalar, sequence, or mapping