pub struct ContextParser<P> {
pub(crate) parser: P,
pub(crate) contexts: Vec<StringContext>,
}Expand description
A parser that attaches context to the ParseStack in case of an error.
This is our equivalent to winnow’s Context parser.
Fields§
§parser: P§contexts: Vec<StringContext>Trait Implementations§
Source§impl<P: Debug> Debug for ContextParser<P>
impl<P: Debug> Debug for ContextParser<P>
Source§impl<'i, O, P> Parser<LocatingSlice<&'i str>, O, ErrMode<ParseStack<'i>>> for ContextParser<P>
impl<'i, O, P> Parser<LocatingSlice<&'i str>, O, ErrMode<ParseStack<'i>>> for ContextParser<P>
Source§fn parse_next(&mut self, i: &mut Input<'i>) -> PResult<'i, O>
fn parse_next(&mut self, i: &mut Input<'i>) -> PResult<'i, O>
Take tokens from the [
Stream], turning it into the output Read more§fn parse(
&mut self,
input: I,
) -> Result<O, ParseError<I, <E as ParserError<I>>::Inner>>where
Self: Sized,
I: Stream + StreamIsPartial,
E: ParserError<I>,
<E as ParserError<I>>::Inner: ParserError<I>,
fn parse(
&mut self,
input: I,
) -> Result<O, ParseError<I, <E as ParserError<I>>::Inner>>where
Self: Sized,
I: Stream + StreamIsPartial,
E: ParserError<I>,
<E as ParserError<I>>::Inner: ParserError<I>,
§fn parse_iter(&mut self, input: I) -> ParseIter<'_, Self, I, O, E> ⓘwhere
Self: Sized,
I: Stream + StreamIsPartial,
E: ParserError<I>,
<E as ParserError<I>>::Inner: ParserError<I>,
fn parse_iter(&mut self, input: I) -> ParseIter<'_, Self, I, O, E> ⓘwhere
Self: Sized,
I: Stream + StreamIsPartial,
E: ParserError<I>,
<E as ParserError<I>>::Inner: ParserError<I>,
§fn parse_peek(&mut self, input: I) -> Result<(I, O), E>
fn parse_peek(&mut self, input: I) -> Result<(I, O), E>
Take tokens from the [
Stream], turning it into the output Read more§fn by_ref(&mut self) -> ByRef<'_, Self, I, O, E>where
Self: Sized,
fn by_ref(&mut self) -> ByRef<'_, Self, I, O, E>where
Self: Sized,
Treat
&mut Self as a parser Read more§fn default_value<O2>(self) -> DefaultValue<Self, I, O, O2, E>
fn default_value<O2>(self) -> DefaultValue<Self, I, O, O2, E>
Produce a type’s default value Read more
§fn output_into<O2>(self) -> OutputInto<Self, I, O, O2, E>
fn output_into<O2>(self) -> OutputInto<Self, I, O, O2, E>
Convert the parser’s output to another type using
std::convert::From Read more§fn take(self) -> Take<Self, I, O, E>where
Self: Sized,
I: Stream,
fn take(self) -> Take<Self, I, O, E>where
Self: Sized,
I: Stream,
Produce the consumed input as produced value. Read more
§fn with_taken(self) -> WithTaken<Self, I, O, E>where
Self: Sized,
I: Stream,
fn with_taken(self) -> WithTaken<Self, I, O, E>where
Self: Sized,
I: Stream,
Produce the consumed input with the output Read more
§fn span(self) -> Span<Self, I, O, E>where
Self: Sized,
I: Stream + Location,
fn span(self) -> Span<Self, I, O, E>where
Self: Sized,
I: Stream + Location,
Produce the location of the consumed input as produced value. Read more
§fn with_span(self) -> WithSpan<Self, I, O, E>where
Self: Sized,
I: Stream + Location,
fn with_span(self) -> WithSpan<Self, I, O, E>where
Self: Sized,
I: Stream + Location,
Produce the location of consumed input with the output Read more
§fn map<G, O2>(self, map: G) -> Map<Self, G, I, O, O2, E>
fn map<G, O2>(self, map: G) -> Map<Self, G, I, O, O2, E>
Maps a function over the output of a parser Read more
§fn try_map<G, O2, E2>(self, map: G) -> TryMap<Self, G, I, O, O2, E, E2>
fn try_map<G, O2, E2>(self, map: G) -> TryMap<Self, G, I, O, O2, E, E2>
Applies a function returning a
Result over the output of a parser. Read more§fn verify_map<G, O2>(self, map: G) -> VerifyMap<Self, G, I, O, O2, E>
fn verify_map<G, O2>(self, map: G) -> VerifyMap<Self, G, I, O, O2, E>
§fn flat_map<G, H, O2>(self, map: G) -> FlatMap<Self, G, H, I, O, O2, E>
fn flat_map<G, H, O2>(self, map: G) -> FlatMap<Self, G, H, I, O, O2, E>
Creates a parser from the output of this one Read more
§fn and_then<G, O2>(self, inner: G) -> AndThen<Self, G, I, O, O2, E>
fn and_then<G, O2>(self, inner: G) -> AndThen<Self, G, I, O, O2, E>
Applies a second parser over the output of the first one Read more
§fn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>where
Self: Sized,
I: Stream,
O: ParseSlice<O2>,
E: ParserError<I>,
fn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>where
Self: Sized,
I: Stream,
O: ParseSlice<O2>,
E: ParserError<I>,
Apply
std::str::FromStr to the output of the parser Read more§fn verify<G, O2>(self, filter: G) -> Verify<Self, G, I, O, O2, E>
fn verify<G, O2>(self, filter: G) -> Verify<Self, G, I, O, O2, E>
Returns the output of the child parser if it satisfies a verification function. Read more
§fn context<C>(self, context: C) -> Context<Self, I, O, E, C>
fn context<C>(self, context: C) -> Context<Self, I, O, E, C>
If parsing fails, add context to the error Read more
§fn context_with<F, C, FI>(
self,
context: F,
) -> ContextWith<Self, I, O, E, F, C, FI>
fn context_with<F, C, FI>( self, context: F, ) -> ContextWith<Self, I, O, E, F, C, FI>
If parsing fails, dynamically add context to the error Read more
§fn map_err<G, E2>(self, map: G) -> MapErr<Self, G, I, O, E, E2>
fn map_err<G, E2>(self, map: G) -> MapErr<Self, G, I, O, E, E2>
Maps a function over the error of a parser Read more
§fn complete_err(self) -> CompleteErr<Self, I, O, E>where
Self: Sized,
fn complete_err(self) -> CompleteErr<Self, I, O, E>where
Self: Sized,
Transforms [
Incomplete][crate::error::ErrMode::Incomplete] into [Backtrack][crate::error::ErrMode::Backtrack] Read more§fn err_into<E2>(self) -> ErrInto<Self, I, O, E, E2>
fn err_into<E2>(self) -> ErrInto<Self, I, O, E, E2>
Convert the parser’s error to another type using
std::convert::FromAuto Trait Implementations§
impl<P> Freeze for ContextParser<P>where
P: Freeze,
impl<P> RefUnwindSafe for ContextParser<P>where
P: RefUnwindSafe,
impl<P> Send for ContextParser<P>where
P: Send,
impl<P> Sync for ContextParser<P>where
P: Sync,
impl<P> Unpin for ContextParser<P>where
P: Unpin,
impl<P> UnsafeUnpin for ContextParser<P>where
P: UnsafeUnpin,
impl<P> UnwindSafe for ContextParser<P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<'i, O, P> ContextExt<'i, O> for P
impl<'i, O, P> ContextExt<'i, O> for P
Source§fn label(self, label: impl Into<String>) -> ContextParser<Self>
fn label(self, label: impl Into<String>) -> ContextParser<Self>
Set a label that describes what is currently being parsed.
Source§fn expected_char(self, expected: char) -> ContextParser<Self>
fn expected_char(self, expected: char) -> ContextParser<Self>
Add a
char literal to describe what is expected at the failing position.Source§fn expected_chars(
self,
expected: impl IntoIterator<Item = char>,
) -> ContextParser<Self>
fn expected_chars( self, expected: impl IntoIterator<Item = char>, ) -> ContextParser<Self>
Helper function to add multiple chars like
Self::expected_char.Source§fn expected_string(self, expected: &'static str) -> ContextParser<Self>
fn expected_string(self, expected: &'static str) -> ContextParser<Self>
Add a string literal that is expected at the failing position.
Source§fn expected_strings<I>(self, expected: I) -> ContextParser<Self>
fn expected_strings<I>(self, expected: I) -> ContextParser<Self>
Helper function to add multiple strings literals like
Self::expected_string.Source§fn expected_text(self, expected: impl Into<String>) -> ContextParser<Self>
fn expected_text(self, expected: impl Into<String>) -> ContextParser<Self>
Add a free-form text that describes what is expected at the failing position.
Source§fn description(self, description: impl Into<String>) -> ContextParser<Self>
fn description(self, description: impl Into<String>) -> ContextParser<Self>
Add a free-form description of what went wrong at the failing position. Read more