pub struct ParseStack<'i> {
pub(crate) at: usize,
pub external: Option<Arc<dyn Error + Send + Sync>>,
pub(crate) pending: Vec<StringContext>,
pub(crate) layers: Vec<Layer>,
pub(crate) source: &'i str,
}Expand description
A custom nested and span-aware parser error.
This error type is used across the ALPM project and provides well-formated and detailed parsing
errors. It allows addition of context per layer/type. For more information on the formatting see
the Display impl of ParseStack.
Fields§
§at: usizeByte offset of the deepest failure within the input.
external: Option<Arc<dyn Error + Send + Sync>>An external error, for the case that the final parser failure happened outside of winnow.
pending: Vec<StringContext>The StringContext instances that are not yet captured by a layer boundary.
layers: Vec<Layer>All closed nesting layers, innermost first.
source: &'i strThe full original source text. Required for rendering.
Implementations§
Source§impl<'i> ParseStack<'i>
impl<'i> ParseStack<'i>
Sourcepub(crate) fn close_layer(self, name: String, start: usize) -> Self
pub(crate) fn close_layer(self, name: String, start: usize) -> Self
Moves all pending context calls into a new layer named name.
This is called by the LayerParser in case an error unwinds.
Sourcepub(crate) fn innermost(&self) -> LayerRef<'_>
pub(crate) fn innermost(&self) -> LayerRef<'_>
Returns the innermost layer.
Pending context belongs to the outermost “anonymous” layer that’s not yet named. If no named layer can be found, but there’s some pending context, we return the pending context as an anonymous layer as a fallback.
Sourcepub(crate) fn layer_stack(&self) -> Vec<LayerRef<'_>>
pub(crate) fn layer_stack(&self) -> Vec<LayerRef<'_>>
Returns the stack from outermost to innermost.
Pending context is positioned first as an anonymous outermost layer.
Sourcepub(crate) fn innermost_expected(&self) -> Vec<String>
pub(crate) fn innermost_expected(&self) -> Vec<String>
Returns all “expected” style contexts of the innermost layer that has any.
The layers are searched from the innermost outwards, with pending context being the outermost anonymous layer. If there’s no hit on the innermost layer, we just take the next best layer with such context to at least provide some information to the user.
Returns an empty list if no layer has any “expected” style context.
Sourcepub(crate) fn headline(&self) -> String
pub(crate) fn headline(&self) -> String
Returns the “headline” for the error.
Tries to get the best match available in the following order:
StringContext::Labelname of the innermost layer- Name of first non-anonymous string
- A simple fallback to the static string
"invalid".
Sourcefn anonymous_layer(&self) -> LayerRef<'_>
fn anonymous_layer(&self) -> LayerRef<'_>
Takes the current pending context and return it as an anonymous layer.
Trait Implementations§
Source§impl<'i> AddContext<LocatingSlice<&'i str>, StrContext> for ParseStack<'i>
impl<'i> AddContext<LocatingSlice<&'i str>, StrContext> for ParseStack<'i>
Source§fn add_context(
self,
_input: &Input<'i>,
_token_start: &<Input<'i> as Stream>::Checkpoint,
context: StrContext,
) -> Self
fn add_context( self, _input: &Input<'i>, _token_start: &<Input<'i> as Stream>::Checkpoint, context: StrContext, ) -> Self
Add a new context entry to the current layer.
This provides backwards compatibility with winnow’s Parser::context API.
The StrContext is internally converted to our owned StringContext representation.
Entries are staged inside Self until the current layer is closed.
Source§impl<'i> Clone for ParseStack<'i>
impl<'i> Clone for ParseStack<'i>
Source§fn clone(&self) -> ParseStack<'i>
fn clone(&self) -> ParseStack<'i>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'i> Debug for ParseStack<'i>
impl<'i> Debug for ParseStack<'i>
Source§impl Display for ParseStack<'_>
impl Display for ParseStack<'_>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Displays this parse error.
The rendered output is structured into three visual sections:
- A headline with the innermost available label context.
- A source snippet with an underline spanning from beginning of the innermost named layer up to the exact failing character. Any expected literals are shown next to the caret.
- A footer that provides error context from outermost to innermost layers.
Named layers are rendered with their parser name and a mini source preview:
error: invalid package release
|
1 | foo-1:1.0.0-bar-any
| ^ expected positive decimal integer
|
= while parsing:
installed package name: (foo-1:1.0.0-bar-any)
└ alpm-package-version: (1:1.0.0-bar-any)
│ → an alpm-package-version (full or full with epoch) followed by a `-` and an alpm-architecture
└ alpm-pkgrel: (bar-any)
→ invalid package release
→ A freeform description over here
→ expected positive decimal integerPending context that has not yet unwound past a named layer is rendered as an anonymous outermost layer:
= while parsing:
→ alpm-package file name
→ a package name, followed by an alpm-package-version...
└ installed package name: (foo-1:1.0.0_any)Color output is controlled globally via [colored::control] (for example via
[colored::control::set_override]).
Source§impl Error for ParseStack<'_>
impl Error for ParseStack<'_>
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl<'i, E: Error + Send + Sync + 'static> FromExternalError<LocatingSlice<&'i str>, E> for ParseStack<'i>
impl<'i, E: Error + Send + Sync + 'static> FromExternalError<LocatingSlice<&'i str>, E> for ParseStack<'i>
Source§fn from_external_error(input: &Input<'i>, e: E) -> Self
fn from_external_error(input: &Input<'i>, e: E) -> Self
ParserError::from_input] but also include an external error.Source§impl<'i> ParserError<LocatingSlice<&'i str>> for ParseStack<'i>
impl<'i> ParserError<LocatingSlice<&'i str>> for ParseStack<'i>
Source§fn or(self, other: Self) -> Self
fn or(self, other: Self) -> Self
When handling multiple parsing branches (alt), keep the failure that reached further into
the input.
Source§type Inner = ParseStack<'i>
type Inner = ParseStack<'i>
Self Read moreSource§fn from_input(input: &Input<'i>) -> Self
fn from_input(input: &Input<'i>) -> Self
Source§fn into_inner(self) -> Result<Self::Inner, Self>
fn into_inner(self) -> Result<Self::Inner, Self>
§fn incomplete(input: &I, _needed: Needed) -> Self
fn incomplete(input: &I, _needed: Needed) -> Self
§fn append(self, _input: &I, _token_start: &<I as Stream>::Checkpoint) -> Self
fn append(self, _input: &I, _token_start: &<I as Stream>::Checkpoint) -> Self
ParserError::from_input] but merges it with the existing error. Read more§fn is_backtrack(&self) -> bool
fn is_backtrack(&self) -> bool
§fn is_incomplete(&self) -> bool
fn is_incomplete(&self) -> bool
Needed] Read more