oxc-yaml-parser
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.
Example
use ;
let allocator = default;
let parser = new;
let root = parser.parse.unwrap;
println!;
More examples are available in examples.
Conformance
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.
License
MIT