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 436)
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
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 })
}
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 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 PartialEq<TokenStream> for TokenStream
impl PartialEq<TokenStream> 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 TryFrom<Rc<SourceFile, Global>> for TokenStream
impl TryFrom<Rc<SourceFile, Global>> for TokenStream
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