oxc-yaml-parser 0.0.3

A YAML 1.2 parser that produces a comment-preserving typed AST.
Documentation

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 Err with 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 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.

Conformance

cargo run -p conformance (or just conformance) parses three corpora and snapshots the results under tasks/conformance/snapshots:

  • the official yaml-test-suite (data branch, 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

The scanner derives from libyaml (MIT) by way of saphyr (MIT); their copyright notices are included in LICENSE.

Sponsored By