Skip to main content

TokenTree

Enum TokenTree 

Source
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

Source

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 26)
13    fn parse(input: &mut ParseStream) -> Result<Self, TokenParseError> {
14        let Some(token) = input.next_token() else {
15            return Err(TokenParseError::UnexpectedEnd {
16                expected: "identifier",
17                span: Span::for_text(""),
18            });
19        };
20
21        let span = token.span();
22        match token {
23            TokenTree::Ident(identifier) => Ok(Self(identifier)),
24            token => Err(TokenParseError::UnexpectedToken {
25                expected: "identifier",
26                found: token.spelling().unwrap_or("group or trivia").to_owned(),
27                span,
28            }),
29        }
30    }
Source

pub fn leading_trivia(&self) -> &LeadingTrivia

Borrows the comments attached before this atom.

Source

pub fn leading_trivia_mut(&mut self) -> &mut LeadingTrivia

Mutably borrows the comments attached before this atom.

Source

pub fn trailing_trivia(&self) -> &TrailingTrivia

Borrows the comments attached after this atom.

Source

pub fn trailing_trivia_mut(&mut self) -> &mut TrailingTrivia

Mutably borrows the comments attached after this atom.

Trait Implementations§

Source§

impl Clone for TokenTree

Source§

fn clone(&self) -> TokenTree

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TokenTree

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TokenTree

Source§

impl FromIterator<TokenTree> for TokenStream

Source§

fn from_iter<T: IntoIterator<Item = TokenTree>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl Lex for TokenTree

Source§

fn to_tokens(&self, output: &mut TokenStream)

Appends this value’s token trees to output.
Source§

fn to_token_stream(&self) -> TokenStream

Emits this value into a fresh token stream.
Source§

fn to_m2(&self) -> String

Renders this value as normalized Macaulay2 source.
Source§

impl Parse for TokenTree

Source§

fn parse(input: &mut ParseStream) -> Result<Self, TokenParseError>

Consumes this value from input. Read more
Source§

impl PartialEq for TokenTree

Source§

fn eq(&self, other: &TokenTree) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Spanned for TokenTree

Source§

fn try_span(&self) -> Option<Span>

Returns the smallest span covering this value, when its constituents share one source snapshot.
Source§

fn span(&self) -> Span

Returns the smallest span covering this value. Read more
Source§

fn expect_span(&self) -> Span

Returns this value’s span when one source snapshot covers it. Read more
Source§

impl StructuralPartialEq for TokenTree

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, !>

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.