Token

Struct Token 

Source
pub struct Token { /* private fields */ }
Expand description

A single token.

This struct is written in such a way that it can be passed in registers. The actual representation is TokenRepr, but it should not be accessed directly.

Implementations§

Source§

impl Token

Source

pub const EOF: Token

The EOF token.

Source

pub const DUMMY: Token

A dummy token that will be thrown away later.

Source

pub const fn new(kind: TokenKind, span: Span) -> Token

Creates a new token.

Source

pub fn from_ast_ident(ident: Ident) -> Token

Recovers a Token from an Ident.

Source

pub fn ident(&self) -> Option<Ident>

Creates a new identifier if the kind is TokenKind::Ident.

Source

pub fn lit(&self) -> Option<TokenLit>

Returns the literal if the kind is TokenKind::Literal.

Source

pub fn lit_kind(&self) -> Option<TokenLitKind>

Returns this token’s literal kind, if any.

Source

pub fn comment(&self) -> Option<(bool, DocComment)>

Returns the comment if the kind is TokenKind::Comment, and whether it’s a doc-comment.

Source

pub fn doc(&self) -> Option<DocComment>

Returns the comment if the kind is TokenKind::Comment.

Does not check that is_doc is true.

Source

pub fn is_op(&self) -> bool

Returns true if the token is an operator.

Source

pub fn as_unop(&self, is_postfix: bool) -> Option<UnOp>

Returns the token as a unary operator, if any.

Source

pub fn as_binop(&self) -> Option<BinOp>

Returns the token as a binary operator, if any.

Source

pub fn as_binop_eq(&self) -> Option<BinOp>

Returns the token as a binary operator, if any.

Source

pub fn is_ident(&self) -> bool

Returns true if the token is an identifier.

Source

pub fn is_lit(&self) -> bool

Returns true if the token is a literal. Includes bool literals.

Source

pub fn is_keyword(&self, kw: Symbol) -> bool

Returns true if the token is a given keyword, kw.

Source

pub fn is_keyword_any(&self, kws: &[Symbol]) -> bool

Returns true if the token is any of the given keywords.

Source

pub fn is_used_keyword(&self) -> bool

Returns true if the token is a keyword used in the language.

Source

pub fn is_unused_keyword(&self) -> bool

Returns true if the token is a keyword reserved for possible future use.

Source

pub fn is_reserved_ident(&self, yul: bool) -> bool

Returns true if the token is a keyword.

Source

pub fn is_non_reserved_ident(&self, yul: bool) -> bool

Returns true if the token is an identifier, but not a keyword.

Source

pub fn is_elementary_type(&self) -> bool

Returns true if the token is an elementary type name.

Note that this does not include [u]fixedMxN types.

Source

pub fn is_bool_lit(&self) -> bool

Returns true if the token is the identifier true or false.

Source

pub fn is_numeric_lit(&self) -> bool

Returns true if the token is a numeric literal.

Source

pub fn is_integer_lit(&self) -> bool

Returns true if the token is the integer literal.

Source

pub fn is_rational_lit(&self) -> bool

Returns true if the token is the rational literal.

Source

pub fn is_str_lit(&self) -> bool

Returns true if the token is a string literal.

Source

pub fn is_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool

Returns true if the token is an identifier for which pred holds.

Source

pub fn is_eof(&self) -> bool

Returns true if the token is an end-of-file marker.

Source

pub fn is_open_delim(&self, d: Delimiter) -> bool

Returns true if the token is the given open delimiter.

Source

pub fn is_close_delim(&self, d: Delimiter) -> bool

Returns true if the token is the given close delimiter.

Source

pub fn is_comment(&self) -> bool

Returns true if the token is a normal comment (not a doc-comment).

Source

pub fn is_comment_or_doc(&self) -> bool

Returns true if the token is a comment or doc-comment.

Source

pub fn is_location_specifier(&self) -> bool

Returns true if the token is a location specifier.

Source

pub fn is_mutability_specifier(&self) -> bool

Returns true if the token is a mutability specifier.

Source

pub fn is_visibility_specifier(&self) -> bool

Returns true if the token is a visibility specifier.

Source

pub fn full_description(&self) -> impl Display

Returns this token’s full description: {self.description()} '{self.kind}'.

Source

pub fn as_str(&self) -> &str

Returns the string representation of the token.

Source

pub fn description(self) -> Option<TokenDescription>

Returns this token’s description, if any.

Trait Implementations§

Source§

impl Clone for Token

Source§

fn clone(&self) -> Token

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Token

Source§

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

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

impl Deref for Token

Source§

type Target = TokenRepr

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<Token as Deref>::Target

Dereferences the value.
Source§

impl DerefMut for Token

Source§

fn deref_mut(&mut self) -> &mut <Token as Deref>::Target

Mutably dereferences the value.
Source§

impl From<Ident> for Token

Source§

fn from(ident: Ident) -> Token

Converts to this type from the input type.
Source§

impl PartialEq for Token

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Token

Source§

impl Eq for Token

Auto Trait Implementations§

§

impl Freeze for Token

§

impl RefUnwindSafe for Token

§

impl Send for Token

§

impl Sync for Token

§

impl Unpin 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> 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, R> CollectAndApply<T, R> for T

Source§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

Source§

type Output = R

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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<Q> ToOwnedEquivalent<<Q as ToOwned>::Owned> for Q
where Q: ToOwned + Eq + ?Sized,

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 16 bytes