pub struct TokenStream { /* private fields */ }Expand description
A peekable stream of tokens with span tracking.
Implementations§
Source§impl TokenStream
impl TokenStream
Sourcepub fn peek_ahead(&self, n: usize) -> Option<&Token>
pub fn peek_ahead(&self, n: usize) -> Option<&Token>
Peek at the token n positions ahead without consuming.
Sourcepub fn eat(&mut self, expected: &TokenKind) -> Option<Token>
pub fn eat(&mut self, expected: &TokenKind) -> Option<Token>
Consume the next token only if its kind matches expected.
Sourcepub fn eat_while<F>(&mut self, pred: F) -> Vec<Token>
pub fn eat_while<F>(&mut self, pred: F) -> Vec<Token>
Consume tokens while the predicate holds.
Sourcepub fn expect(&mut self, expected: &TokenKind) -> Result<Token, String>
pub fn expect(&mut self, expected: &TokenKind) -> Result<Token, String>
Consume the next token and return an error if the kind is wrong.
Sourcepub fn collect_remaining(self) -> Vec<Token>
pub fn collect_remaining(self) -> Vec<Token>
Collect all remaining tokens as a Vec.
Source§impl TokenStream
impl TokenStream
Sourcepub fn look_ahead(&self, n: usize) -> Option<&Token>
pub fn look_ahead(&self, n: usize) -> Option<&Token>
Peek at the n-th token from the current position (0 = next).
Sourcepub fn skip_while<F: FnMut(&Token) -> bool>(&mut self, pred: F)
pub fn skip_while<F: FnMut(&Token) -> bool>(&mut self, pred: F)
Consume and discard tokens while pred holds.
Sourcepub fn skip_to_inclusive(&mut self, kind: &TokenKind)
pub fn skip_to_inclusive(&mut self, kind: &TokenKind)
Consume tokens up to and including the next occurrence of kind.
Sourcepub fn skip_to(&mut self, kind: &TokenKind)
pub fn skip_to(&mut self, kind: &TokenKind)
Consume tokens up to (but not including) the next occurrence of kind.
Sourcepub fn peek_slice(&self, n: usize) -> &[Token]
pub fn peek_slice(&self, n: usize) -> &[Token]
Return a slice of the next n tokens without consuming them.
Sourcepub fn matches_sequence(&self, kinds: &[&TokenKind]) -> bool
pub fn matches_sequence(&self, kinds: &[&TokenKind]) -> bool
Check if the next n tokens match the given kind sequence.
Trait Implementations§
Source§impl Clone for TokenStream
impl Clone for TokenStream
Source§fn clone(&self) -> TokenStream
fn clone(&self) -> TokenStream
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TokenStream
impl RefUnwindSafe for TokenStream
impl Send for TokenStream
impl Sync for TokenStream
impl Unpin for TokenStream
impl UnsafeUnpin for TokenStream
impl UnwindSafe for TokenStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more