pub struct Tokens(/* private fields */);Expand description
Tokens are a thin wrapper over a vector of Token objects
They are usually read from a Mouth and treated as an immutable interface.
For access to the inner Token contents, use one of the unlist methods.
Implementations§
Source§impl Tokens
impl Tokens
Sourcepub fn unlist_ref(&self) -> &Vec<Token>
pub fn unlist_ref(&self) -> &Vec<Token>
Return a reference to the tokens making up this Tokens
Sourcepub fn unlist_mut(&mut self) -> &mut Vec<Token>
pub fn unlist_mut(&mut self) -> &mut Vec<Token>
Return a mutable reference to the tokens making up this Tokens
Sourcepub fn starts_with_text(&self, prefix: &str) -> bool
pub fn starts_with_text(&self, prefix: &str) -> bool
Zero-alloc equivalent of self.to_string().starts_with(prefix).
Walks tokens byte-by-byte into prefix using the same Display
semantics as eq_text (COMMENT skipped, ARG prefixed with #).
Returns true once the full prefix has been consumed, even if
more token text follows.
Sourcepub fn eq_text(&self, target: &str) -> bool
pub fn eq_text(&self, target: &str) -> bool
Zero-alloc equivalent of self.to_string() == target. Walks the
contained tokens byte-by-byte, skipping COMMENT tokens (matching
Display for Tokens) and prefixing ARG tokens with # (matching
Display for Token). Returns true iff the rendered text exactly
equals target. Used by DefMacro bodies that check keyword
values like true / false / swapnumber without wanting to
allocate a fresh String per invocation.
pub fn revert(self) -> Vec<Token>
Sourcepub fn to_number(&self) -> Number
pub fn to_number(&self) -> Number
to_number casts back to a parsed Number (usually via gullet::read_number) which had to be re-converted to a Tokens for reentering the expansion flow
Sourcepub fn to_dimension(&self) -> Dimension
pub fn to_dimension(&self) -> Dimension
to_dimension casts back to a parsed Dimension (usually via gullet::read_dimension) which had to be re-converted to a Tokens for reentering the expansion flow
Sourcepub fn to_glue(&self) -> Glue
pub fn to_glue(&self) -> Glue
to_glue casts back to a parsed Glue (usually via gullet::read_glue) which had to be re-converted to a Tokens for reentering the expansion flow
Sourcepub fn to_mu_glue(&self) -> MuGlue
pub fn to_mu_glue(&self) -> MuGlue
to_mu_glue casts back to a parsed MuGlue (usually via gullet::read_mu_glue) which had to be re-converted to a Tokens for reentering the expansion flow
Sourcepub fn to_mu_dimension(&self) -> MuDimension
pub fn to_mu_dimension(&self) -> MuDimension
to_mu_dimension casts back to a parsed MuGlue (usually via gullet::read_mu_glue) which had to be re-converted to a Tokens for reentering the expansion flow
Sourcepub fn to_float(&self) -> Float
pub fn to_float(&self) -> Float
to_float casts back to a parsed Float (usually via gullet::read_float) which had to be re-converted to a Tokens for reentering the expansion flow
Sourcepub fn to_keyvals(&self) -> Result<KeyVals>
pub fn to_keyvals(&self) -> Result<KeyVals>
to_keyvals casts back to a parsed KeyVals (usually via a KeyVals parameter type) which had to be re-converted to a Tokens for reentering the expansion flow
Sourcepub fn unwrap_or_default(self) -> Tokens
pub fn unwrap_or_default(self) -> Tokens
returns self, for compatibility convenience with Option
Sourcepub fn be_digested(self) -> Result<Digested>
pub fn be_digested(self) -> Result<Digested>
digest the current Tokens
Sourcepub fn neutralize(self, extraspecials: &[char]) -> Tokens
pub fn neutralize(self, extraspecials: &[char]) -> Tokens
neutralize each token
Sourcepub fn is_balanced(&self) -> bool
pub fn is_balanced(&self) -> bool
Checks if any BEGIN/END code groups are correctly nested and closed
Sourcepub fn substitute_parameters(&self, args: &[Option<Cow<'_, Tokens>>]) -> Self
pub fn substitute_parameters(&self, args: &[Option<Cow<'_, Tokens>>]) -> Self
substitutes the parameters (ARG catcode) in a Tokens list for concrete arguments
Sourcepub fn untex(self) -> String
pub fn untex(self) -> String
Consumes a Tokens to a string containing TeX that created it (or could have). Note that this is not necessarily the original TeX code; expansions or other substitutions may have taken place.
Design decision: The Perl UnTeX inserts %\n line-breaks (TeX comment + newline) when
a token string would exceed 78 characters. The Rust port deliberately omits this feature.
Line-break insertion is purely cosmetic and makes test expectations fragile — the %\n
appears verbatim in tex= attributes of ltx:Math elements, causing test XML files to
contain % escape sequences that depend on exact token lengths. We instead always
produce compact, single-line output. Test .xml files should not contain % .
Sourcepub fn untex_string(self) -> TeXString
pub fn untex_string(self) -> TeXString
untex, typed — the blessed way to get TeX markup out of
a Tokens and back into a tokenizing sink.
Prefer this over untex() whenever the string is destined for
Tokenize! / mouth::tokenize / mouth::tokenize_internal: it is the
only Tokens→TeXString conversion, so the sink’s signature proves
the round trip cannot weld a control word (\v S stays \v S, not
\vS). untex() itself is unchanged for the callers that want a plain
String (a tex= attribute, a log message, a comparison).
Sourcepub fn pack_parameters(self) -> Result<Self>
pub fn pack_parameters(self) -> Result<Self>
Packs repeated CC_PARAM tokens into CC_ARG tokens for use as a macro body (and other token lists) Also unwraps \noexpand tokens, since that is also needed for macro bodies (but not strictly part of packing parameters)
Sourcepub fn strip_braces(self) -> Self
pub fn strip_braces(self) -> Self
Trims outer braces (if they balance each other). Strips exactly 1 layer of matching outer braces by default. Should this also trim whitespace? or only if there are braces?
Sourcepub fn strip_braces_n(self, layers: usize) -> Self
pub fn strip_braces_n(self, layers: usize) -> Self
Trims layers outer brace pairs (if they balance each other).
Also trims whitespace outer to the removed braces.
Follows the Perl Tokens.pm algorithm: first collects all balanced
brace pairs, then strips from outside-in, only removing pairs that
span the full remaining width.
Trait Implementations§
Source§impl From<RegisterValue> for Tokens
impl From<RegisterValue> for Tokens
Source§fn from(v: RegisterValue) -> Tokens
fn from(v: RegisterValue) -> Tokens
Source§impl From<Tokens> for RegisterValue
impl From<Tokens> for RegisterValue
Source§fn from(n: Tokens) -> RegisterValue
fn from(n: Tokens) -> RegisterValue
Source§impl From<Tokens> for ExpansionBody
impl From<Tokens> for ExpansionBody
Source§fn from(t: Tokens) -> ExpansionBody
fn from(t: Tokens) -> ExpansionBody
Source§impl IntoOption<Option<Reversion>> for Tokens
impl IntoOption<Option<Reversion>> for Tokens
Source§fn into_option(self) -> Option<Reversion>
fn into_option(self) -> Option<Reversion>
Source§impl IntoRegisterValueOption<Option<RegisterValue>> for Tokens
impl IntoRegisterValueOption<Option<RegisterValue>> for Tokens
fn into_register_value_option(self) -> Option<RegisterValue>
Source§impl IntoTokensResult<Result<Tokens, Error>> for Tokens
impl IntoTokensResult<Result<Tokens, Error>> for Tokens
Source§fn into_tokens_result(self) -> Result<Tokens>
fn into_tokens_result(self) -> Result<Tokens>
Source§impl ToTokens for Tokens
Available on crate feature codegen only.
impl ToTokens for Tokens
codegen only.