Expand description
Perl-style local assignments (dynamic scope)
This module provides stack-based dynamic scoping for global state,
matching Perl’s local mechanism. Each “localized” field uses a Vec<T>
as a stack: push to shadow, pop to restore.
§RAII Guards
Each localized variable has a corresponding Guard type that pushes on
creation and pops on Drop. This prevents leaked state on early returns
or panics:
let _guard = local_current_token_guard(token);
// ... do work ...
// guard auto-pops when _guard goes out of scopeThe explicit set_*/expire_* pairs still exist for cases where
RAII doesn’t fit (e.g., cross-function push/pop with different lifetimes).
Structs§
- Local
Guard - Generic RAII guard that calls an expire function on drop. Zero-cost when the expire function is a simple fn pointer.
- Localized
- These are fields realized via Perl’s “local” mechanism in LaTeXML, but (for now) require explicit “expire” calls in Rust. Ideally their ergonomics gets improved, or we gradually phase them out.
- Suppressed
TabMarks - Disables tab marks for the lifetime of the guard, restoring the previous
count on drop —
tex.web§394macro_call:
Functions§
- align_
group_ count - decrement_
align_ group_ count - expire_
align_ group_ count - expire_
current_ token - expires the most recent (localized) current token.
- expire_
dual_ branch - expire (localized) flag for “dual branch”
- expire_
ifframe - expires the most recent (originally Perl-local)
IfFrame - expire_
reading_ alignment - expire_
state_ unlocked - get_
current_ token - gets the (localized) current token
- get_
dual_ branch - get the current value for “dual branch”
- get_
ifframe - retrieves the most recent (originally Perl-local)
IfFrame - get_
reading_ alignment - has_
reading_ alignment - increment_
align_ group_ count - initialize_
localized - Reset all localized variables to their default state. Must be called between conversion runs to prevent state pollution.
- local_
align_ group_ count - local_
align_ group_ count_ guard - Push a localized align group count; returns guard that pops on drop.
- local_
build_ template - local_
current_ token - localizes a new current token. see
Stomach::invoke_token - local_
current_ token_ guard - Push a localized current token; returns guard that pops on drop.
- local_
dual_ branch_ guard - Push a localized dual branch; returns guard that pops on drop.
- local_
ifframe_ guard - Push a localized if-frame; returns guard that pops on drop.
- local_
reading_ alignment - local_
reading_ alignment_ guard - Push a localized reading alignment; returns guard that pops on drop.
- local_
state_ unlocked - local_
state_ unlocked_ guard - Push a localized state unlocked flag; returns guard that pops on drop.
- open_
conditional_ count - Number of currently open conditional frames (
\if…whose\fihas not been digested yet). Zero at any clean point between top-level constructs — the fragment-yield seam predicate requires exactly that. - set_
align_ group_ count - set_
build_ template - set_
dual_ branch - sets the (localized) flag for “dual branch”
- set_
ifframe - sets a (originally Perl-local)
IfFramethat needs to be manually expired. - state_
is_ unlocked - take_
build_ template - with_
current_ build_ template