alpm_parsers/error/mod.rs
1//! This module provides a custom winnow error type that keeps track of nested context and spans.
2//!
3//! [`ParseStack`] keeps a stack of nested layers (one per [`LayerParser`])
4//! together with the span positions that were being parsed.
5//!
6//! The error type requires the usage of winnow's [`LocatingSlice`], which allows our errors to be
7//! span-aware.
8//!
9//! [`LayerParser`]s are created by using the [`LayerExt`] trait.
10//!
11//! Context messages are attached via the [`ContextExt`] functions.
12//!
13//! Winnow's [`Parser::context`] with [`StrContext`] is supported as well for backwards
14//! compatibility. Once migrated, this backwards compatibility will be phased out.
15//!
16//![`Parser::context`]: winnow::Parser::context
17//![`StrContext`]: winnow::error::StrContext
18
19mod context;
20mod context_parser;
21mod layer;
22mod layer_parser;
23mod parse_stack;
24mod render;
25
26pub use context_parser::{ContextExt, ContextParser};
27pub use layer_parser::{LayerExt, LayerParser};
28pub use parse_stack::ParseStack;
29use winnow::{LocatingSlice, ModalResult};
30
31/// A convenience type alias around LocatingSlice.
32pub type Input<'i> = LocatingSlice<&'i str>;
33
34/// Return type alias for parsers that uses the ParseStack error type.
35pub type PResult<'i, T> = ModalResult<T, ParseStack<'i>>;