Skip to main content

Token

Enum Token 

Source
pub enum Token {
    Punctuation,
    Keyword,
    Entity,
    Support,
    Constant,
    String,
    Comment,
    Invalid,
}
Expand description

What a glyph in a fenced code block is to the language it is written in — the syntax-highlighting vocabulary, one level down from Role.

Eight classes rather than the hundreds of scopes a Sublime grammar names, and the same eight plates colours its published pages with: each is the first atom of a TextMate scope — keyword.control.rust is a keyword, string.quoted.double a string — and a palette that tells these eight apart is a palette that reads. Finer than this is a theme’s business, and a theme is exactly what core does not carry: like Role, a token says what a glyph is and leaves what colour to paint it to the frontend, so the same document highlights in ANSI colours on a terminal and in an Hsla in a GUI.

Only a glyph with Role::Code carries one, and only in a fenced block whose info string names a language the bundled grammars know (see crate::syntax). Inline `code`, an indented block, a bare fence, and a language no grammar covers all carry None, and draw in the code colour exactly as they did before this existed.

Variants§

§

Punctuation

Brackets, operators, separators — punctuation.*. The quietest class: a frontend typically draws it in the comment colour, so the " opening a string reads as the string’s and not as its own thing.

§

Keyword

A reserved word or a storage modifier — keyword.* and storage.* (fn, let, pub, const, if).

§

Entity

A name the author defined or named — entity.* (a function or type at its definition) and variable.* (a parameter, a field, self).

§

Support

A name the language or its library provides — support.* (a builtin function, a standard type).

§

Constant

A literal that is not a string — constant.* (a number, true, an escape sequence, a character literal).

§

String

A string literal, delimiters included — string.*.

§

Comment

A comment — comment.*. A frontend typically italicises it as well.

§

Invalid

What the grammar could not parse — invalid.*.

Implementations§

Source§

impl Token

Source

pub const ALL: [Self; 8]

Every token, in precedence order: a scope whose atoms name two of these (punctuation.definition.string.begin is both punctuation and string) is the later one, so a string’s quotes read as string and a comment’s // as comment. The frontends iterate this to build their palettes, so a token added here is one a palette test immediately demands an entry for.

Source

pub const fn name(self) -> &'static str

The class id a frontend keys a stylesheet or a palette on — the first atom of the scope it stands for, so a rule written for plates output (plates-keyword) and one written for leaf (leaf-t-keyword) name the same thing.

Source

pub fn from_name(name: &str) -> Option<Self>

The token a class id names, or None for a name outside the vocabulary — the inverse of name.

Source

pub const fn index(self) -> usize

This token’s position in ALL — the index a frontend’s own palette array is keyed by, the way MarkColor::index keys the highlighter washes.

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 Copy for Token

Source§

impl Debug for Token

Source§

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

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

impl Eq for Token

Source§

impl PartialEq for Token

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq 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 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.