Skip to main content

Token

Struct Token 

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

Encapsulates the information contained in the current token. We only ever create one of these, but it is cleaner to keep the data in a separate class. Port of Token.

Implementations§

Source§

impl Token

Source

pub fn new(source: SourceId) -> Token

A fresh none token with an empty range in source.

Source

pub fn kind(&self) -> TokenKind

\return the kind of this token.

Source

pub fn is_res_word(&self) -> bool

\return true if this token is a reserved word.

Source

pub fn is_template_literal(&self) -> bool

\return true if this token is one of the four template-literal kinds.

Source

pub fn start_loc(&self) -> SMLoc

\return the location of the first byte of the token.

Source

pub fn end_loc(&self) -> SMLoc

\return the location one past the last byte of the token.

Source

pub fn source_range(&self) -> SMRange

\return the half-open source range covered by the token.

Source

pub fn get_numeric_literal(&self) -> f64

\return the value of a numeric_literal token.

Source

pub fn get_identifier(&self) -> AtomBytes

\return the interned name of an identifier token.

Source

pub fn get_private_identifier(&self) -> AtomBytes

\return the interned name of a private_identifier token, without the leading # (which is still part of the token’s source range).

Source

pub fn get_res_word_identifier(&self) -> AtomBytes

\return the interned spelling of a reserved-word token.

Source

pub fn get_res_word_or_identifier(&self) -> AtomBytes

\return the interned spelling of an identifier or reserved word, for the many places where the grammar accepts either.

Source

pub fn get_string_literal(&self) -> AtomBytes

\return the cooked value of a string_literal token, with escapes and line continuations already processed.

Source

pub fn get_string_literal_raw_value(&self) -> AtomBytes

\return the raw (undecoded) text of a JSX string literal. Only set by Token::set_jsx_string_literal; the normal string path leaves it unset.

Source

pub fn get_string_literal_contains_escapes(&self) -> bool

\return whether a string_literal contained any escape or line continuation. The parser uses this to build a directive’s raw text: with no escapes the raw equals the cooked value, otherwise it must re-slice the source between the quotes.

Source

pub fn get_template_literal_contains_not_escapes(&self) -> bool

\return whether the template literal token contains a NotEscapeSequence.

Source

pub fn get_template_value(&self) -> Option<AtomBytes>

\return the cooked value of a template-literal token, or None if it contains a NotEscapeSequence (legal only in a tagged template).

Source

pub fn get_template_raw_value(&self) -> AtomBytes

\return the Template Raw Value (TRV) of a template-literal token.

Source

pub fn get_bigint_literal(&self) -> AtomBytes

\return the value of a bigint_literal token as text, never converted to a number: the literal without its trailing n and with numeric separators removed, but with any radix prefix kept (0xF_Fn -> 0xFF). This is the ESTree bigint property.

Source

pub fn get_bigint_literal_raw_value(&self) -> AtomBytes

\return the raw source text of a bigint_literal token, including any radix prefix and the trailing n.

Source

pub fn get_regexp_literal(&self) -> RegExpLiteral

\return the body and flags of a regexp_literal token.

Source

pub fn get_jsx_text_value(&self) -> AtomBytes

\return the value of a jsx_text token, with HTML entities decoded.

Source

pub fn get_jsx_text_raw(&self) -> AtomBytes

\return the raw source text of a jsx_text token, with HTML entities left as written.

Trait Implementations§

Source§

impl Clone for Token

Source§

fn clone(&self) -> Token

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 Token

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Token

§

impl RefUnwindSafe for Token

§

impl Send for Token

§

impl Sync 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> 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 = 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.