Skip to main content

Token

Struct Token 

Source
pub struct Token {
    pub text: SymStr,
    pub code: Catcode,
}
Expand description

The core immutable syntactic primitive resulting from TeX’s read-in and expansion process We allow the fields to be public, so that we can use builder macros such as

macro_rules! T_SPACE(() => {
    Token { text: arena::pin_static(" "), code: Catcode::SPACE}
  });

Fields§

§text: SymStr

an arena id the character content for this token

§code: Catcode

a TeX catcode

Implementations§

Source§

impl Token

====================================================================== Accessors.

Source

pub fn new<T: AsRef<str>>(text: T, code: Catcode) -> Self

simple Token constructor, wrapping over text and catcode

Source

pub fn cycle_fingerprint(&self) -> u64

A cheap structural fingerprint for the cycle-detection guard (crate::cycle_guard). Matches PartialEq semantics: SPACE tokens fingerprint by catcode alone (their text is irrelevant to equality). NOT a stable hash across processes — for in-run loop detection only.

Source

pub fn get_cs_name(&self) -> SymStr

Get the CS Name of the token. This is the name that definitions will be stored under; It’s the same for various `different’ BEGIN tokens, eg.

Source

pub fn with_cs_name<R, FnR>(&self, caller: FnR) -> R
where FnR: FnOnce(&str) -> R,

Execute a closure using the CS Name of the token. This is the name that definitions will be stored under; It’s the same for various `different’ BEGIN tokens, eg.

Source

pub fn pin_cs_name(&self) -> SymStr

artificial, but avoids the data race

Source

pub fn get_primitive_name(&self) -> Option<&'static str>

Get the fixed name of a primitive catcode, or empty string otherwise

Source

pub fn get_executable_name(&self) -> String

Get the CS name only if the catcode is executable!

Source

pub fn get_executable_primitive_name(&self) -> Option<&'static str>

Intersect executable and primitive

Source

pub fn get_sym(&self) -> SymStr

Use the ticket representing the interned “text” of the token

Source

pub fn with_str<R, FnR>(&self, caller: FnR) -> R
where FnR: FnOnce(&str) -> R,

Use the interned &str “text” of the token use to_string instead for an owned String with simpler

Source

pub fn is_noexpand_family(&self) -> bool

True for any member of the \special_relax no-expand family — the representation of a \noexpand’d (expandable or undefined) CS/active token. Such a token is a CS whose NAME is \special_relax \x01 <shadowed text>, carrying the shadowed token’s identity PER-TOKEN (faithful to TeX’s no_expand_flag, which preserves cur_cs), while the whole family resolves to \special_relax’s \relax meaning (crate::state::lookup_meaning fallback). The bare \special_relax (no suffix) is the no-shadow case (\dont_expand at end-of-input). \x01 is never valid in a CS name or as an active char, so the encoding is unambiguous.

Source

pub fn noexpand_shadowed(&self) -> Option<Token>

Recover the shadowed token from a \special_relax-family token, if it shadows one (i.e. not the bare \special_relax). The shadowed token is a CS (text begins \) or an active char.

Source

pub fn get_charcode(&self) -> u32

Return the character code of character part of the token, or 256 if it is a control sequence

Source

pub fn get_catcode(&self) -> Catcode

Return the catcode of the token.

Source

pub fn is_executable(&self) -> bool

is the current one

Source

pub fn neutralize(self, extraspecials: &[char]) -> Token

neutralize really should only retroactively imitate what Semiverbatim would have done. So, it needs to neutralize those in SPECIALS NOTE that although ‘%’ gets it’s catcode changed in Semiverbatim, I’m pretty sure we do NOT want to neutralize comments (turn them into Catcode::OTHER) here, since if comments do get into the Tokens, that will introduce weird crap into the stream.

Source

pub fn as_other(&self) -> Token

Source

pub fn as_cs(&self) -> Token

Source

pub fn substitute_parameters(self, args: &[&Token]) -> Self

Source

pub fn revert(self) -> Token

A Token reverts to itself

Source

pub fn stringify(&self) -> String

A string form which is primarily used for error-reporting

Source

pub fn to_register(&self) -> Option<Rc<Register>>

Source

pub fn to_number(&self) -> Number

Source

pub fn to_dimension(&self) -> Dimension

Source

pub fn to_mu_dimension(&self) -> MuDimension

Source

pub fn to_glue(&self) -> Glue

Source

pub fn to_mu_glue(&self) -> MuGlue

Source

pub fn to_float(&self) -> Float

Source

pub fn be_digested(self) -> Result<Digested>

Source

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

Check whether the current token is defined as other. That is, whether it is equal to other, or \let to other. other is is presumed to be some “constant”, explicit token, such as T_SPACE or T_CS!("\\endcsname").

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 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, f: &mut Formatter<'_>) -> Result

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

impl<'a> From<&'a Stored> for Token

Source§

fn from(value: &'a Stored) -> Token

Converts to this type from the input type.
Source§

impl<'a> From<&'a Token> for Stored

Source§

fn from(value: &'a Token) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a Tokens> for Token

Source§

fn from(ts: &'a Tokens) -> Token

Converts to this type from the input type.
Source§

impl From<&Token> for Tokens

Source§

fn from(t: &Token) -> Tokens

Converts to this type from the input type.
Source§

impl From<&str> for Token

Source§

fn from(text: &str) -> Token

Converts to this type from the input type.
Source§

impl From<Option<Tokens>> for Token

Source§

fn from(ts_opt: Option<Tokens>) -> Token

Converts to this type from the input type.
Source§

impl From<Token> for Stored

Source§

fn from(value: Token) -> Self

Converts to this type from the input type.
Source§

impl From<Token> for Tokens

Source§

fn from(t: Token) -> Tokens

Converts to this type from the input type.
Source§

impl From<Token> for Result<Tokens>

Source§

fn from(t: Token) -> Result<Tokens>

Converts to this type from the input type.
Source§

impl From<Token> for Vec<Token>

Source§

fn from(t: Token) -> Vec<Token>

Converts to this type from the input type.
Source§

impl From<Token> for Option<Tokens>

Source§

fn from(t: Token) -> Option<Tokens>

Converts to this type from the input type.
Source§

impl From<Token> for Option<Cow<'static, Tokens>>

Source§

fn from(t: Token) -> Option<Cow<'static, Tokens>>

Converts to this type from the input type.
Source§

impl From<Token> for ArgWrap

Source§

fn from(t: Token) -> Self

Converts to this type from the input type.
Source§

impl From<Token> for RegisterValue

Source§

fn from(n: Token) -> RegisterValue

Converts to this type from the input type.
Source§

impl From<Token> for ExpansionBody

Source§

fn from(t: Token) -> ExpansionBody

Converts to this type from the input type.
Source§

impl From<Token> for Option<ExpansionBody>

Source§

fn from(t: Token) -> Option<ExpansionBody>

Converts to this type from the input type.
Source§

impl From<Tokens> for Token

Source§

fn from(ts: Tokens) -> Token

Converts to this type from the input type.
Source§

impl IntoRegisterValueOption<Option<RegisterValue>> for Token

Source§

impl IntoTokensResult<Result<Tokens, Error>> for Token

Source§

fn into_tokens_result(self) -> Result<Tokens>

Performs the conversion, used for DefMacro return values etc
Source§

impl PartialEq for Token

Compare two tokens; They are equal if they both have same catcode & string

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

Available on crate feature codegen only.
Source§

fn to_tokens(&self, stream: &mut TokenStream)

Write self to the given TokenStream. Read more
Source§

fn to_token_stream(&self) -> TokenStream

Convert self directly into a TokenStream object. Read more
Source§

fn into_token_stream(self) -> TokenStream
where Self: Sized,

Convert self directly into a TokenStream object. Read more
Source§

impl TryFrom<ArgWrap> for Token

Source§

type Error = Error

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

fn try_from(aw: ArgWrap) -> Result<Token>

Performs the conversion.

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> IntoResultArgWrap<Result<ArgWrap, Error>> for T
where T: Into<ArgWrap>,

Source§

fn into_result_argwrap(self) -> Result<ArgWrap, Error>

performs the conversion
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 = 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.