A Rust YAML 1.2 parser that produces a comment-preserving, span-accurate typed AST, designed for building formatters like Prettier.

Stars

14

7-day growth

No data

Forks

0

Open issues

0

License

MIT

Last updated

2026-07-28

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

It mirrors the AST used by Prettier's YAML printer, retains comments and exact byte spans, and is built on a port of libyaml's scanning algorithm, making it a reliable foundation for formatting and tooling.

Who it is for

  • Rust developers building YAML formatters or linters
  • Contributors to Prettier or similar code formatters
  • Toolchain authors needing a syntax-only, span-aware YAML parser
  • Developers migrating from yaml-unist-parser to a Rust ecosystem

Use cases

  • Formatting YAML files with comment preservation and span-accurate transformations
  • Building static analysis tools that inspect YAML structure without value resolution
  • Generating syntax-highlighted YAML output based on exact source spans
  • Testing and validating YAML parsers against standard conformance suites

Strengths

  • Comment-preserving AST with exact byte spans for faithful reconstruction
  • Fail-fast error handling that returns span information on syntax errors
  • High conformance: passes all valid inputs from official yaml-test-suite and Prettier fixtures
  • Lightweight and syntax-only, avoiding schema/tag complexity for focused formatting tasks

Considerations

  • Does not perform schema/tag resolution, anchor/alias handling, or value typing
  • Accepting invalid YAML is a non-goal; errors on invalid inputs are tracked but not strictly rejected
  • Limited to YAML 1.2 and may not cover all edge cases of YAML 1.1 or custom dialects

README quick start

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

Related repositories

Similar projects matched by category, topics, and programming language.

l0ng-ai
Featured
l0ng-ai GitHub avatar

tty7

tty7 is a fast, GPU-accelerated terminal workbench with persistent sessions, built-in input tools, SSH support, and coding agent awareness.

Developer ToolsCLI & Terminal
359
steelbrain
Featured
steelbrain GitHub avatar

reims-vgpu

reims-vgpu is an experimental virtual GPU for macOS guests that uses QEMU to decode the guest's GPU command stream and execute it through Metal or Vulkan, leveraging the built-in AppleParavirtGPU driver without requiring custom kexts.

Desktop Apps
143
m-novotny
Featured
m-novotny GitHub avatar

memguard-rs

A Rust library that provides secure memory handling primitives including zeroization on drop, memory locking, constant-time comparison, and compile-time guarded regions, with zero dependencies and no_std support.

Embedded & IoTSecurity
131