pub struct ExplicitBuilder { /* private fields */ }Expand description
Builder for Explicit automata.
Allocate states with ExplicitBuilder::new_state, add rules with
ExplicitBuilder::add_rule, mark accepting states with
ExplicitBuilder::add_accepting, then call ExplicitBuilder::build.
The builder checks that every state in every rule was allocated by this builder. This catches many accidental mixups between automata early.
Implementations§
Source§impl ExplicitBuilder
impl ExplicitBuilder
Sourcepub fn new_state(&mut self) -> StateId
pub fn new_state(&mut self) -> StateId
Allocate and return a fresh state.
States are assigned densely starting at StateId(0).
Sourcepub fn add_accepting(&mut self, q: StateId)
pub fn add_accepting(&mut self, q: StateId)
Mark a state as accepting.
A tree is accepted when its root can be assigned one of the accepting states. Passing a state not allocated by this builder panics.
Sourcepub fn add_rule(&mut self, f: Symbol, children: Vec<StateId>, q: StateId)
pub fn add_rule(&mut self, f: Symbol, children: Vec<StateId>, q: StateId)
Add a bottom-up transition rule.
children is the exact child-state tuple for the rule. An empty vector
creates a nullary rule, suitable for leaf symbols. Passing STUCK or a
state not allocated by this builder panics.
Sourcepub fn add_weighted_rule(
&mut self,
f: Symbol,
children: Vec<StateId>,
q: StateId,
weight: f64,
)
pub fn add_weighted_rule( &mut self, f: Symbol, children: Vec<StateId>, q: StateId, weight: f64, )
Add a weighted bottom-up transition rule.
children is the exact child-state tuple for the rule. An empty vector
creates a nullary rule, suitable for leaf symbols. Passing STUCK or a
state not allocated by this builder panics.
Sourcepub fn build(self) -> Explicit
pub fn build(self) -> Explicit
Build the explicit automaton.
Panics if duplicate transitions were added. Use Self::try_build to
receive a typed error instead.
Sourcepub fn try_build(self) -> Result<Explicit, ExplicitBuildError>
pub fn try_build(self) -> Result<Explicit, ExplicitBuildError>
Build the explicit automaton, rejecting duplicate transitions.
Multiple rules with the same symbol and children but different result
states are preserved, making the automaton nondeterministic for that
query. The exact same (symbol, children, result) transition may not be
added twice, regardless of weight.
Trait Implementations§
Source§impl Clone for ExplicitBuilder
impl Clone for ExplicitBuilder
Source§fn clone(&self) -> ExplicitBuilder
fn clone(&self) -> ExplicitBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more