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: SymStran arena id the character content for this token
code: Catcodea TeX catcode
Implementations§
Source§impl Token
======================================================================
Accessors.
impl Token
====================================================================== Accessors.
Sourcepub fn new<T: AsRef<str>>(text: T, code: Catcode) -> Self
pub fn new<T: AsRef<str>>(text: T, code: Catcode) -> Self
simple Token constructor, wrapping over text and catcode
Sourcepub fn cycle_fingerprint(&self) -> u64
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.
Sourcepub fn get_cs_name(&self) -> SymStr
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.
Sourcepub fn with_cs_name<R, FnR>(&self, caller: FnR) -> R
pub fn with_cs_name<R, FnR>(&self, caller: FnR) -> 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.
Sourcepub fn pin_cs_name(&self) -> SymStr
pub fn pin_cs_name(&self) -> SymStr
artificial, but avoids the data race
Sourcepub fn get_primitive_name(&self) -> Option<&'static str>
pub fn get_primitive_name(&self) -> Option<&'static str>
Get the fixed name of a primitive catcode, or empty string otherwise
Sourcepub fn get_executable_name(&self) -> String
pub fn get_executable_name(&self) -> String
Get the CS name only if the catcode is executable!
Sourcepub fn get_executable_primitive_name(&self) -> Option<&'static str>
pub fn get_executable_primitive_name(&self) -> Option<&'static str>
Intersect executable and primitive
Sourcepub fn with_str<R, FnR>(&self, caller: FnR) -> R
pub fn with_str<R, FnR>(&self, caller: FnR) -> R
Use the interned &str “text” of the token
use to_string instead for an owned String with simpler
Sourcepub fn is_noexpand_family(&self) -> bool
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.
Sourcepub fn noexpand_shadowed(&self) -> Option<Token>
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.
Sourcepub fn get_charcode(&self) -> u32
pub fn get_charcode(&self) -> u32
Return the character code of character part of the token, or 256 if it is a control sequence
Sourcepub fn get_catcode(&self) -> Catcode
pub fn get_catcode(&self) -> Catcode
Return the catcode of the token.
Sourcepub fn is_executable(&self) -> bool
pub fn is_executable(&self) -> bool
is the current one
Sourcepub fn neutralize(self, extraspecials: &[char]) -> Token
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.
pub fn as_other(&self) -> Token
pub fn as_cs(&self) -> Token
pub fn substitute_parameters(self, args: &[&Token]) -> Self
pub fn to_register(&self) -> Option<Rc<Register>>
pub fn to_number(&self) -> Number
pub fn to_dimension(&self) -> Dimension
pub fn to_mu_dimension(&self) -> MuDimension
pub fn to_glue(&self) -> Glue
pub fn to_mu_glue(&self) -> MuGlue
pub fn to_float(&self) -> Float
pub fn be_digested(self) -> Result<Digested>
Sourcepub fn defined_as(&self, other: &Token) -> bool
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§
impl Copy for Token
Source§impl From<Token> for RegisterValue
impl From<Token> for RegisterValue
Source§fn from(n: Token) -> RegisterValue
fn from(n: Token) -> RegisterValue
Source§impl From<Token> for ExpansionBody
impl From<Token> for ExpansionBody
Source§fn from(t: Token) -> ExpansionBody
fn from(t: Token) -> ExpansionBody
Source§impl IntoRegisterValueOption<Option<RegisterValue>> for Token
impl IntoRegisterValueOption<Option<RegisterValue>> for Token
fn into_register_value_option(self) -> Option<RegisterValue>
Source§impl IntoTokensResult<Result<Tokens, Error>> for Token
impl IntoTokensResult<Result<Tokens, Error>> for Token
Source§fn into_tokens_result(self) -> Result<Tokens>
fn into_tokens_result(self) -> Result<Tokens>
Source§impl PartialEq for Token
Compare two tokens; They are equal if they both have same catcode & string
impl PartialEq for Token
Compare two tokens; They are equal if they both have same catcode & string
Source§impl ToTokens for Token
Available on crate feature codegen only.
impl ToTokens for Token
codegen only.