oxc-yaml-parser parses YAML 1.2 into a comment-preserving, span-faithful typed AST, designed for building formatters.
- The AST mirrors yaml-unist-parser's node shapes — the AST Prettier's YAML printer consumes.
- Scalar values are not cooked: consumers slice the original source through spans.
- Comments are retained as trivia with exact spans.
- Syntax-only: no schema/tag resolution, no anchor/alias resolution, no value typing.
- Fail-fast: a syntax error returns
Errwith a span; no partial AST is produced.
The scanner is a port of the libyaml scanning algorithm (by way of saphyr), adapted to byte-offset spans and trivia retention.
use oxc_yaml_parser::{Allocator, Parser};
let allocator = Allocator::default();
let parser = Parser::new(&allocator, "key: value # comment");
let root = parser.parse().unwrap();
println!("{root:#?}");More examples are available in examples.
cargo run -p conformance (or just conformance) parses three corpora and snapshots the results under tasks/conformance/snapshots:
- the official yaml-test-suite (
databranch, including its invalid-input cases), - Prettier's YAML format fixtures,
- local edge fixtures covering Prettier's input-acceptance tolerances.
All valid inputs in all three corpora parse successfully. Rejecting invalid YAML is a non-goal; outcomes on invalid inputs are tracked in the snapshots for review.
MIT
The scanner derives from libyaml (MIT) by way of saphyr (MIT); their copyright notices are included in LICENSE.