FlowMany

Struct FlowMany 

Source
pub struct FlowMany<P, O>(pub P, _);
Expand description

Collect Continue(T1) values until Break(T2).

Prefer crate::parser::ParserMut::flow_many.

§Examples

use chasa::prelude::*;
use std::ops::ControlFlow;

let mut input = "ab]";
let take_until_bracket = |i: In<&str, Merger<&str, StdErr<char>>, (), ()>| match i.input.next() {
    Some(']') => ControlFlow::Break(']'),
    Some(c) => ControlFlow::Continue(c),
    None => ControlFlow::Break('\0'),
};
let r = parse_once::<_, StdErr<char>, _, _>(&mut input, take_until_bracket.flow_many::<String, char, char>());
assert_eq!(r.out.0, "ab");
assert_eq!(r.out.1, ']');
assert_eq!(input, "");

Tuple Fields§

§0: P

Implementations§

Source§

impl<P, O> FlowMany<P, O>

Source

pub fn new(parser: P) -> Self

Create a new FlowMany.

Trait Implementations§

Source§

impl<I, E, N, L, P, O, T1, T2> Parser<I, E, N, L> for FlowMany<P, O>
where I: Input, E: ErrMode<I>, N: Rb, L: RbBack, P: Parser<I, E, N, L, Out = ControlFlow<T2, T1>>, O: FromIterator<T1>,

Source§

fn run(&self, input: In<'_, I, E, N, L>) -> Self::Out

Source§

fn by_ref<'a>(&'a self) -> RefParser<'a, Self>

Borrow a parser immutably as ParserOnce. Read more
Source§

fn flow_many_map<F, O, T1, T2>(self, f: F) -> FlowManyMap<Self, F>
where Self: Sized + ParserMut<I, E, N, L, Out = ControlFlow<T2, T1>>, F: for<'a, 'b> Fn(&mut FlowManyIterator<'a, 'b, Self, I, E, N, L, T1, T2>) -> O,

Source§

fn many_map<F, O>(self, f: F) -> ManyMap<Self, F>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E>>, F: for<'a, 'b> Fn(ManyMapIterator<'a, 'b, Self, I, E, N, L>) -> O,

Like ParserMut::many, but lets you fold via a streaming iterator. Read more
Source§

fn many1_map<F, O>(self, f: F) -> Many1Map<Self, F>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E>>, F: for<'a, 'b> Fn(Many1MapIterator<'a, 'b, Self, I, E, N, L>) -> O,

Like Parser::many_map, but requires at least one element.
Source§

fn sep_map<Q, F, T, S, O>( self, sep_p: Q, f: F, ) -> SepMap<Zero, Allow, Self, Q, F, T>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E, Value = T>>, Q: ParserMut<I, E, N, L, Out: OutOf<I, E, Value = S, Error = ErrOf<Self, I, E, N, L>>>, F: for<'a, 'b> Fn(SepMapIterator<'a, 'b, Self, Q, I, E, N, L, Zero, Allow>) -> O,

Like ParserMut::sep, but lets you fold via a streaming iterator. Read more
Source§

fn sep1_map<Q, F, T, S, O>( self, sep_p: Q, f: F, ) -> SepMap<One, Allow, Self, Q, F, T>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E, Value = T>>, Q: ParserMut<I, E, N, L, Out: OutOf<I, E, Value = S, Error = ErrOf<Self, I, E, N, L>>>, F: for<'a, 'b> Fn(SepMapIterator<'a, 'b, Self, Q, I, E, N, L, One, Allow>) -> O,

Like Parser::sep_map, but requires at least one item (1+). Read more
Source§

fn map<O, F>(self, f: F) -> Map<Self, F>
where Self: Sized, Self::Out: OutOf<I, E>, F: Fn(ValueOf<Self, I, E, N, L>) -> O,

Map the output of a parser. Read more
Source§

fn bind<P2, F>(self, f: F) -> Bind<Self, F>
where Self: Sized, Self::Out: OutOf<I, E>, F: Fn(ValueOf<Self, I, E, N, L>) -> P2, P2: ParserOnce<I, E, N, L, Out: OutOf<I, E, Error = ErrOf<Self, I, E, N, L>>>,

Sequential bind (flat_map). Read more
Source§

impl<I, E, N, L, P, O, T1, T2> ParserMut<I, E, N, L> for FlowMany<P, O>
where I: Input, E: ErrMode<I>, N: Rb, L: RbBack, P: ParserMut<I, E, N, L, Out = ControlFlow<T2, T1>>, O: FromIterator<T1>,

Source§

fn run_mut(&mut self, input: In<'_, I, E, N, L>) -> Self::Out

Source§

fn by_mut<'a>(&'a mut self) -> MutParser<'a, Self>

Borrow a parser mutably as ParserOnce. Read more
Source§

fn map_mut<O, F>(self, f: F) -> Map<Self, F>
where Self: Sized, Self::Out: OutOf<I, E>, F: FnMut(ValueOf<Self, I, E, N, L>) -> O,

Like Parser::map, but intended for mutable/repeatable mappers (FnMut).
Source§

fn bind_mut<P2, F>(self, f: F) -> Bind<Self, F>
where Self: Sized, Self::Out: OutOf<I, E>, F: FnMut(ValueOf<Self, I, E, N, L>) -> P2, P2: ParserOnce<I, E, N, L, Out: OutOf<I, E, Error = ErrOf<Self, I, E, N, L>>>,

Like Parser::bind, but intended for mutable/repeatable binders (FnMut).
Source§

fn flow<C, S, Step, T>(self, state: S, step: Step) -> Flow<Self, S, Step>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E, Value = T>>, Step: FnMut(S, T) -> ControlFlow<C, S>,

Stateful loop that terminates on soft failure via In::maybe. Read more
Source§

fn flow_many<O, T1, T2>(self) -> FlowMany<Self, O>
where Self: Sized + ParserMut<I, E, N, L, Out = ControlFlow<T2, T1>>, O: FromIterator<T1>,

Collect Continue(T1) values until Break(T2). Read more
Source§

fn flow_many_map_once<F, O, T1, T2>(self, f: F) -> FlowManyMap<Self, F>
where Self: Sized + ParserMut<I, E, N, L, Out = ControlFlow<T2, T1>>, F: for<'a, 'b> FnOnce(&mut FlowManyIterator<'a, 'b, Self, I, E, N, L, T1, T2>) -> O,

Like Parser::flow_many_map, but intended for single-shot mappers (FnOnce).
Source§

fn flow_many_map_mut<F, O, T1, T2>(self, f: F) -> FlowManyMap<Self, F>
where Self: Sized + ParserMut<I, E, N, L, Out = ControlFlow<T2, T1>>, F: for<'a, 'b> FnMut(&mut FlowManyIterator<'a, 'b, Self, I, E, N, L, T1, T2>) -> O,

Like Parser::flow_many_map, but intended for mutable/repeatable mappers (FnMut).
Source§

fn many<O>(self) -> Many<Self, O>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E>>, O: FromIterator<ValueOf<Self, I, E, N, L>>,

Repeat a parser until soft failure, collecting outputs. Read more
Source§

fn many1<O>(self) -> Many1<Self, O>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E>>, O: FromIterator<ValueOf<Self, I, E, N, L>>,

Repeat a parser one or more times, collecting outputs. Read more
Source§

fn many_map_once<F, O>(self, f: F) -> ManyMap<Self, F>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E>>, F: for<'a, 'b> FnOnce(ManyMapIterator<'a, 'b, Self, I, E, N, L>) -> O,

Like Parser::many_map, but intended for single-shot mappers (FnOnce).
Source§

fn many_map_mut<F, O>(self, f: F) -> ManyMap<Self, F>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E>>, F: for<'a, 'b> FnMut(ManyMapIterator<'a, 'b, Self, I, E, N, L>) -> O,

Like Parser::many_map, but intended for mutable/repeatable mappers (FnMut). Read more
Source§

fn many1_map_once<F, O>(self, f: F) -> Many1Map<Self, F>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E>>, F: for<'a, 'b> FnOnce(Many1MapIterator<'a, 'b, Self, I, E, N, L>) -> O,

Like Parser::many1_map, but intended for single-shot mappers (FnOnce).
Source§

fn many1_map_mut<F, O>(self, f: F) -> Many1Map<Self, F>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E>>, F: for<'a, 'b> FnMut(Many1MapIterator<'a, 'b, Self, I, E, N, L>) -> O,

Like Parser::many1_map, but intended for mutable/repeatable mappers (FnMut).
Source§

fn many_skip(self) -> SkipMany<Self>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E>>,

Repeat a parser until soft failure, discarding outputs. Read more
Source§

fn many1_skip(self) -> SkipMany1<Self>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E>>,

Repeat a parser one or more times, discarding outputs. Read more
Source§

fn count<R, O>(self, range: R) -> Count<Self, O>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E>>, R: CountRange, O: FromIterator<ValueOf<Self, I, E, N, L>>,

Repeat a parser a specified number of times. Read more
Source§

fn sep<O, Q, T>(self, sep_p: Q) -> Sep<O, Zero, Allow, Self, Q, T>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E, Value = T>>, Q: ParserMut<I, E, N, L, Out: OutOf<I, E, Error = ErrOf<Self, I, E, N, L>>>, O: FromIterator<T>,

Parse a separated list: item (sep item)*. Read more
Source§

fn sep1<O, Q, T>(self, sep_p: Q) -> Sep<O, One, Allow, Self, Q, T>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E, Value = T>>, Q: ParserMut<I, E, N, L, Out: OutOf<I, E, Error = ErrOf<Self, I, E, N, L>>>, O: FromIterator<T>,

Like ParserMut::sep, but requires at least one item (1+). Read more
Source§

fn sep_map_once<Q, F, T, S, O>( self, sep_p: Q, f: F, ) -> SepMap<Zero, Allow, Self, Q, F, T>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E, Value = T>>, Q: ParserMut<I, E, N, L, Out: OutOf<I, E, Value = S, Error = ErrOf<Self, I, E, N, L>>>, F: for<'a, 'b> FnOnce(SepMapIterator<'a, 'b, Self, Q, I, E, N, L, Zero, Allow>) -> O,

Like Parser::sep_map, but intended for single-shot mappers (FnOnce).
Source§

fn sep_map_mut<Q, F, T, S, O>( self, sep_p: Q, f: F, ) -> SepMap<Zero, Allow, Self, Q, F, T>
where Self: Sized + ParserMut<I, E, N, L, Out: OutOf<I, E, Value = T>>, Q: ParserMut<I, E, N, L, Out: OutOf<I, E, Value = S, Error = ErrOf<Self, I, E, N, L>>>, F: for<'a, 'b> FnMut(SepMapIterator<'a, 'b, Self, Q, I, E, N, L, Zero, Allow>) -> O,

Like Parser::sep_map, but intended for mutable/repeatable mappers (FnMut).
Source§

fn sep_reduce<Q, F>(self, op: Q, f: F) -> SepReduce<Self, Q, F>

Left-associative separator reduction: term (op term)*. let mut input = “a+a+a”; let term = item(‘a’).to(1); let plus = item(‘+’).to(()); let out = parse_ok_once(&mut input, term.sep_reduce(plus, |a, _, b| a + b)).unwrap(); assert_eq!(out, 3); assert_eq!(input, “”); Read more
Source§

impl<I, E, N, L, P, O, T1, T2> ParserOnce<I, E, N, L> for FlowMany<P, O>
where I: Input, E: ErrMode<I>, N: Rb, L: RbBack, P: ParserMut<I, E, N, L, Out = ControlFlow<T2, T1>>, O: FromIterator<T1>,

Source§

type Out = (O, T2)

Source§

fn run_once(self, input: In<'_, I, E, N, L>) -> Self::Out

Source§

fn or_not(self) -> OrNot<Self>

Optionalize a parser with OutOf semantics. Read more
Source§

fn cut(self) -> CutIfOk<Self>
where Self::Out: OutOf<I, E>,

Commit-on-success for OutOf parsers. Read more
Source§

fn with_range(self) -> WithRange<Self>
where Self::Out: OutOf<I, E>,

Attach the consumed range (start and end positions) to a parser output. Read more
Source§

fn with_seq<S>(self) -> WithSeq<Self, S>
where Self::Out: OutOf<I, E>,

Attach the consumed sequence to a parser output. Read more
Source§

fn lookahead(self) -> Lookahead<Self>
where Self::Out: OutOf<I, E>,

Run this parser as lookahead. Read more
Source§

fn no_cut(self) -> NoCut<Self>

Run this parser in a non-root cut scope (cut does not trigger commits). Read more
Source§

fn not(self) -> Not<Self>
where Self::Out: OutOf<I, E>,

Negative lookahead for OutOf parsers. Read more
Source§

fn label(self, label: impl Into<Cow<'static, str>>) -> Label<Self>

Attach a label to a parser failure (Parsec-like <?>). Read more
Source§

fn label_with<F, S>(self, f: F) -> LabelWith<Self, F>
where F: Fn() -> S, S: Into<Cow<'static, str>>,

Attach a lazily-evaluated label to a parser failure. Read more
Source§

fn label_with_once<F, S>(self, f: F) -> LabelWith<Self, F>
where F: FnOnce() -> S, S: Into<Cow<'static, str>>,

Like ParserOnce::label_with, but intended for single-shot label builders (FnOnce).
Source§

fn label_with_mut<F, S>(self, f: F) -> LabelWith<Self, F>
where F: FnMut() -> S, S: Into<Cow<'static, str>>,

Like ParserOnce::label_with, but intended for mutable/repeatable label builders (FnMut).
Source§

fn align_errors<T, E2>(self) -> AlignErrors<Self, (T, E2)>
where I: SeqInput<T>, E2: MergeErrors, Self: ParserOnce<I, Merger<I, E2>, N, L, Out: OutOf<I, Merger<I, E2>>>,

Align and merge errors, returning the consumed sequence on failure.
Source§

fn align_ranged_errors<T, E2>(self) -> AlignRangedErrors<Self, (T, E2)>
where I: SeqInput<T>, E2: MergeErrors, Self: ParserOnce<I, Merger<I, E2>, N, L, Out: OutOf<I, Merger<I, E2>>>,

Align and merge errors, returning the consumed sequence and range on failure.
Source§

fn map_once<O, F>(self, f: F) -> Map<Self, F>
where Self::Out: OutOf<I, E>, F: FnOnce(ValueOf<Self, I, E, N, L>) -> O,

Like Parser::map, but intended for single-shot mappers (FnOnce).
Source§

fn lift_result<O, E1>(self) -> LiftResult<Self>
where Self: ParserOnce<I, (), N, L, Out = Result<O, E1>>,

Lift a direct Result output into a merger-based parser with ranged errors.
Source§

fn lift_ranged_result<O1, O2, E1>(self) -> LiftRangedResult<Self>
where Self: ParserOnce<I, (), N, L, Out = (O1, Result<O2, (Range<I::Pos>, E1)>)>,

Lift a direct (A, Result<B, (range, err)>) output into a merger-based parser.
Source§

fn to<O>(self, value: O) -> To<Self, O>
where Self::Out: OutOf<I, E>,

Replace the output of a parser with a constant value. Read more
Source§

fn bind_once<P2, F>(self, f: F) -> Bind<Self, F>
where Self::Out: OutOf<I, E>, F: FnOnce(ValueOf<Self, I, E, N, L>) -> P2, P2: ParserOnce<I, E, N, L, Out: OutOf<I, E, Error = ErrOf<Self, I, E, N, L>>>,

Like Parser::bind, but intended for single-shot binders (FnOnce).
Source§

fn then<P>(self, right: P) -> (Self, P)

Parse self then right, returning both outputs as a tuple. Read more
Source§

fn left<P>(self, right: P) -> Left<Self, P>

Parse self then right, returning the output of self. Read more
Source§

fn right<P>(self, right: P) -> Right<Self, P>

Parse self then right, returning the output of right. Read more
Source§

fn between<Lp, Rp>(self, left: Lp, right: Rp) -> Between<Lp, Self, Rp>

Parse left, then self, then right, returning the output of self. Read more
Source§

fn or<P>(self, other: P) -> Choice<(Self, P)>
where Self::Out: OutOf<I, E>, P: ParserOnce<I, E, N, L, Out = Self::Out>,

Choice: try self, then other on soft failure. Read more
Source§

fn map_err<E1, E2, E3, F, O>(self, f: F) -> MapErr<Self, F, (O, E1)>
where Self: ParserOnce<I, Merger<I, E1>, N, L, Out = Option<O>>, F: FnOnce(&[E1]) -> E2, E2: Into<E3>,

Auto Trait Implementations§

§

impl<P, O> Freeze for FlowMany<P, O>
where P: Freeze,

§

impl<P, O> RefUnwindSafe for FlowMany<P, O>
where P: RefUnwindSafe,

§

impl<P, O> Send for FlowMany<P, O>
where P: Send,

§

impl<P, O> Sync for FlowMany<P, O>
where P: Sync,

§

impl<P, O> Unpin for FlowMany<P, O>
where P: Unpin,

§

impl<P, O> UnwindSafe for FlowMany<P, O>
where P: UnwindSafe,

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> 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<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.