Skip to main content

Module local_assignments

Module local_assignments 

Source
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 scope

The explicit set_*/expire_* pairs still exist for cases where RAII doesn’t fit (e.g., cross-function push/pop with different lifetimes).

Structs§

LocalGuard
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.
SuppressedTabMarks
Disables tab marks for the lifetime of the guard, restoring the previous count on drop — tex.web §394 macro_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 \fi has 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) IfFrame that needs to be manually expired.
state_is_unlocked
take_build_template
with_current_build_template