Skip to main content

NameBinder

Struct NameBinder 

Source
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

Source

pub fn new() -> Self

Create a new empty name binder.

Source

pub fn len(&self) -> usize

Get the total number of slots allocated.

Use this after bind() to determine VarStore size.

Source

pub fn is_empty(&self) -> bool

Check if any slots have been allocated.

Source

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).

Source

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.

Source

pub fn external_var_count(&self) -> usize

Get the number of external variables.

Source

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.

Source

pub fn pop_var(&mut self)

Pop the most recent variable binding.

Used by for/some/every expressions after binding their body.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for NameBinder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NameBinder

Source§

fn default() -> NameBinder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSendSync for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.