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
impl MemberEnv
pub const fn new() -> Self
Sourcepub fn with_initial_scalars(
initial: impl IntoIterator<Item = (usize, i64)>,
) -> Self
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.
Sourcepub fn reset_to_initial(
&mut self,
initial: impl IntoIterator<Item = (usize, i64)>,
)
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.
Sourcepub fn scalar(&self, member: usize) -> Option<i64>
pub fn scalar(&self, member: usize) -> Option<i64>
Reads a scalar slot; None when never written.
Sourcepub fn set_scalar(&mut self, member: usize, value: i64)
pub fn set_scalar(&mut self, member: usize, value: i64)
Writes a scalar slot.
Sourcepub fn add_scalar(&mut self, member: usize, delta: i64) -> i64
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.
Sourcepub fn stack_top(&self, member: usize) -> Option<i64>
pub fn stack_top(&self, member: usize) -> Option<i64>
Top of a stack slot; None when empty or never pushed.
Sourcepub fn push_stack(&mut self, member: usize, value: i64)
pub fn push_stack(&mut self, member: usize, value: i64)
Pushes onto a stack slot.
Sourcepub fn pop_stack(&mut self, member: usize) -> Option<i64>
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.