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//! ## Basic Usage
5//!
6//! ```rust
7//! use oxc_yaml_parser::{Allocator, Parser};
8//!
9//! let allocator = Allocator::default();
10//! let parser = Parser::new(&allocator, "key: value # comment");
11//! match parser.parse() {
12//! Ok(root) => {
13//! assert_eq!(root.children.len(), 1);
14//! assert_eq!(root.comments.len(), 1);
15//! }
16//! Err(error) => {
17//! // Syntax error with span; no partial AST is produced.
18//! println!("{error}");
19//! }
20//! }
21//! ```
22
23pub mod ast;
24mod error;
25mod parser;
26mod pos;
27mod scanner;
28
29pub use error::{Error, ErrorKind};
30pub use oxc_allocator::Allocator;
31pub use parser::Parser;
32pub use pos::Span;
33
34/// Size regression guards, in the spirit of oxc_ast's generated assertions:
35/// enums stay pointer-sized-plus-tag, and hot token types stay small.
36#[cfg(all(test, target_pointer_width = "64"))]
37mod size_asserts {
38 use crate::{ast, scanner};
39
40 #[test]
41 fn sizes() {
42 // Scanner-side: every buffered token pays these.
43 assert_eq!(size_of::<scanner::Token>(), 20);
44 assert_eq!(size_of::<scanner::TokenKind>(), 8);
45 // AST: `Content` is tag + arena Box, and the niche keeps `Option` free.
46 assert_eq!(size_of::<ast::Content>(), 16);
47 assert_eq!(size_of::<Option<ast::Content>>(), 16);
48 // `Node` adds the span and props on top of the content.
49 // Node-position fields box it so container children stay small (guarded below).
50 assert_eq!(size_of::<ast::Node>(), 48);
51 assert_eq!(size_of::<ast::MappingItem>(), 56);
52 assert_eq!(size_of::<ast::SequenceItem>(), 16);
53 // Flow sequence entries: both variants boxed, two words total.
54 assert_eq!(size_of::<ast::FlowSequenceEntry>(), 16);
55 }
56}