#[repr(C)]pub struct Token {
pub text: SymStr,
pub code: Catcode,
pub prov: u16,
}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}
});#[repr(C)] pins the field order text, code, prov (loc): code stays at byte 4, where it sat before
prov existed, and with a two-byte Catcode the struct has no padding (prov at 6). Rust’s default layout put
prov at 4 and code at 6, which made every move of a token through Option<Token>, CheckedRead::Tok and the
read path’s Result slot a 4-piece field-wise copy (gullet::read_internal_token_checked: +1.29 % instructions
on an empty article; +1.14 % with repr(C) alone, the pad byte still copied apart; +0.65 % gap-free). The guard
is token_layout_code_at_byte_4.
Fields§
§text: SymStran arena id the character content for this token
code: Catcodea TeX catcode
prov: u16Out-of-band field provenance (0 = none): the frontmatter field whose stored value this token
is a token of (the kernel \title/\author stamp their store, latexml_engine \lx@field@mark), so the
ink digested from it is known for that field’s print. Not part of TeX’s token: excluded from PartialEq
(\ifx, \meaning, \pdfstrcmp, xstring compare as pdflatex does), never written, never dumped. It sits in
what was the struct’s padding: Token stays 8 bytes (token_size_invariant). OXIDIZED_DESIGN #715.
Implementations§
Source§impl Token
impl Token
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 from_sym(text: SymStr, code: Catcode) -> Self
pub fn from_sym(text: SymStr, code: Catcode) -> Self
Construct a token directly from an already-interned SymStr without
re-probing or interning into the arena.
Sourcepub fn try_cs<T: AsRef<str>>(text: T) -> Option<Self>
pub fn try_cs<T: AsRef<str>>(text: T) -> Option<Self>
Look up an already-interned control-sequence token without interning a
new symbol if text has never been seen.
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. A SPACE token’s code is always 32: tex.web §289 space_token = 2^8·spacer + " " and §349 (mid_line + car_ret → cur_chr := " ") — an
end-of-line becomes a space with character code 32, whatever produced it.
This token keeps its "\n" TEXT (Perl’s data model, PRESERVE_NEWLINES,
the tex= reversion) but Perl’s getCharcode returned ord("\n") = 10
for it (Token.pm:243), so \if compared an end-of-line space unequal to a
typed one: stringstrings’ \if\BlankSpace#1 took the wrong branch on a
\@for item that was a lone newline and desynchronised the conditional
stack (Extra \else), then tikzviolinplots’ KDE loop ran away
(batch 56gc, OXIDIZED_DESIGN #260).
Sourcepub fn group_step(&self) -> i32
pub fn group_step(&self) -> i32
How far this token moves a brace count: 1 for a begin-group, -1 for an end-group, else 0. Brace balance is a property of a run of tokens, no reading of what they spell.
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 is_active_or_cs(&self) -> bool
pub fn is_active_or_cs(&self) -> bool
A control sequence or an active character (Catcode::is_active_or_cs).
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").
Sourcepub fn spelled_as(&self, other: &Token) -> bool
pub fn spelled_as(&self, other: &Token) -> bool
Whether this token is other itself, as defined_as compares: the same catcode and, but for a space, the same
text.
Sourcepub fn meaning_name(&self) -> Option<Token>
pub fn meaning_name(&self) -> Option<Token>
The token this one’s meaning names, as defined_as reads it: the control sequence of its definition, or the token
a \let copied. One meaning lookup; a character token that is not active names none.
Sourcepub fn with_meaning_name<R>(
&self,
f: impl FnOnce(Option<Token>, Option<&Stored>) -> R,
) -> R
pub fn with_meaning_name<R>( &self, f: impl FnOnce(Option<Token>, Option<&Stored>) -> R, ) -> R
Calls f with meaning_name and the meaning itself, from one meaning lookup: for a caller that tests a token
against several primitives (defined_as looks the meaning up per call) or reads its definition too
(tex_fonts::read_font_ident). A character token that is not active has neither.
Trait Implementations§
impl Copy for Token
impl Eq for Token
The comparison is reflexive (a token is equal to itself, a space to any space).
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 Hash for Token
Hashes what PartialEq compares: the catcode, and the text unless a space (every space is one), so that equal
tokens hash alike (a set of the distinct tokens read: the frontmatter rehearsal’s \let-copy scan).
impl Hash for Token
Hashes what PartialEq compares: the catcode, and the text unless a space (every space is one), so that equal
tokens hash alike (a set of the distinct tokens read: the frontmatter rehearsal’s \let-copy scan).
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 RegisterCs for Token
impl RegisterCs for Token
fn register_cs(self) -> Token
Source§impl RegisterCs for &Token
impl RegisterCs for &Token
fn register_cs(self) -> Token
Source§impl ToTokens for Token
Available on crate feature codegen only.
impl ToTokens for Token
codegen only.