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
impl KTokenStream
Sourcepub fn new(tokens: &TokenStream) -> Self
pub fn new(tokens: &TokenStream) -> Self
create a new instance from a TokenStream
Sourcepub fn new_with_pos(tokens: &TokenStream, pos: usize) -> Self
pub fn new_with_pos(tokens: &TokenStream, pos: usize) -> Self
create the a new instance from a TokenStream and the initial position
Sourcepub fn advance(&mut self) -> TokenTree
pub fn advance(&mut self) -> TokenTree
advance the position and return the previous element in position - 1
Sourcepub fn lookup(&self, step: usize) -> &TokenTree
pub fn lookup(&self, step: usize) -> &TokenTree
perform a search operation inside the stream by a number of specified steps.
Sourcepub fn has(&self, step: usize) -> bool
pub fn has(&self, step: usize) -> bool
perform a search operation inside the stream by a number of specified steps.
Sourcepub fn prev(&self) -> &TokenTree
pub fn prev(&self) -> &TokenTree
take the previous element of the stream from the current position.
Sourcepub fn to_ktoken_stream(&self) -> KTokenStream
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
Sourcepub fn opt_ktoken_stream(&self) -> Option<KTokenStream>
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