pub enum TokenTree {
Group(TokenGroup),
Literal(LiteralToken),
Punct(Punct),
Ident(IdentToken),
}Expand description
One raw M2 token tree.
Variants§
Group(TokenGroup)
A delimited group.
Literal(LiteralToken)
A literal.
Punct(Punct)
Punctuation.
Ident(IdentToken)
An identifier or keyword spelling.
Implementations§
Source§impl TokenTree
impl TokenTree
Sourcepub fn spelling(&self) -> Option<&str>
pub fn spelling(&self) -> Option<&str>
Returns the token’s source spelling when it is a flat lexical atom.
Examples found in repository?
examples/parse_emit_walkthrough.rs (line 23)
10 fn parse(input: &mut ParseStream) -> Result<Self, TokenParseError> {
11 let Some(token) = input.next_token() else {
12 return Err(TokenParseError::UnexpectedEnd {
13 expected: "identifier",
14 span: Span::for_text(""),
15 });
16 };
17
18 let span = token.span();
19 match token {
20 TokenTree::Ident(identifier) => Ok(Self(identifier)),
21 token => Err(TokenParseError::UnexpectedToken {
22 expected: "identifier",
23 found: token.spelling().unwrap_or("group or trivia").to_owned(),
24 span,
25 }),
26 }
27 }Sourcepub fn leading_trivia(&self) -> &LeadingTrivia
pub fn leading_trivia(&self) -> &LeadingTrivia
Borrows the comments attached before this atom.
Sourcepub fn leading_trivia_mut(&mut self) -> &mut LeadingTrivia
pub fn leading_trivia_mut(&mut self) -> &mut LeadingTrivia
Mutably borrows the comments attached before this atom.
Sourcepub fn trailing_trivia(&self) -> &TrailingTrivia
pub fn trailing_trivia(&self) -> &TrailingTrivia
Borrows the comments attached after this atom.
Sourcepub fn trailing_trivia_mut(&mut self) -> &mut TrailingTrivia
pub fn trailing_trivia_mut(&mut self) -> &mut TrailingTrivia
Mutably borrows the comments attached after this atom.
Trait Implementations§
impl Eq for TokenTree
Source§impl FromIterator<TokenTree> for TokenStream
impl FromIterator<TokenTree> for TokenStream
Source§impl Lex for TokenTree
impl Lex for TokenTree
Source§fn to_tokens(&self, output: &mut TokenStream)
fn to_tokens(&self, output: &mut TokenStream)
Appends this value’s token trees to
output.Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Emits this value into a fresh token stream.
Source§impl Parse for TokenTree
impl Parse for TokenTree
Source§fn parse(input: &mut ParseStream) -> Result<Self, TokenParseError>
fn parse(input: &mut ParseStream) -> Result<Self, TokenParseError>
Consumes this value from
input. Read moreSource§impl Spanned for TokenTree
impl Spanned for TokenTree
impl StructuralPartialEq for TokenTree
Auto Trait Implementations§
impl Freeze for TokenTree
impl RefUnwindSafe for TokenTree
impl Send for TokenTree
impl Sync for TokenTree
impl Unpin for TokenTree
impl UnsafeUnpin for TokenTree
impl UnwindSafe for TokenTree
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