granit_parser/lib.rs
1// Copyright 2015, Yuheng Chen.
2// Copyright 2023, Ethiraric.
3// See the LICENSE file at the top-level directory of this distribution.
4
5//! YAML 1.2 parser implementation in pure Rust.
6//!
7//! `granit-parser` is a low-level event parser. It reads YAML input and yields a stream of
8//! [`Event`] values paired with their source [`Span`].
9//!
10//! Add it to your project:
11//!
12//! ```sh
13//! cargo add granit-parser
14//! ```
15//!
16//! # Usage
17//!
18//! ```rust
19//! use granit_parser::{Event, Parser};
20//!
21//! # fn main() -> Result<(), granit_parser::ScanError> {
22//! let yaml = "items:\n - milk\n - bread\n";
23//!
24//! for next in Parser::new_from_str(yaml) {
25//! let (event, _span) = next?;
26//! if let Event::Scalar(value, ..) = event {
27//! println!("{value}");
28//! }
29//! }
30//! # Ok(())
31//! # }
32//! ```
33//!
34//! # Features
35//! **Note:** This crate's MSRV is `1.81.0`.
36//!
37//! #### `debug_prints`
38//! Enables the `debug` module and usage of debug prints in the scanner and the parser. Do not
39//! enable if you are consuming the crate rather than working on it as this can significantly
40//! decrease performance. Output remains opt-in behind a local compile-time toggle in
41//! `src/debug.rs`.
42//!
43//! This feature does not raise the MSRV further.
44//!
45//! This feature is _not_ `no_std` compatible.
46
47#![forbid(unsafe_code)]
48#![warn(missing_docs, clippy::pedantic)]
49#![no_std]
50
51#[macro_use]
52extern crate alloc;
53
54#[cfg(feature = "debug_prints")]
55extern crate std;
56
57mod char_traits;
58#[macro_use]
59mod debug;
60pub mod input;
61mod parser;
62/// A stack-based parser implementation.
63pub mod parser_stack;
64mod scanner;
65
66pub use crate::input::{str::StrInput, BorrowedInput, BufferedInput, Input};
67pub use crate::parser::{Event, EventReceiver, Parser, ParserTrait, SpannedEventReceiver, Tag};
68pub use crate::scanner::{Marker, ScalarStyle, ScanError, Scanner, Span, Token, TokenType};