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
impl Token
Sourcepub fn is_res_word(&self) -> bool
pub fn is_res_word(&self) -> bool
\return true if this token is a reserved word.
Sourcepub fn is_template_literal(&self) -> bool
pub fn is_template_literal(&self) -> bool
\return true if this token is one of the four template-literal kinds.
Sourcepub fn source_range(&self) -> SMRange
pub fn source_range(&self) -> SMRange
\return the half-open source range covered by the token.
Sourcepub fn get_numeric_literal(&self) -> f64
pub fn get_numeric_literal(&self) -> f64
\return the value of a numeric_literal token.
Sourcepub fn get_identifier(&self) -> AtomBytes
pub fn get_identifier(&self) -> AtomBytes
\return the interned name of an identifier token.
Sourcepub fn get_private_identifier(&self) -> AtomBytes
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).
Sourcepub fn get_res_word_identifier(&self) -> AtomBytes
pub fn get_res_word_identifier(&self) -> AtomBytes
\return the interned spelling of a reserved-word token.
Sourcepub fn get_res_word_or_identifier(&self) -> AtomBytes
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.
Sourcepub fn get_string_literal(&self) -> AtomBytes
pub fn get_string_literal(&self) -> AtomBytes
\return the cooked value of a string_literal token, with escapes
and line continuations already processed.
Sourcepub fn get_string_literal_raw_value(&self) -> AtomBytes
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.
Sourcepub fn get_string_literal_contains_escapes(&self) -> bool
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.
Sourcepub fn get_template_literal_contains_not_escapes(&self) -> bool
pub fn get_template_literal_contains_not_escapes(&self) -> bool
\return whether the template literal token contains a NotEscapeSequence.
Sourcepub fn get_template_value(&self) -> Option<AtomBytes>
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).
Sourcepub fn get_template_raw_value(&self) -> AtomBytes
pub fn get_template_raw_value(&self) -> AtomBytes
\return the Template Raw Value (TRV) of a template-literal token.
Sourcepub fn get_bigint_literal(&self) -> AtomBytes
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.
Sourcepub fn get_bigint_literal_raw_value(&self) -> AtomBytes
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.
Sourcepub fn get_regexp_literal(&self) -> RegExpLiteral
pub fn get_regexp_literal(&self) -> RegExpLiteral
\return the body and flags of a regexp_literal token.
Sourcepub fn get_jsx_text_value(&self) -> AtomBytes
pub fn get_jsx_text_value(&self) -> AtomBytes
\return the value of a jsx_text token, with HTML entities decoded.
Sourcepub fn get_jsx_text_raw(&self) -> AtomBytes
pub fn get_jsx_text_raw(&self) -> AtomBytes
\return the raw source text of a jsx_text token, with HTML entities
left as written.