Skip to main content

Token

Enum Token 

Source
pub enum Token {
    Literal(Literal),
    Identifier(Ident),
    Punct {
        op: PunctOp,
        span: Span,
    },
    OpenDelim {
        delimiter: Delimiter,
        span: Span,
    },
    CloseDelim {
        delimiter: Delimiter,
        span: Span,
    },
    DocComment {
        text: String,
        inner: bool,
        span: Span,
    },
    Error {
        message: String,
        span: Span,
    },
}
Expand description

A flattened token that represents elements from a TokenTree stream.

Groups are flattened into OpenDelim and CloseDelim tokens, making parsing simpler by removing nesting from the token stream.

§Examples

use cel_parser::lex_lexer::{LexLexer, Token};

let input: proc_macro2::TokenStream = "name".parse()?;
let token = LexLexer::new(input.into_iter()).next().unwrap();
assert!(matches!(token, Token::Identifier(id) if id == "name"));

Variants§

§

Literal(Literal)

A literal value (integer, string, boolean, or float) with eager discrimination.

§

Identifier(Ident)

An identifier.

§

Punct

A punctuation operator storing all one to three characters inline.

Fields

§op: PunctOp

The operator (e.g., “+”, “&&”, “<=”).

§span: Span

Span for error reporting.

§

OpenDelim

Opening delimiter (flattened from Group).

Fields

§delimiter: Delimiter

The type of delimiter (Parenthesis, Brace, Bracket).

§span: Span

Span for error reporting.

§

CloseDelim

Closing delimiter (flattened from Group).

Fields

§delimiter: Delimiter

The type of delimiter (Parenthesis, Brace, Bracket).

§span: Span

Span for error reporting.

§

DocComment

A recognized //////! doc comment, unwrapped from the #[doc = "..."]/ #![doc = "..."] attribute-shaped token sequence proc_macro2 produces for it. General #[...] attribute syntax is not supported — see Token::Error.

Fields

§text: String

The comment’s text: the doc-attribute string literal’s value verbatim (including its leading space), e.g. " the total" for /// the total.

§inner: bool

true for //!/#![doc] (inner), false for ////#[doc] (outer).

§span: Span

The # token’s span.

§

Error

An unsupported attribute shape or a literal Syn cannot parse.

Fields

§message: String

A description of what was expected instead.

§span: Span

Where the mismatch was detected.

Trait Implementations§

Source§

impl Debug for Token

Source§

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

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

impl HasSpan for Token

Source§

fn span(&self) -> Span

Returns the token’s preserved source or diagnostic span.

Auto Trait Implementations§

§

impl !Send for Token

§

impl !Sync for Token

§

impl Freeze for Token

§

impl RefUnwindSafe for Token

§

impl Unpin for Token

§

impl UnsafeUnpin for Token

§

impl UnwindSafe for Token

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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.