PFoldLeft

Struct PFoldLeft 

Source
pub struct PFoldLeft<P, TP, F, I, O2> { /* private fields */ }
Expand description

A parser combinator that applies left-associative folding.

PFoldLeft takes three parsers:

  • head: a parser that produces the initial value (O)
  • tail: a parser that produces an iterable of additional values (O2)
  • f: Fn(O, O2) -> O.

This is useful for building left-associative constructs such as arithmetic expressions like 1 - 2 - 3 which should parse as ((1 - 2) - 3).

§Type Parameters

  • P: Parser for the head element (left-most value).
  • TP: Parser for the tail elements (right-side iterable).
  • F: The folding function applied from left to right.
  • I: The iterable type returned by the tail parser.
  • O2: The item type inside the tail iterable.

Trait Implementations§

Source§

impl<P: Clone, TP: Clone, F: Clone, I: Clone, O2: Clone> Clone for PFoldLeft<P, TP, F, I, O2>

Source§

fn clone(&self) -> PFoldLeft<P, TP, F, I, 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, K, O, P, TP, F, I, O2> Parser<'a, K, O> for PFoldLeft<P, TP, F, I, O2>
where K: PartialEq + Clone + 'a, O: Clone + 'a, O2: Clone + 'a, P: Parser<'a, K, O>, I: IntoIterator<Item = O2> + Clone + 'a, TP: Parser<'a, K, I>, F: Fn(O, O2) -> O + Clone + 'a,

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, K, O, P, TP, F, I, O2> ParserCore<'a, K, O> for PFoldLeft<P, TP, F, I, O2>
where K: PartialEq + Clone + 'a, O: Clone + 'a, P: Parser<'a, K, O>, I: IntoIterator<Item = O2> + Clone + 'a, TP: Parser<'a, K, I>, F: Fn(O, O2) -> O + Clone + 'a,

Source§

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

Runs the head parser, then the tail parser, and folds the results.

Auto Trait Implementations§

§

impl<P, TP, F, I, O2> Freeze for PFoldLeft<P, TP, F, I, O2>
where P: Freeze, TP: Freeze, F: Freeze,

§

impl<P, TP, F, I, O2> RefUnwindSafe for PFoldLeft<P, TP, F, I, O2>

§

impl<P, TP, F, I, O2> Send for PFoldLeft<P, TP, F, I, O2>
where P: Send, TP: Send, F: Send, I: Send, O2: Send,

§

impl<P, TP, F, I, O2> Sync for PFoldLeft<P, TP, F, I, O2>
where P: Sync, TP: Sync, F: Sync, I: Sync, O2: Sync,

§

impl<P, TP, F, I, O2> Unpin for PFoldLeft<P, TP, F, I, O2>
where P: Unpin, TP: Unpin, F: Unpin, I: Unpin, O2: Unpin,

§

impl<P, TP, F, I, O2> UnwindSafe for PFoldLeft<P, TP, F, I, 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.