pub struct ParseStream<'a> { /* private fields */ }Expand description
The parsing cursor, similar to syn’s ParseBuffer.
This is the primary interface for consuming tokens during parsing.
Implementations§
Source§impl<'a> ParseStream<'a>
impl<'a> ParseStream<'a>
Sourcepub fn is_empty_raw(&self) -> bool
pub fn is_empty_raw(&self) -> bool
Returns true if there are no more tokens (including comments) except EOF.
Sourcepub fn peek(&self) -> &Token
pub fn peek(&self) -> &Token
Peek at the current token without consuming it. Comment tokens are skipped transparently.
Sourcepub fn peek_raw(&self) -> &Token
pub fn peek_raw(&self) -> &Token
Peek at the raw token at the cursor without skipping comments.
Sourcepub fn set_cursor(&self, pos: usize)
pub fn set_cursor(&self, pos: usize)
Set the current cursor position (used for backtracking).
Sourcepub fn save_state(&self) -> ParserState
pub fn save_state(&self) -> ParserState
Save the full parser state (cursor + pending_gts) for speculative parsing.
Sourcepub fn restore_state(&self, state: ParserState)
pub fn restore_state(&self, state: ParserState)
Restore the full parser state (cursor + pending_gts) after speculative parsing.
Sourcepub fn is_ident(&self, name: &str) -> bool
pub fn is_ident(&self, name: &str) -> bool
Check if the current token is an identifier with the given name.
Sourcepub fn is_any_ident(&self) -> bool
pub fn is_any_ident(&self) -> bool
Check if the current token is any identifier (including contextual keywords).
Sourcepub fn is_type_ident(&self) -> bool
pub fn is_type_ident(&self) -> bool
Check if the current token can be used as a type name.
Sourcepub fn is_keyword(&self, kind: TokenKind) -> bool
pub fn is_keyword(&self, kind: TokenKind) -> bool
Check if the current token is a given keyword.
Sourcepub fn eat(&self, expected: &TokenKind) -> bool
pub fn eat(&self, expected: &TokenKind) -> bool
Consume the next token if it matches the expected kind.
Sourcepub fn expect(&self, kind: TokenKind) -> Result<()>
pub fn expect(&self, kind: TokenKind) -> Result<()>
If the current token matches the given kind, consume it. Otherwise, report an error.
Sourcepub fn look_ahead(&self, n: usize) -> &Token
pub fn look_ahead(&self, n: usize) -> &Token
Look ahead n tokens (skipping comments).
Sourcepub fn parse_terminated<T, F>(&self, parse_item: F) -> Result<Vec<T>>
pub fn parse_terminated<T, F>(&self, parse_item: F) -> Result<Vec<T>>
Parse a comma-separated list of items terminated by some token.
Sourcepub fn parse_separated<T, F>(
&self,
can_start_fn: fn(&TokenKind) -> bool,
parse_item: F,
) -> Result<Vec<T>>
pub fn parse_separated<T, F>( &self, can_start_fn: fn(&TokenKind) -> bool, parse_item: F, ) -> Result<Vec<T>>
Parse zero or more items separated by commas, not requiring a terminator.
Sourcepub fn try_parse<T, F>(&self, f: F) -> Option<T>
pub fn try_parse<T, F>(&self, f: F) -> Option<T>
Try to parse something. If parsing fails, revert the cursor.
Sourcepub fn parse_parenthesized<T, F>(&self, f: F) -> Result<T>
pub fn parse_parenthesized<T, F>(&self, f: F) -> Result<T>
Parse something inside parentheses.
Sourcepub fn parse_braced<T, F>(&self, f: F) -> Result<T>
pub fn parse_braced<T, F>(&self, f: F) -> Result<T>
Parse something inside braces.
Sourcepub fn parse_bracketed<T, F>(&self, f: F) -> Result<T>
pub fn parse_bracketed<T, F>(&self, f: F) -> Result<T>
Parse something inside brackets.
Sourcepub fn expect_then_raw_span(&self, kind: TokenKind) -> Result<Span>
pub fn expect_then_raw_span(&self, kind: TokenKind) -> Result<Span>
Consume the expected token, then return the span of the raw token at the cursor.
Unlike expect(kind); peek().span, this does NOT skip comments after consuming.
Sourcepub fn parse_ident(&self) -> Result<Ident>
pub fn parse_ident(&self) -> Result<Ident>
Also accepts contextual keywords (record, sealed, var, yield, open, etc.)
Sourcepub fn take_errors(&self) -> Vec<Error>
pub fn take_errors(&self) -> Vec<Error>
Take any errors accumulated during parsing.
Sourcepub fn span_since(&self, start: Span) -> Span
pub fn span_since(&self, start: Span) -> Span
Create a span covering from the given start to the current position.
Sourcepub fn skip_comments_to_peek(&self)
pub fn skip_comments_to_peek(&self)
Skip past any comment tokens at the current cursor position. This is the public version for explicit comment skipping.
Sourcepub fn collect_pending_doc_comments(&self) -> Vec<Comment>
pub fn collect_pending_doc_comments(&self) -> Vec<Comment>
Collect pending doc comments (skipped by peek/advance). Returns only doc comments (/// and /** */), discards regular comments.
Sourcepub fn collect_pending_comments(&self) -> Vec<Comment>
pub fn collect_pending_comments(&self) -> Vec<Comment>
Collect all pending comments (skipped by peek/advance).
Sourcepub fn collect_leading_doc_comments(&self) -> Vec<Comment>
pub fn collect_leading_doc_comments(&self) -> Vec<Comment>
Collect and consume leading doc comments (/// and /** /). Regular comments (// and / */) are skipped.
Sourcepub fn collect_leading_comments(&self) -> Vec<Comment>
pub fn collect_leading_comments(&self) -> Vec<Comment>
Collect and consume all leading comments (both doc and regular).