pub struct ParseStream<'a> { /* private fields */ }Implementations§
Source§impl<'a> ParseStream<'a>
impl<'a> ParseStream<'a>
pub fn new(input: &'a TokenStream) -> Self
pub fn from_config(input: &'a TokenStream, config: ParseConfig) -> Self
pub fn config(&self) -> &ParseConfig
pub fn is_empty(&self) -> bool
pub fn span(&self) -> Span
pub fn fork(&self) -> Self
Sourcepub fn lookahead(&self) -> Self
pub fn lookahead(&self) -> Self
Create a non-consuming fork whose parser activity is omitted from traces.
This is intended for grammar lookahead that needs more information than
peek’s boolean result.
pub fn seek(&mut self, other: &Self)
Source§impl<'a> ParseStream<'a>
impl<'a> ParseStream<'a>
pub fn remaining(&self) -> usize
pub fn curr(&self) -> Option<&TokenTree>
Sourcepub fn nth(&self, n: usize) -> Option<&TokenTree>
pub fn nth(&self, n: usize) -> Option<&TokenTree>
Look ahead n tokens without consuming (nth(0) == curr). When a glued
punct has been split, the pending half is nth(0) and the real stream
follows it.
pub fn prev(&self) -> Option<&TokenTree>
pub fn peek<T: Peek>(&mut self) -> bool
pub fn parse<T: Parse>(&mut self) -> Result<T, ParseError>
Sourcepub fn parse_if<T: Parse>(&mut self) -> Option<T>
pub fn parse_if<T: Parse>(&mut self) -> Option<T>
Parse T if it matches; leave the stream unchanged otherwise.
Sourcepub fn parse_while<T: Parse>(&mut self) -> Vec<T>
pub fn parse_while<T: Parse>(&mut self) -> Vec<T>
Parse T repeatedly while it matches, collecting results. Never errors.
Sourcepub fn parse_until_empty<T: Parse>(&mut self) -> Result<Vec<T>, ParseError>
pub fn parse_until_empty<T: Parse>(&mut self) -> Result<Vec<T>, ParseError>
Parse T until the stream is empty, propagating the first error.
Sourcepub fn skip_while<T: Parse>(&mut self) -> &mut Self
pub fn skip_while<T: Parse>(&mut self) -> &mut Self
Discard leading T tokens while they match. Returns self for chaining.
Sourcepub fn skip_if<T: Parse>(&mut self) -> &mut Self
pub fn skip_if<T: Parse>(&mut self) -> &mut Self
Discard one T if it matches. Returns self for chaining.
Sourcepub fn skip_until<F: Fn(Option<&TokenTree>) -> bool>(
&mut self,
pred: F,
) -> &mut Self
pub fn skip_until<F: Fn(Option<&TokenTree>) -> bool>( &mut self, pred: F, ) -> &mut Self
Advance past tokens until pred(curr()) is true (does NOT consume the matching token).
Returns self for chaining.
pub fn advance_by(&mut self, n: usize) -> Option<&[TokenTree]>
Sourcepub fn advance(&mut self) -> Option<&TokenTree>
pub fn advance(&mut self) -> Option<&TokenTree>
move the iterator forward and return the token. Consumes a pending split half first if one is present.
Sourcepub fn eat_punct_head(&mut self, head: &str) -> Option<Span>
pub fn eat_punct_head(&mut self, head: &str) -> Option<Span>
Consume the next token as the single-char punct spelled head. If the
next token is a longer glued punct that starts with head (e.g. >>,
>=, >>=), peel off the first char and leave the remainder as a pending
split token. Returns the span for the consumed head punct, or None if
the next token isn’t a punct starting with head.
Sourcepub fn parse_group(&mut self, delim: Delim) -> Result<TokenStream, ParseError>
pub fn parse_group(&mut self, delim: Delim) -> Result<TokenStream, ParseError>
Consume a group with the given delimiter and return its inner token stream. The caller can then create a new ParseStream over the returned stream.
Sourcepub fn parse_group_spanned(
&mut self,
delim: Delim,
) -> Result<(DelimSpan, TokenStream), ParseError>
pub fn parse_group_spanned( &mut self, delim: Delim, ) -> Result<(DelimSpan, TokenStream), ParseError>
Like parse_group, but also returns the group’s
DelimSpan (the open/close spans of its delimiters).