Struct minparser::DefLine

source ·
pub struct DefLine<I, FILE = ()> { /* private fields */ }
Expand description

A positioned iterator

When I is a char iterator DefLine<I, FILE> provides the method next_pos that returns the next available positioned character as Pos<Option<char>, FILE> by calling I::next.

Implementations§

source§

impl<I, F> DefLine<I, F>

source

pub fn map_iter<J, MF: FnOnce(I) -> J>(self, f: MF) -> DefLine<J, F>

Applies f to the inner iterator iter of type I inside self to get a new DefLine with f(iter) as iter.

source

pub fn map_iter_reset<J, MF: FnOnce(I) -> J>(self, f: MF) -> DefLine<J, F>

Like DefLine::map_iter but also resets the position to the beginning.

source§

impl<I, F> DefLine<I, F>
where I: Iterator<Item = char>, F: Default + Clone,

source

pub fn new<J: IntoIterator<IntoIter = I>>(it: J) -> Self

Like DefLine::new_file but with F::default() as file.

source§

impl<I, F> DefLine<I, F>
where I: Iterator<Item = char>, F: Clone,

source

pub fn new_file<J>(it: J, f: F) -> Self
where J: IntoIterator<IntoIter = I>,

Creates a new DefLine with the specified iterator and file.

source

pub fn peekable(self) -> DefLine<Peekable<I>, F>

Same as self.map_iter(I::peekable)

source

pub fn next_pos(&mut self) -> Pos<Option<char>, F>

Advances the iterator and returns the next positioned value.

When the iterator has finished the returned position follows the one that has been returned by the last character.

source

pub fn next_pos_cf<T, MF: FnMut(char) -> ControlFlow<T>>( &mut self, f: MF, ) -> Pos<Option<T>, F>

Discards characters as long as Self::next_pos returns Some(ch) and f(ch) returns ControlFlow::Continue.

When f(ch) returns ControlFlow::Break(t) then this function will return Some(t).

source

pub fn next_pos_until<MF: FnMut(char) -> bool>( &mut self, f: MF, ) -> Pos<Option<char>, F>

Like DefLine::next_pos_cf but discards characters as long as f returns true.

source

pub fn next_no_spaces(&mut self) -> Pos<Option<char>, F>

Next character discarding whitespaces and newline characters.

Removes any whitespace according to predicates::is_whitespace.

source

pub fn next_nl_no_spaces(&mut self) -> Pos<Option<char>, F>

Next character discarding whitespaces but not newline characters.

source§

impl<I, F> DefLine<Peekable<I>, F>
where I: Iterator<Item = char>, F: Clone,

source

pub fn peek_pos(&mut self) -> Pos<Option<char>, F>

Like DefLine::next_pos but doesn’t remove the character from the underlying iterator.

source

pub fn peek_pos_cf<T, MF: FnMut(char) -> ControlFlow<T>>( &mut self, f: MF, ) -> Pos<Option<T>, F>

Like DefLine::next_pos_cf but when f(ch) returns ControlFlow::Break then ch is not removed from the underlying iterator.

source

pub fn peek_pos_until<MF: FnMut(char) -> bool>( &mut self, f: MF, ) -> Pos<Option<char>, F>

Like DefLine::next_pos_until but when f(ch) returns false then ch is not removed from the underlying iterator.

source

pub fn discard(&mut self)

Discard the last character in the iterator

source

pub fn grab_cf<V: Appender<K>, K, MF: FnMut(char) -> ControlFlow<(), K>>( &mut self, f: MF, ) -> Pos<V, F>

Appends characters to an accumulator.

Every time DefLine::peek_pos returns Some(ch) and f(ch) returns ControlFlow::Continue(k) then ch is discarded and k is pushed into an accumulator of type V. When f(ch) returns instead ControlFlow::Break then ch is not discarded and the used accumulator is returned.

source

pub fn grab_until<V: Appender<char>, MF: FnMut(char) -> bool>( &mut self, f: MF, ) -> Pos<V, F>

Like DefLine::grab_cf but appends characters as long as f returns true.

source

pub fn get_line<V: Appender<char>>(&mut self) -> Pos<V, F>

Gets a line

source

pub fn cap_ht_cf<V: AppenderExt<K>, K, SP: FnMut(char) -> bool, CF: FnMut(char) -> ControlFlow<(), K>>( &mut self, sp: SP, cf: CF, ) -> Pos<V, F>

Removes leading and trailing characters.

Every character returned by DefLine::peek_pos can be considered a space or a nonspace character depending on whether sp returns true or false. Until function cf returns ControlFlow::Continue retrieved characters are stores in a container of type V and when cf returns ControlFlow::Break then leading and trailing spaces are removed from the returned container.

If the returned container is not empty then the returned position is exactly the position of the first nonspace appended character, otherwise it is the position of the first character that terminated the accumulation.

source

pub fn cap_spaces<V: AppenderExt<char>, CF: FnMut(char) -> ControlFlow<()>>( &mut self, f: CF, ) -> Pos<V, F>

Removes leading and trailing whitespaces.

See also DefLine::cap_ht_cf and predicates::is_whitespace for the used definition of whitespace.

source

pub fn get_line_cap<V: AppenderExt<char>>(&mut self) -> Pos<V, F>

Gets a line and removes leading and trailing whitespaces.

See also DefLine::cap_ht_cf and predicate::is_whitespace for the used definition of whitespace.

source

pub fn get_ident<V: Appender<char>>(&mut self) -> Pos<V, F>

Parse an identifier.

Gets an identifier defined as a contiguous sequence of alphabetic characters as defined in predicates::is_alphabetic.

source

pub fn get_num(&mut self) -> Pos<Option<u32>, F>

Parses a decimal number.

source

pub fn get_hex_num(&mut self) -> Pos<Option<u32>, F>

Parses an hexadecimal number (without the prefix).

source

pub fn peek_no_spaces(&mut self) -> Pos<Option<char>, F>

Peeks character by discarding whitespaces and newline characters.

Removes any whitespace according to predicates::is_whitespace.

source

pub fn peek_nl_no_spaces(&mut self) -> Pos<Option<char>, F>

Peeks character by whitespaces but not newline characters.

Auto Trait Implementations§

§

impl<I, FILE> Freeze for DefLine<I, FILE>
where I: Freeze, FILE: Freeze,

§

impl<I, FILE> RefUnwindSafe for DefLine<I, FILE>
where I: RefUnwindSafe, FILE: RefUnwindSafe,

§

impl<I, FILE> Send for DefLine<I, FILE>
where I: Send, FILE: Send,

§

impl<I, FILE> Sync for DefLine<I, FILE>
where I: Sync, FILE: Sync,

§

impl<I, FILE> Unpin for DefLine<I, FILE>
where I: Unpin, FILE: Unpin,

§

impl<I, FILE> UnwindSafe for DefLine<I, FILE>
where I: UnwindSafe, FILE: 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>,

§

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

§

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.