pub struct NameBinder { /* private fields */ }Expand description
Compile-time variable binder for slot allocation.
Provides stack-based scoping with slot IDs into a data pool. Used during expression binding to assign variable slots.
External variables (those declared before mark_external_boundary() is called)
are tracked separately and can be retrieved via external_vars().
Implementations§
Source§impl NameBinder
impl NameBinder
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the total number of slots allocated.
Use this after bind() to determine VarStore size.
Sourcepub fn mark_external_boundary(&mut self)
pub fn mark_external_boundary(&mut self)
Mark the current stack position as the boundary between external variables and internally-bound variables.
Call this after pushing all external variables (those provided by the API user) and before binding the expression (which may introduce for/let/quantified variables).
Sourcepub fn external_vars(&self) -> impl Iterator<Item = (&QualifiedName, VarSlotId)>
pub fn external_vars(&self) -> impl Iterator<Item = (&QualifiedName, VarSlotId)>
Iterate over external variables (those pushed before mark_external_boundary()).
Returns an iterator of (name, slot) pairs for all external variables.
Sourcepub fn external_var_count(&self) -> usize
pub fn external_var_count(&self) -> usize
Get the number of external variables.
Sourcepub fn push_var(&mut self, name: QualifiedName) -> VarRef
pub fn push_var(&mut self, name: QualifiedName) -> VarRef
Push a new variable binding onto the stack.
Allocates a new slot and returns a VarRef to it.
Sourcepub fn pop_var(&mut self)
pub fn pop_var(&mut self)
Pop the most recent variable binding.
Used by for/some/every expressions after binding their body.
Sourcepub fn resolve(&self, name: &QualifiedName) -> Result<VarRef, XPathError>
pub fn resolve(&self, name: &QualifiedName) -> Result<VarRef, XPathError>
Resolve a variable name to its slot.
Searches from the top of the stack (most recent binding first). Returns XPST0008 if the variable is not bound.
Sourcepub fn resolve_with_names(
&self,
name: &QualifiedName,
names: &NameTable,
) -> Result<VarRef, XPathError>
pub fn resolve_with_names( &self, name: &QualifiedName, names: &NameTable, ) -> Result<VarRef, XPathError>
Resolve a variable name to its slot, with NameTable for error messages.
Same as resolve() but provides better error messages.