Skip to main content

Token

Struct Token 

Source
pub struct Token {
    pub name: TokenText,
    pub tin: Tin,
    pub val: Value,
    pub src: TokenText,
    pub len: usize,
    pub site: Site,
    pub err: TokenCode,
    pub why: TokenCode,
    pub use_data: Option<Box<HashMap<String, Value>>>,
    pub ignored: Option<Box<Token>>,
    pub val_fn: Option<TokenValFunc>,
}
Expand description

A single lexical token produced by the lexer.

Fields§

§name: TokenText§tin: Tin§val: Value§src: TokenText§len: usize

UTF-8 byte length of src, paired with the byte offset site.si.

§site: Site

Where in the source this token starts.

§err: TokenCode§why: TokenCode§use_data: Option<Box<HashMap<String, Value>>>

Plugin diagnostic details, boxed and absent until something writes one. Prefer use_data() and use_data_mut() to reaching through the Option; the shape is public only so that a Token can still be built with a struct literal. It is boxed because a HashMap is 48 bytes inline, a token is cloned about six times per input construct, and almost no token ever carries a detail. Measured by padding Token, 96 bytes of it is worth 3% to 12% depending on the grammar.

§ignored: Option<Box<Token>>

Optional ignored trivia associated with this token. Negotiated re-lexing carries it to the replacement token.

§val_fn: Option<TokenValFunc>

Optional semantic value callback. val remains the eagerly produced fallback and the value shown by raw token inspection.

Implementations§

Source§

impl Token

Source

pub fn new( name: impl AsRef<str>, tin: Tin, val: Value, src: impl Into<TokenText>, pnt: Point, ) -> Self

Source

pub fn use_data(&self) -> &HashMap<String, Value>

Plugin diagnostic details. Empty unless something wrote one.

Source

pub fn use_data_mut(&mut self) -> &mut HashMap<String, Value>

Mutable access, allocating the bag on first write.

Source

pub fn no_token() -> Self

Source

pub fn is_no_token(&self) -> bool

Source

pub fn bad(&mut self, err: &str) -> &mut Self

Source

pub fn bad_with_details( &mut self, err: &str, details: impl IntoIterator<Item = (String, Value)>, ) -> &mut Self

Mark this token bad and deep-merge plugin diagnostic details into its existing use_data bag. This is the typed Rust form of token.bad(code, details).

Source

pub fn with_val_func(self, callback: TokenValFunc) -> Self

Attach an already shared lazy value callback.

Source

pub fn with_lazy_value( self, callback: impl Fn(&mut Rule, &mut Context) -> Value + Send + Sync + 'static, ) -> Self

Attach a lazy value callback without constructing a wrapper first.

Source

pub fn resolve_val(&self, rule: &mut Rule, context: &mut Context) -> Value

Resolve the semantic token value against the live parse state.

Trait Implementations§

Source§

impl Clone for Token

Source§

fn clone(&self) -> Self

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

impl Default for Token

Source§

fn default() -> Self

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

impl Display for Token

Source§

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

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

impl PartialEq for Token

Source§

fn eq(&self, other: &Self) -> 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 !RefUnwindSafe for Token

§

impl !UnwindSafe for Token

§

impl Freeze for Token

§

impl Send for Token

§

impl Sync for Token

§

impl Unpin for Token

§

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

Source§

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

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.