Skip to main content

Generator

Struct Generator 

Source
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>

Source

pub fn new(grammar: &'g CheckedGrammar, seed: u64) -> Self

Creates a generator seeded with seed.

Source

pub fn with_options(self, options: GenOptions) -> Self

Sets the generation options.

Source

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

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'g> Freeze for Generator<'g>

§

impl<'g> RefUnwindSafe for Generator<'g>

§

impl<'g> Send for Generator<'g>

§

impl<'g> Sync for Generator<'g>

§

impl<'g> Unpin for Generator<'g>

§

impl<'g> UnsafeUnpin for Generator<'g>

§

impl<'g> UnwindSafe for Generator<'g>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.