oxc_yaml_parser/lib.rs
1//! oxc-yaml-parser is a YAML 1.2 parser that produces a comment-preserving,
2//! span-faithful typed AST, designed for building formatters.
3//!
4//! The AST mirrors [yaml-unist-parser](https://github.com/prettier/yaml-unist-parser)'s
5//! node shapes (the AST Prettier's YAML printer consumes). Scalar values are
6//! not cooked: consumers slice the original source through spans.
7//!
8//! ## Basic Usage
9//!
10//! ```rust
11//! use oxc_yaml_parser::{Allocator, Parser};
12//!
13//! let allocator = Allocator::default();
14//! let parser = Parser::new(&allocator, "key: value # comment");
15//! match parser.parse() {
16//! Ok(root) => {
17//! assert_eq!(root.children.len(), 1);
18//! assert_eq!(root.comments.len(), 1);
19//! }
20//! Err(error) => {
21//! // Syntax error with span; no partial AST is produced.
22//! println!("{error}");
23//! }
24//! }
25//! ```
26
27pub mod ast;
28mod error;
29mod parser;
30mod pos;
31mod scanner;
32
33pub use error::{Error, ErrorKind};
34pub use oxc_allocator::Allocator;
35pub use parser::Parser;
36pub use pos::Span;
37
38/// Size regression guards, in the spirit of oxc_ast's generated assertions:
39/// enums stay pointer-sized-plus-tag, and hot token types stay small.
40#[cfg(all(test, target_pointer_width = "64"))]
41mod size_asserts {
42 use crate::{ast, scanner};
43
44 #[test]
45 fn sizes() {
46 // Scanner-side: every buffered token pays these.
47 assert_eq!(size_of::<scanner::Token>(), 20);
48 assert_eq!(size_of::<scanner::TokenKind>(), 8);
49 // AST: `Content` is tag + arena Box, and the niche keeps `Option` free.
50 assert_eq!(size_of::<ast::Content>(), 16);
51 assert_eq!(size_of::<Option<ast::Content>>(), 16);
52 // Flow sequence entries: the rare pair variant is boxed so plain
53 // items don't pay for it.
54 assert_eq!(size_of::<ast::FlowSequenceEntry>(), 24);
55 }
56}