Resrap

Struct Resrap 

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

Resrap is the main access point for single-threaded uses. It’s a collection of grammars which can be generated using parsing grammar.

Implementations§

Source§

impl Resrap

Source

pub fn new() -> Self

Creates and returns a new Resrap instance. The returned instance starts with no loaded grammars.

Source

pub fn parse_grammar( &mut self, name: String, grammar: String, ) -> Result<(), String>

Parses a grammar string and stores it under the given name.

§Arguments
  • name - A unique identifier for this grammar (e.g., “C”), should be in ABNF format (Check osdc/resrap for more info on that).
  • grammar - The grammar string to parse
§Returns

Returns error generated while parsing

Source

pub fn parse_grammar_file( &mut self, name: String, location: String, ) -> Result<(), String>

Parses a grammar from a file and stores it under the given name.

§Arguments
  • name - A unique identifier for this grammar (e.g., “C”), should be in ABNF format (Check osdc/resrap for more info on that).
  • location - Path to the grammar file
§Returns

Returns error generated while parsing

Source

pub fn generate_with_seed( &self, name: &str, starting_node: String, seed: u64, tokens: usize, ) -> Result<Vec<String>, &str>

Generates content from the grammar identified by ‘name’ with a seed.

§Arguments
  • name - The grammar name to use
  • starting_node - The starting symbol in the grammar for generation
  • seed - A numeric seed to make generation deterministic
  • tokens - Number of tokens to generate
§Returns

A string containing the generated content.

Trait Implementations§

Source§

impl Default for Resrap

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Resrap

§

impl RefUnwindSafe for Resrap

§

impl Send for Resrap

§

impl Sync for Resrap

§

impl Unpin for Resrap

§

impl UnwindSafe for Resrap

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