PBind

Struct PBind 

Source
pub struct PBind<P, O1, O2> { /* private fields */ }
Expand description

A parser combinator that applies a transformation function to the result of a parser.

This is useful for mapping parsed values into a new representation, such as converting a parsed string into an integer, or wrapping a result in a custom enum.

§Type Parameters

  • P: The inner parser
  • O1: The output type of the inner parser P
  • O2: The output type after applying the transformation function

Trait Implementations§

Source§

impl<P: Clone, O1: Clone, O2: Clone> Clone for PBind<P, O1, O2>

Source§

fn clone(&self) -> PBind<P, O1, O2>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, P, K, O1, O2> Parser<'a, K, O2> for PBind<P, O1, O2>
where K: PartialEq + Clone + 'a, O1: Clone + 'a, O2: Clone + 'a, P: Parser<'a, K, O1>,

Source§

fn then<P2, O2>(self, p2: P2) -> PSeq<Self, P2>
where O2: Clone + 'a, P2: Parser<'a, K, O2>,

Sequence two parsers and return a tuple of their results.
Source§

fn or<P2>(self, p2: P2) -> POr<Self, P2>
where P2: Parser<'a, K, O>,

Try this parser or an alternative parser if this one fails.
Source§

fn map<O2, F>(self, f: F) -> PBind<Self, O, O2>
where F: Fn(O) -> O2 + 'static, O2: Clone + 'a,

Apply a function to transform the output of the parser.
Source§

fn between<A, P1, P2>(self, l: P1, r: P2) -> PBetween<P1, Self, P2, A>
where A: Clone + 'a, P1: Parser<'a, K, A>, P2: Parser<'a, K, A>,

Apply this parser between two delimiters, discarding the delimiters’ results.
Source§

fn many(self) -> PMany<Self>

Match this parser zero or more times and collect the results. This is the by default behavior of crate::parser::many::PMany yet one can specialize behavior with crate::parser::many::PMany::at_least and crate::parser::many::PMany::at_most
Source§

fn many1(self) -> PMany<Self>

Match this parser one or more times and collect the results.
Source§

fn delimited_by<PD, A>(self, delim: PD) -> PDelim<Self, PD, A>
where A: Clone + 'a, PD: Parser<'a, K, A>,

Parse this parser zero or more times separated by a delimiter (but keep only the content values). By defualt allow trailing delimiters use crate::parser::delim::PDelim::no_trailing, crate::parser::delim::PDelim::at_least and crate::parser::delim::PDelim::at_most to specialize this parser.
Source§

fn delimited_by1<PD, A>(self, delim: PD) -> PDelim<Self, PD, A>
where A: Clone + 'a, PD: Parser<'a, K, A>,

Parse this parser one or more times separated by a delimiter (but keep only the content values).
Source§

fn not(self) -> PNot<Self, O>

Succeeds only if this parser fails, and vice versa. Produces no value.
Source§

fn padded_by<PD, A>(self, pad: PD) -> PPaddedBy<Self, PD, A>
where A: Clone + 'a, PD: Parser<'a, K, A> + Clone,

Surround this parser with padding (like whitespace) and return the result.
Source§

fn into_<Out>(self, out: Out) -> PInto<Self, O, Out, K>
where Out: PartialEq + Clone + 'a,

Ignores the actual parsed value and replaces it with a given one.
Source§

fn debug(self, label: &'static str) -> PDebug<Self>
where K: ErrorDisplay,

Debug tracing combinator to help inspect parsing behavior.
Source§

fn and<P2, A>(self, second: P2) -> PAnd<Self, P2, A>
where A: Clone + 'a, P2: Parser<'a, K, A>,

Apply another parser after this one, but return only the result of the first as well as the location after parsing.
Source§

fn until_end(self) -> PUntilEnd<Self, K>

Succeeds if and only if the inner parser succeeds and consumes all input
Source§

fn foldl<TP, F, I, O2>(self, tail: TP, f: F) -> PFoldLeft<Self, TP, F, I, O2>
where O2: Clone + 'a, I: IntoIterator<Item = O2> + Clone + 'a, TP: Parser<'a, K, I>, F: Fn(O, O2) -> O + Clone + 'a,

Use self as init while folding left on tail using f
Source§

fn ignore_then<P2, OO>(self, then: P2) -> PIgnoreThen<Self, P2, O>
where OO: Clone + 'a, P2: Parser<'a, K, OO>,

Parsers two parsers in sequence ignores the result of the first and returns the result of the second
Source§

fn then_ignore<P2, OI>(self, ignore: P2) -> PThenIgnore<Self, P2, OI>
where OI: Clone + 'a, P2: Parser<'a, K, OI>,

Parsers two parsers in sequence returns the result of the first and ignores the result of the second
Source§

fn map_with_span<F, O2>(self, f: F) -> PMapWithSpan<Self, O, O2>
where F: Fn(O, Span) -> O2 + 'static, O2: Clone + 'a,

Map the result of the parser through a function with the span which the parser was successful parsing
Source§

fn map_error<F>(self, f: F) -> PMapError<'a, K, Self>
where F: Fn(Error<'a, K>) -> Error<'a, K> + 'static,

Map an error of self with f if it fails else result the result of self
Source§

impl<'a, P, K, O1, O2> ParserCore<'a, K, O2> for PBind<P, O1, O2>
where K: PartialEq + Clone + 'a, O1: Clone + 'a, P: Parser<'a, K, O1>,

Source§

fn parse(&self, i: PInput<'a, K>) -> Result<PSuccess<'a, K, O2>, Error<'a, K>>

Applies the inner parser, then transforms its result using the function f.

If parsing succeeds, the transformation function is applied to the result, and the transformed value is returned.

§Errors

Returns a parse failure if the inner parser p fails.

Auto Trait Implementations§

§

impl<P, O1, O2> Freeze for PBind<P, O1, O2>
where P: Freeze,

§

impl<P, O1, O2> !RefUnwindSafe for PBind<P, O1, O2>

§

impl<P, O1, O2> !Send for PBind<P, O1, O2>

§

impl<P, O1, O2> !Sync for PBind<P, O1, O2>

§

impl<P, O1, O2> Unpin for PBind<P, O1, O2>
where P: Unpin,

§

impl<P, O1, O2> !UnwindSafe for PBind<P, O1, O2>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<K> IntoToken<K> for K

Source§

fn into_token(self) -> K

Converts self into a token of type K.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.