pub struct Generator<'g> { /* private fields */ }Expand description
Generates strings that a rule accepts.
Deterministic: the same seed, options and sequence of calls produce the same strings, within
a crate version (D15). Constructible only from a CheckedGrammar (D1).
Implementations§
Source§impl<'g> Generator<'g>
impl<'g> Generator<'g>
Sourcepub fn new(grammar: &'g CheckedGrammar, seed: u64) -> Self
pub fn new(grammar: &'g CheckedGrammar, seed: u64) -> Self
Creates a generator seeded with seed.
Sourcepub fn with_options(self, options: GenOptions) -> Self
pub fn with_options(self, options: GenOptions) -> Self
Sets the generation options.
Sourcepub const fn steps(&self) -> u64
pub const fn steps(&self) -> u64
How many nodes have been visited during the most recent call.
Reset by every Generator::generate, so one call’s budget is never spent by the last.
That differs from crate::Recognizer::steps, which counts over the whole life of a
recognizer: a generator is asked for many independent strings, while a recognizer is
bound to one input and answers questions about it.
The counter GenOptions::max_steps limits, and what tests assert against rather than
wall-clock time (D31).
Sourcepub fn uncovered(&mut self, rule: &str) -> Result<usize, GenError>
pub fn uncovered(&mut self, rule: &str) -> Result<usize, GenError>
How many coverage units rule can reach that have not been covered yet.
Counted over the generatable graph, so a branch the generator would never take is not counted against it (D10). Zero means every branch reachable from this rule has been taken by some successful call.
With GenOptions::coverage set, this is also the bound: each successful call
reduces it by at least one, so it reaches zero within this many calls.
§Errors
As Generator::generate, for the same reasons: a rule that cannot be generated from
has no coverage to report.
Sourcepub fn generate(&mut self, rule: &str) -> Result<String, GenError>
pub fn generate(&mut self, rule: &str) -> Result<String, GenError>
Generates one string that rule accepts.
§Errors
GenError::UnknownRule if there is no such rule; the compatibility limits of
SCOPE.md 6.6 if the rule can reach a prose value or an unrepresentable terminal;
GenError::NoFiniteExpansion if it matches nothing at all; or a resource limit.