Skip to main content

ParseStream

Struct ParseStream 

Source
pub struct ParseStream<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> ParseStream<'a>

Source

pub fn new(input: &'a TokenStream) -> Self

Source

pub fn from_config(input: &'a TokenStream, config: ParseConfig) -> Self

Source

pub fn config(&self) -> &ParseConfig

Source

pub fn is_empty(&self) -> bool

Source

pub fn span(&self) -> Span

Source

pub fn fork(&self) -> Self

Source

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.

Source

pub fn seek(&mut self, other: &Self)

Source§

impl<'a> ParseStream<'a>

Source

pub fn remaining(&self) -> usize

Source

pub fn curr(&self) -> Option<&TokenTree>

Source

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.

Source

pub fn prev(&self) -> Option<&TokenTree>

Source

pub fn peek<T: Peek>(&mut self) -> bool

Source

pub fn parse<T: Parse>(&mut self) -> Result<T, ParseError>

Source

pub fn parse_if<T: Parse>(&mut self) -> Option<T>

Parse T if it matches; leave the stream unchanged otherwise.

Source

pub fn parse_while<T: Parse>(&mut self) -> Vec<T>

Parse T repeatedly while it matches, collecting results. Never errors.

Source

pub fn parse_until_empty<T: Parse>(&mut self) -> Result<Vec<T>, ParseError>

Parse T until the stream is empty, propagating the first error.

Source

pub fn skip_while<T: Parse>(&mut self) -> &mut Self

Discard leading T tokens while they match. Returns self for chaining.

Source

pub fn skip_if<T: Parse>(&mut self) -> &mut Self

Discard one T if it matches. Returns self for chaining.

Source

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.

Source

pub fn advance_by(&mut self, n: usize) -> Option<&[TokenTree]>

Source

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.

Source

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.

Source

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.

Source

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).

Auto Trait Implementations§

§

impl<'a> !Send for ParseStream<'a>

§

impl<'a> !Sync for ParseStream<'a>

§

impl<'a> Freeze for ParseStream<'a>

§

impl<'a> RefUnwindSafe for ParseStream<'a>

§

impl<'a> Unpin for ParseStream<'a>

§

impl<'a> UnsafeUnpin for ParseStream<'a>

§

impl<'a> UnwindSafe for ParseStream<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.