Struct KTokenStream

Source
pub struct KTokenStream { /* private fields */ }
Expand description

Convinient way to manage any kind of tokens stream by exposing basic function to advance and consume the stream.

Heavenly inspired to albert_stream https://github.com/vincenzopalazzo/albert/tree/main/stream

Implementations§

Source§

impl KTokenStream

Source

pub fn new(tokens: &TokenStream) -> Self

create a new instance from a TokenStream

Source

pub fn new_with_pos(tokens: &TokenStream, pos: usize) -> Self

create the a new instance from a TokenStream and the initial position

Source

pub fn advance(&mut self) -> TokenTree

advance the position and return the previous element in position - 1

Source

pub fn lookup(&self, step: usize) -> &TokenTree

perform a search operation inside the stream by a number of specified steps.

Source

pub fn has(&self, step: usize) -> bool

perform a search operation inside the stream by a number of specified steps.

Source

pub fn next(&mut self)

advance the position of the stream.

Source

pub fn prev(&self) -> &TokenTree

take the previous element of the stream from the current position.

Source

pub fn peek(&self) -> &TokenTree

return he token at the current position.

Source

pub fn last(&self) -> &TokenTree

return the last token of the stream.

Source

pub fn match_tok(&self, tok: &str) -> bool

match the current token with the one specified.

Source

pub fn is_end(&self) -> bool

check if it is reach the end of the stream

Source

pub fn to_ktoken_stream(&self) -> KTokenStream

unwrap the TokenTree::Group and the return the token stream that contains. If the current token it is not a TokenTree::Group the function will panic

Source

pub fn opt_ktoken_stream(&self) -> Option<KTokenStream>

unwrap the TokenTree::Group and the return the token stream that contains. If the current token it is not a TokenTree::Group the function will panic

Source

pub fn unwrap_group(&self) -> TokenTree

Source

pub fn unwrap_group_as_stream(&self) -> TokenStream

Source

pub fn is_group(&self) -> bool

check if the current token is a TokenTree::Group

Source

pub fn consume_brace(&mut self)

Trait Implementations§

Source§

impl Debug for KTokenStream

Source§

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

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

impl From<&TokenStream> for KTokenStream

Source§

fn from(value: &TokenStream) -> Self

Converts to this type from the input type.
Source§

impl From<TokenStream> for KTokenStream

Source§

fn from(value: TokenStream) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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.