Skip to main content

MemberEnv

Struct MemberEnv 

Source
pub struct MemberEnv { /* private fields */ }
Expand description

Grammar-declared member state: numbered scalar and stack slots.

Recognition threads this by value along each speculative path (it is part of the parser’s memo key), so it is ordered and compares structurally. Absent slots are not stored: a slot holding 0 is distinct from one never written, but an emptied stack is canonicalized back to absent so two logically identical paths stay Eq — and keep sharing memo entries.

Scalar and stack slot numbers live in separate namespaces; the generator assigns each declared member to one or the other.

Implementations§

Source§

impl MemberEnv

Source

pub const fn new() -> Self

Source

pub fn with_initial_scalars( initial: impl IntoIterator<Item = (usize, i64)>, ) -> Self

Builds an environment holding a grammar’s declared initial scalar values.

Grammars write private bool verbatium = true; / private int level = 1;. Those initializers are part of the grammar’s meaning: a predicate reading a slot that silently started at 0 instead would reject input the source grammar accepts. Generated recognizers seed with this so a fresh recognizer — and every Self::reset_to_initial afterwards — starts where the grammar says.

Source

pub fn reset_to_initial( &mut self, initial: impl IntoIterator<Item = (usize, i64)>, )

Clears all state back to the declared initial scalar values.

This is what a recognizer reset needs: not “empty”, but the state a freshly constructed recognizer had. Stacks always reset to empty, since a declaration cannot pre-seed one.

Source

pub fn is_empty(&self) -> bool

Whether no slot has been written.

Source

pub fn scalar(&self, member: usize) -> Option<i64>

Reads a scalar slot; None when never written.

Source

pub fn set_scalar(&mut self, member: usize, value: i64)

Writes a scalar slot.

Source

pub fn add_scalar(&mut self, member: usize, delta: i64) -> i64

Adds to a scalar slot (absent reads as 0) and returns the new value.

Source

pub fn stack_top(&self, member: usize) -> Option<i64>

Top of a stack slot; None when empty or never pushed.

Source

pub fn stack_len(&self, member: usize) -> usize

Depth of a stack slot; 0 when never pushed.

Source

pub fn push_stack(&mut self, member: usize, value: i64)

Pushes onto a stack slot.

Source

pub fn pop_stack(&mut self, member: usize) -> Option<i64>

Pops a stack slot, returning the removed value, or None when empty.

An emptied stack drops its slot so it compares equal to one never pushed — otherwise push-then-pop would produce a memo key that no longer matches the equivalent untouched path.

Source

pub fn scalars(&self) -> impl Iterator<Item = (usize, i64)> + '_

Iterates written scalar slots in slot order.

Trait Implementations§

Source§

impl Clone for MemberEnv

Source§

fn clone(&self) -> MemberEnv

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemberEnv

Source§

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

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

impl Default for MemberEnv

Source§

fn default() -> MemberEnv

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

impl Eq for MemberEnv

Source§

impl Ord for MemberEnv

Source§

fn cmp(&self, other: &MemberEnv) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for MemberEnv

Source§

fn eq(&self, other: &MemberEnv) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for MemberEnv

Source§

fn partial_cmp(&self, other: &MemberEnv) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for MemberEnv

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.