pub struct TokenStream { /* private fields */ }Expand description
An iterator over a sequence of tokens.
Supports peeking, consuming, and backtracking (via snapshots).
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 (0 = current).
Sourcepub fn current_kind(&self) -> Option<&TokenKind>
pub fn current_kind(&self) -> Option<&TokenKind>
Get the current token kind without consuming.
Sourcepub fn at_keyword(&self, kw: &TokenKind) -> bool
pub fn at_keyword(&self, kw: &TokenKind) -> bool
Check if the current token matches a given kind (by tag, ignoring data).
Sourcepub fn at_ident(&self, name: &str) -> bool
pub fn at_ident(&self, name: &str) -> bool
Check if the current token is an identifier with a specific name.
Sourcepub fn consume_if(&mut self, kind: &TokenKind) -> bool
pub fn consume_if(&mut self, kind: &TokenKind) -> bool
Consume the current token if it matches the given kind.
Returns true if consumed, false otherwise.
Sourcepub fn expect(&mut self, kind: &TokenKind) -> Result<&Token, String>
pub fn expect(&mut self, kind: &TokenKind) -> Result<&Token, String>
Expect a specific token kind; return an error string if it doesn’t match.
Sourcepub fn expect_ident(&mut self) -> Result<String, String>
pub fn expect_ident(&mut self) -> Result<String, String>
Expect an identifier and return its name.
Sourcepub fn current_span(&self) -> Span
pub fn current_span(&self) -> Span
Get the current span (or a dummy span if at EOF).
Sourcepub fn skip_until(&mut self, kinds: &[TokenKind])
pub fn skip_until(&mut self, kinds: &[TokenKind])
Skip tokens until we hit one of the given token kinds (for error recovery).
Sourcepub fn drain_remaining(&mut self) -> Vec<Token>
pub fn drain_remaining(&mut self) -> Vec<Token>
Collect all tokens from the current position to the end.
Auto 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