Struct flexi_parse::TokenStream
source · pub struct TokenStream { /* private fields */ }Expand description
A sequence of tokens.
This is the return type of
Group::token_stream, and can be created
from a proc_macro::TokenStream or
proc_macro2::TokenStream.
Implementations§
source§impl TokenStream
impl TokenStream
sourcepub fn prepare_whitespace(&mut self)
pub fn prepare_whitespace(&mut self)
Removes all whitespace that doesn’t come at the start of a line.
Note that the parse* functions remove all whitespace.
sourcepub fn remove_blank_space(&mut self)
pub fn remove_blank_space(&mut self)
Removes all non-newline whitespace from self.
Note that the parse* functions will remove all whitespace.
sourcepub fn remove_whitespace(&mut self)
pub fn remove_whitespace(&mut self)
Removes all whitespace tokens from this stream.
This method is automatically called by the parse* functions.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if there are no tokens in self.
Examples found in repository?
examples/lox/main.rs (line 439)
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
fn parse(input: ParseStream) -> Result<Self> {
let name: Ident = input.parse()?;
let mut contents: Group<Parentheses> = input.parse()?;
contents.remove_whitespace();
let Parentheses(span) = contents.delimiters();
let tokens = contents.into_token_stream();
let params: Vec<Ident> = if tokens.is_empty() {
vec![]
} else {
let params: Punctuated<Ident, Punct![","]> =
Punctuated::parse_separated.parse(tokens)?;
params.into_iter().collect()
};
if params.len() >= 255 {
input.add_error(input.new_error(
"Can't have more than 254 parameters".to_string(),
span,
error_codes::TOO_MANY_ARGS,
));
}
let mut contents: Group<Braces> = input.parse()?;
contents.remove_whitespace();
let body = block.parse(contents.into_token_stream())?;
Ok(Function { name, params, body })
}sourcepub fn append(&mut self, other: &mut TokenStream)
pub fn append(&mut self, other: &mut TokenStream)
Add another TokenStream to the end of self.
Trait Implementations§
source§impl Clone for TokenStream
impl Clone for TokenStream
source§fn clone(&self) -> TokenStream
fn clone(&self) -> TokenStream
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for TokenStream
impl Debug for TokenStream
source§impl Display for TokenStream
impl Display for TokenStream
source§impl<A: ToTokens> Extend<A> for TokenStream
impl<A: ToTokens> Extend<A> for TokenStream
source§fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
source§impl<'a> From<&'a TokenStream> for ParseBuffer<'a>
impl<'a> From<&'a TokenStream> for ParseBuffer<'a>
source§fn from(value: &'a TokenStream) -> Self
fn from(value: &'a TokenStream) -> Self
Converts to this type from the input type.
source§impl<'a> From<TokenStream> for ParseBuffer<'a>
impl<'a> From<TokenStream> for ParseBuffer<'a>
source§fn from(value: TokenStream) -> Self
fn from(value: TokenStream) -> Self
Converts to this type from the input type.
source§impl From<TokenStream> for TokenStream
Available on crate features proc-macro and proc-macro2 only.
impl From<TokenStream> for TokenStream
Available on crate features
proc-macro and proc-macro2 only.source§fn from(value: TokenStream) -> Self
fn from(value: TokenStream) -> Self
Converts to this type from the input type.
source§impl From<TokenStream> for TokenStream
Available on crate feature proc-macro2 only.
impl From<TokenStream> for TokenStream
Available on crate feature
proc-macro2 only.source§fn from(value: TokenStream2) -> Self
fn from(value: TokenStream2) -> Self
Converts to this type from the input type.
source§impl Hash for TokenStream
impl Hash for TokenStream
source§impl PartialEq for TokenStream
impl PartialEq for TokenStream
source§fn eq(&self, other: &TokenStream) -> bool
fn eq(&self, other: &TokenStream) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl PartialOrd for TokenStream
impl PartialOrd for TokenStream
source§fn partial_cmp(&self, other: &TokenStream) -> Option<Ordering>
fn partial_cmp(&self, other: &TokenStream) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moresource§impl ToTokens for TokenStream
impl ToTokens for TokenStream
source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
Append
self to the given TokenStream.source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Convert
self directly into a TokenStream.source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
Convert
self directly into a TokenStream.source§impl ToTokens for TokenStream
Available on crate feature proc-macro2 only.
impl ToTokens for TokenStream
Available on crate feature
proc-macro2 only.source§fn to_tokens(&self, tokens: &mut TokenStream2)
fn to_tokens(&self, tokens: &mut TokenStream2)
source§fn to_token_stream(&self) -> TokenStream2
fn to_token_stream(&self) -> TokenStream2
source§fn into_token_stream(self) -> TokenStream2
fn into_token_stream(self) -> TokenStream2
source§impl<'a> TryFrom<&'a TokenStream> for TokenStream
Available on crate feature proc-macro2 only.
impl<'a> TryFrom<&'a TokenStream> for TokenStream
Available on crate feature
proc-macro2 only.source§impl TryFrom<Arc<SourceFile>> for TokenStream
impl TryFrom<Arc<SourceFile>> for TokenStream
source§impl TryFrom<TokenStream> for TokenStream
Available on crate feature proc-macro2 only.
impl TryFrom<TokenStream> for TokenStream
Available on crate feature
proc-macro2 only.impl StructuralPartialEq for TokenStream
Auto Trait Implementations§
impl RefUnwindSafe for TokenStream
impl Send for TokenStream
impl Sync for TokenStream
impl Unpin 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