Struct TokenStream

Source
pub struct TokenStream<'a> { /* private fields */ }
Expand description

A stream of tokens. This is a wrapper around a logos::Lexer. It implements Clone, so it can be cloned and used to peek ahead. It also implements Iterator, so it can be used to iterate over the tokens.

Implementations§

Source§

impl<'a> TokenStream<'a>

Source

pub fn new(input: &'a str) -> Self

Creates a new token stream from the given input string. The input string is not copied, so it must outlive the token stream.

Source

pub fn len(&self) -> usize

Returns the remaining input string.

Source

pub fn count(&self) -> usize

Returns the number of remaining tokens in the stream.

Source

pub fn is_empty(&self) -> bool

Returns true if the token stream is empty.

Source

pub fn peek(&self) -> Option<(Result<Token, ParserError>, &'a str)>

Returns the next token in the stream, or None if the stream is empty.

Source

pub fn peek_n( &self, n: usize, ) -> Option<Vec<(Result<Token, ParserError>, String)>>

Returns the next n tokens in the stream. If there are fewer than n tokens left, returns the remaining tokens. If the stream is empty, returns None.

Source

pub fn advance(self) -> Self

Skips the next token in the stream.

Source

pub fn span(&self) -> Range<usize>

Returns the span of the current token.

Trait Implementations§

Source§

impl Clone for TokenStream<'_>

Source§

fn clone(&self) -> Self

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> Debug for TokenStream<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a String> for TokenStream<'a>

Source§

fn from(s: &'a String) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for TokenStream<'a>

Source§

fn from(s: &'a str) -> Self

Converts to this type from the input type.
Source§

impl InputLength for TokenStream<'_>

Source§

fn input_len(&self) -> usize

Calculates the input length, as indicated by its name, and the name of the trait itself
Source§

impl<'a> Parser<TokenStream<'a>, &'a str, ParserError> for Token

Source§

fn parse( &mut self, input: TokenStream<'a>, ) -> IResult<TokenStream<'a>, &'a str, ParserError>

A parser takes in input type, and returns a Result containing either the remaining input and the output value, or an error
Source§

fn map<G, O2>(self, g: G) -> Map<Self, G, O>
where G: Fn(O) -> O2, Self: Sized,

Maps a function over the result of a parser
Source§

fn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O>
where G: FnMut(O) -> H, H: Parser<I, O2, E>, Self: Sized,

Creates a second parser from the output of the first one, then apply over the rest of the input
Source§

fn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O>
where G: Parser<O, O2, E>, Self: Sized,

Applies a second parser over the output of the first one
Source§

fn and<G, O2>(self, g: G) -> And<Self, G>
where G: Parser<I, O2, E>, Self: Sized,

Applies a second parser after the first one, return their results as a tuple
Source§

fn or<G>(self, g: G) -> Or<Self, G>
where G: Parser<I, O, E>, Self: Sized,

Applies a second parser over the input if the first one failed
Source§

fn into<O2, E2>(self) -> Into<Self, O, O2, E, E2>
where O2: From<O>, E2: From<E>, Self: Sized,

automatically converts the parser’s output and error values to another type, as long as they implement the From trait
Source§

impl ToString for TokenStream<'_>

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for TokenStream<'a>

§

impl<'a> RefUnwindSafe for TokenStream<'a>

§

impl<'a> Send for TokenStream<'a>

§

impl<'a> Sync for TokenStream<'a>

§

impl<'a> Unpin for TokenStream<'a>

§

impl<'a> UnwindSafe for TokenStream<'a>

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