pub trait TokenStream: Sized {
type Token: Clone;
type Span: SpanLike;
type Spanned<T: Clone>: SpannedLike<T, Span = Self::Span>;
Show 17 methods
// Required methods
fn peek_token_raw(&self) -> Option<&Self::Spanned<Self::Token>>;
fn next_raw(&mut self) -> Option<Self::Spanned<Self::Token>>;
fn cursor(&self) -> usize;
fn rewind(&mut self, pos: usize);
fn fork(&self) -> Self;
fn cursor_span(&self) -> Option<Self::Span>;
fn last_span(&self) -> Option<Self::Span>;
fn span_at(&self, pos: usize) -> Option<Self::Span>;
// Provided methods
fn peek_token(&self) -> Option<&Self::Spanned<Self::Token>> { ... }
fn next(&mut self) -> Option<Self::Spanned<Self::Token>> { ... }
fn peek<T: Peek<Token = Self::Token>>(&self) -> bool { ... }
fn parse<T: Parse<Token = Self::Token>>(&mut self) -> Result<T, T::Error> { ... }
fn parse_spanned<T: Parse<Token = Self::Token> + Clone>(
&mut self,
) -> Result<Self::Spanned<T>, T::Error> { ... }
fn is_empty(&self) -> bool { ... }
fn remaining(&self) -> usize { ... }
fn ensure_consumed(&self) -> Result<(), Error> { ... }
fn span_range(&self, range: Range<usize>) -> Self::Span { ... }
}Expand description
A stream of tokens for parsing.
Provides the core interface for lexer output consumption. Token streams support peeking, consumption, forking for lookahead, and rewinding.
Required Associated Types§
Sourcetype Spanned<T: Clone>: SpannedLike<T, Span = Self::Span>
type Spanned<T: Clone>: SpannedLike<T, Span = Self::Span>
A spanned wrapper type for associating values with spans.
Required Methods§
Sourcefn peek_token_raw(&self) -> Option<&Self::Spanned<Self::Token>>
fn peek_token_raw(&self) -> Option<&Self::Spanned<Self::Token>>
Peeks at the next token without consuming (includes whitespace).
Sourcefn next_raw(&mut self) -> Option<Self::Spanned<Self::Token>>
fn next_raw(&mut self) -> Option<Self::Spanned<Self::Token>>
Consumes and returns the next token (includes whitespace).
Sourcefn cursor_span(&self) -> Option<Self::Span>
fn cursor_span(&self) -> Option<Self::Span>
Returns the span at the current cursor position.
Provided Methods§
Sourcefn peek_token(&self) -> Option<&Self::Spanned<Self::Token>>
fn peek_token(&self) -> Option<&Self::Spanned<Self::Token>>
Peeks at the next significant token (skips whitespace by default).
Sourcefn next(&mut self) -> Option<Self::Spanned<Self::Token>>
fn next(&mut self) -> Option<Self::Spanned<Self::Token>>
Consumes and returns the next significant token.
Sourcefn peek<T: Peek<Token = Self::Token>>(&self) -> bool
fn peek<T: Peek<Token = Self::Token>>(&self) -> bool
Checks if the next token matches type T without consuming.
Sourcefn parse<T: Parse<Token = Self::Token>>(&mut self) -> Result<T, T::Error>
fn parse<T: Parse<Token = Self::Token>>(&mut self) -> Result<T, T::Error>
Parses a value of type T from the stream.
Sourcefn parse_spanned<T: Parse<Token = Self::Token> + Clone>(
&mut self,
) -> Result<Self::Spanned<T>, T::Error>
fn parse_spanned<T: Parse<Token = Self::Token> + Clone>( &mut self, ) -> Result<Self::Spanned<T>, T::Error>
Parses a value and wraps it with its source span.
fn is_empty(&self) -> bool
Sourcefn remaining(&self) -> usize
fn remaining(&self) -> usize
Returns the number of remaining significant tokens (excluding whitespace).
The default implementation counts tokens via peek_token() and next(),
which may be inefficient. Implementations may override this for better performance.
Sourcefn ensure_consumed(&self) -> Result<(), Error>
fn ensure_consumed(&self) -> Result<(), Error>
Sourcefn span_range(&self, range: Range<usize>) -> Self::Span
fn span_range(&self, range: Range<usize>) -> Self::Span
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.