Generator

Struct Generator 

Source
pub struct Generator<'s, SI: SyntaxInterpreter> { /* private fields */ }
Expand description

A helper type that consumes the interpreter and generates the whole code block with it. The block itself is generated with prelude and postlude callbacks. E.g. for Python this snippet can be used to generate the interpret method:

record_type
    .syntax
    .bind(PythonRecordInterpreter::new(&record_type))
    .prelude(|intrp, out| {
        bufwriteln!(out, :>4, "def interpret(self):");
        intrp.offset = 8;
    })
    // There is no need to use the .postlude(|intrp, out|) callback because
    // in Python functions and methods don't have closing brackets or keywords
    .generate()?;

To construct the generator witt a bind method import BindExt trait.

Implementations§

Source§

impl<'s, SI: SyntaxInterpreter> Generator<'s, SI>

Source

pub fn new(syntax: &'s str, interpreter: SI) -> Self

Source

pub fn prelude<F>(self, f: F) -> Self
where F: 's + FnOnce(&mut SI, &mut String) -> SyntaxInterpreterResult<'s, (), SI::Error>,

Source

pub fn postlude<F>(self, f: F) -> Self
where F: 's + FnOnce(&mut SI, &mut String) -> SyntaxInterpreterResult<'s, (), SI::Error>,

Source

pub fn generate(self) -> SyntaxInterpreterResult<'s, Option<String>, SI::Error>

Auto Trait Implementations§

§

impl<'s, SI> Freeze for Generator<'s, SI>
where SI: Freeze,

§

impl<'s, SI> !RefUnwindSafe for Generator<'s, SI>

§

impl<'s, SI> !Send for Generator<'s, SI>

§

impl<'s, SI> !Sync for Generator<'s, SI>

§

impl<'s, SI> Unpin for Generator<'s, SI>
where SI: Unpin,

§

impl<'s, SI> !UnwindSafe for Generator<'s, SI>

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.