Struct parol_runtime::lexer::token::Token

source ·
pub struct Token<'t> {
    pub token_type: TerminalIndex,
    pub location: Location,
    pub token_number: TokenNumber,
    /* private fields */
}
Expand description

The Token<’t> type represents a scanned token. It has a reference to the scanned text in the text member.

The lifetime parameter 't refers to the lifetime of the scanned text.

Fields§

§token_type: TerminalIndex

The index of the terminal in the augmented terminal list

§location: Location

Position information

§token_number: TokenNumber

Unique token number that allows ordering of tokens from different contexts, e.g. comment tokens can be intermingled with normal tokens.

Implementations§

source§

impl<'t> Token<'t>

source

pub fn eoi(token_number: TokenNumber) -> Self

Creates an End-Of-Input token

source

pub fn with<T>( text: T, token_type: TerminalIndex, location: Location, token_number: TokenNumber ) -> Self
where T: Into<Cow<'t, str>>,

Creates a token with given values.

source

pub fn with_location(self, location: Location) -> Self

Change the location of the token after it’s creation

source

pub fn with_type(self, token_type: TerminalIndex) -> Self

Change the location of the token after it’s creation

source

pub fn is_skip_token(&self) -> bool

Indicates whether the token is normally skipped by the TokenStream. The behavior is independent from the language.

source

pub fn is_comment_token(&self) -> bool

Indicates whether the token is a comment token.

source

pub fn text(&self) -> &str

Accesses the token’s scanned text

source

pub fn to_owned(&self) -> Token<'static>

Creates an owned instance of the token from a shared reference

source

pub fn into_owned(self) -> Token<'static>

Creates an owned instance of the token and consumes self

Trait Implementations§

source§

impl<'t> Clone for Token<'t>

source§

fn clone(&self) -> Token<'t>

Returns a copy 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<'t> Debug for Token<'t>

source§

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

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

impl<'t> Default for Token<'t>

source§

fn default() -> Token<'t>

Returns the “default value” for a type. Read more
source§

impl Display for Token<'_>

source§

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

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

impl FormatToken for Token<'_>

source§

fn format(&self, terminal_names: &'static [&'static str]) -> String

Generates a formatted position which an editor can follow via mouse click.
source§

impl From<&Token<'_>> for Location

source§

fn from(token: &Token<'_>) -> Self

Converts to this type from the input type.
source§

impl From<&Token<'_>> for Range<usize>

source§

fn from(token: &Token<'_>) -> Self

Converts to this type from the input type.
source§

impl From<&Token<'_>> for Span

source§

fn from(token: &Token<'_>) -> Self

Converts to this type from the input type.
source§

impl<'t> Ord for Token<'t>

source§

fn cmp(&self, other: &Token<'t>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<'t> PartialEq for Token<'t>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'t> PartialOrd for Token<'t>

source§

fn partial_cmp(&self, other: &Token<'t>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl ToSpan for Token<'_>

source§

fn span(&self) -> Span

Calculates the span of the implementing item
source§

impl<'t> Eq for Token<'t>

source§

impl<'t> StructuralPartialEq for Token<'t>

Auto Trait Implementations§

§

impl<'t> Freeze for Token<'t>

§

impl<'t> RefUnwindSafe for Token<'t>

§

impl<'t> Send for Token<'t>

§

impl<'t> Sync for Token<'t>

§

impl<'t> Unpin for Token<'t>

§

impl<'t> UnwindSafe for Token<'t>

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
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<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,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.