Trait pear::input::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.

Object Safety§

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.

§

type Token = char

§

type Slice = &'a str

§

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

§

type Marker = &'a str

§

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>

§

type Token = char

§

type Slice = &'a str

§

type Many = <Text<'a> as Input>::Slice

§

type Marker = usize

§

type Context = Span<'a>

source§

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

§

type Token = <I as Input>::Token

§

type Slice = <I as Input>::Slice

§

type Many = <I as Input>::Many

§

type Marker = <I as Input>::Marker

§

type Context = <I as Input>::Context

source§

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

§

type Token = <T as Indexable>::One

§

type Slice = Extent<T>

§

type Many = Extent<T>

§

type Marker = usize

§

type Context = Extent<T>