pear::input

Trait Input

Source
pub trait Input: Sized {
    type Token: Token<Self>;
    type Slice: Slice<Self>;
    type Many: Length;
    type Marker: Copy;
    type Context: Show;

    // Required methods
    fn token(&mut self) -> Option<Self::Token>;
    fn slice(&mut self, n: usize) -> Option<Self::Slice>;
    fn peek<F>(&mut self, cond: F) -> bool
       where F: FnMut(&Self::Token) -> bool;
    fn peek_slice<F>(&mut self, n: usize, cond: F) -> bool
       where F: FnMut(&Self::Slice) -> bool;
    fn eat<F>(&mut self, cond: F) -> Option<Self::Token>
       where F: FnMut(&Self::Token) -> bool;
    fn eat_slice<F>(&mut self, n: usize, cond: F) -> Option<Self::Slice>
       where F: FnMut(&Self::Slice) -> bool;
    fn take<F>(&mut self, cond: F) -> Self::Many
       where F: FnMut(&Self::Token) -> bool;
    fn skip<F>(&mut self, cond: F) -> usize
       where F: FnMut(&Self::Token) -> bool;
    fn has(&mut self, n: usize) -> bool;
    fn mark(&mut self, info: &ParserInfo) -> Self::Marker;
    fn context(&mut self, _mark: Self::Marker) -> Self::Context;
}

Required Associated Types§

Required Methods§

Source

fn token(&mut self) -> Option<Self::Token>

Returns a copy of the current token, if there is one.

Source

fn slice(&mut self, n: usize) -> Option<Self::Slice>

Returns a copy of the current slice of size n, if there is one.

Source

fn peek<F>(&mut self, cond: F) -> bool
where F: FnMut(&Self::Token) -> bool,

Checks if the current token fulfills cond.

Source

fn peek_slice<F>(&mut self, n: usize, cond: F) -> bool
where F: FnMut(&Self::Slice) -> bool,

Checks if the current slice of size n (if any) fulfills cond.

Source

fn eat<F>(&mut self, cond: F) -> Option<Self::Token>
where F: FnMut(&Self::Token) -> bool,

Checks if the current token fulfills cond. If so, the token is consumed and returned. Otherwise, returns None.

Source

fn eat_slice<F>(&mut self, n: usize, cond: F) -> Option<Self::Slice>
where F: FnMut(&Self::Slice) -> bool,

Checks if the current slice of size n (if any) fulfills cond. If so, the slice is consumed and returned. Otherwise, returns None.

Source

fn take<F>(&mut self, cond: F) -> Self::Many
where F: FnMut(&Self::Token) -> bool,

Takes tokens while cond returns true, collecting them into a Self::Many and returning it.

Source

fn skip<F>(&mut self, cond: F) -> usize
where F: FnMut(&Self::Token) -> bool,

Skips tokens while cond returns true. Returns the number of skipped tokens.

Source

fn has(&mut self, n: usize) -> bool

Returns true if there are at least n tokens remaining.

Source

fn mark(&mut self, info: &ParserInfo) -> Self::Marker

Emits a marker that represents the current parse position.

Source

fn context(&mut self, _mark: Self::Marker) -> Self::Context

Returns a context to identify the input spanning from mark until but excluding the current position.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a> Input for &'a str

Source§

fn token(&mut self) -> Option<Self::Token>

Returns a copy of the current token, if there is one.

Source§

fn slice(&mut self, n: usize) -> Option<Self::Slice>

Returns a copy of the current slice of size n, if there is one.

Source§

fn peek<F>(&mut self, cond: F) -> bool
where F: FnMut(&Self::Token) -> bool,

Checks if the current token fulfills cond.

Source§

fn peek_slice<F>(&mut self, n: usize, cond: F) -> bool
where F: FnMut(&Self::Slice) -> bool,

Checks if the current slice of size n (if any) fulfills cond.

Source§

fn eat<F>(&mut self, cond: F) -> Option<Self::Token>
where F: FnMut(&Self::Token) -> bool,

Checks if the current token fulfills cond. If so, the token is consumed and returned. Otherwise, returns None.

Source§

fn eat_slice<F>(&mut self, n: usize, cond: F) -> Option<Self::Slice>
where F: FnMut(&Self::Slice) -> bool,

Checks if the current slice of size n (if any) fulfills cond. If so, the slice is consumed and returned. Otherwise, returns None.

Source§

fn take<F>(&mut self, cond: F) -> Self::Many
where F: FnMut(&Self::Token) -> bool,

Takes tokens while cond returns true, collecting them into a Self::Many and returning it.

Source§

fn skip<F>(&mut self, cond: F) -> usize
where F: FnMut(&Self::Token) -> bool,

Skips tokens while cond returns true. Returns the number of skipped tokens.

Source§

fn has(&mut self, n: usize) -> bool

Returns true if there are at least n tokens remaining.

Source§

type Token = char

Source§

type Slice = &'a str

Source§

type Many = <&'a str as Input>::Slice

Source§

type Marker = &'a str

Source§

type Context = &'a str

Source§

fn mark(&mut self, _info: &ParserInfo) -> Self::Marker

Source§

fn context(&mut self, mark: Self::Marker) -> Self::Context

Implementors§

Source§

impl<'a> Input for Text<'a>

Source§

impl<I: Input> Input for Pear<I>

Source§

type Token = <I as Input>::Token

Source§

type Slice = <I as Input>::Slice

Source§

type Many = <I as Input>::Many

Source§

type Marker = <I as Input>::Marker

Source§

type Context = <I as Input>::Context

Source§

impl<T: Indexable + Show + Length + PartialEq> Input for Cursor<T>
where T::One: Show + PartialEq,

Source§

type Token = <T as Indexable>::One

Source§

type Slice = Extent<T>

Source§

type Many = Extent<T>

Source§

type Marker = usize

Source§

type Context = Extent<T>