mod chars;
pub mod encoding;
mod error;
mod event;
mod event_iter;
pub(crate) mod lexer;
pub mod limits;
mod lines;
pub mod loader;
pub mod node;
mod pos;
pub use error::Error;
pub use event::{Chomp, CollectionStyle, Event, ScalarStyle};
pub use lines::{BreakType, Line, LineBuffer};
pub use loader::{LoadError, LoadMode, Loader, LoaderBuilder, LoaderOptions, load};
pub use node::{Document, Node};
pub use pos::{Pos, Span};
pub use limits::{
MAX_ANCHOR_NAME_BYTES, MAX_COLLECTION_DEPTH, MAX_COMMENT_LEN, MAX_DIRECTIVES_PER_DOC,
MAX_RESOLVED_TAG_LEN, MAX_TAG_HANDLE_BYTES, MAX_TAG_LEN,
};
use std::collections::VecDeque;
use event_iter::{CollectionEntry, DirectiveScope, IterState, PendingAnchor, PendingTag};
use lexer::Lexer;
pub fn parse_events(input: &str) -> impl Iterator<Item = Result<(Event<'_>, Span), Error>> + '_ {
EventIter::new(input)
}
struct EventIter<'input> {
lexer: Lexer<'input>,
state: IterState,
queue: VecDeque<(Event<'input>, Span)>,
coll_stack: Vec<CollectionEntry>,
pending_anchor: Option<PendingAnchor<'input>>,
pending_tag: Option<PendingTag<'input>>,
directive_scope: DirectiveScope,
root_node_emitted: bool,
explicit_key_pending: bool,
property_origin_indent: Option<usize>,
}
impl EventIter<'_> {
const fn collection_depth(&self) -> usize {
self.coll_stack.len()
}
}
pub(crate) const fn empty_scalar_event<'input>() -> Event<'input> {
Event::Scalar {
value: std::borrow::Cow::Borrowed(""),
style: ScalarStyle::Plain,
anchor: None,
tag: None,
}
}
pub(crate) const fn marker_span(marker_pos: Pos) -> Span {
Span {
start: marker_pos,
end: Pos {
byte_offset: marker_pos.byte_offset + 3,
line: marker_pos.line,
column: marker_pos.column + 3,
},
}
}
pub(crate) const fn zero_span(pos: Pos) -> Span {
Span {
start: pos,
end: pos,
}
}