Module binding

Module binding 

Source
Expand description

All magic happens here. A module that generates interpreters for SimpleX chat command syntax.

To add support for another language it’s sufficient to implement the SyntaxInterpreter trait and then use the following builder pattern:

use simploxide_bindgen::syntax::binding::BindExt;

//..

let interpret_method = syntax_str
    .bind(YourInterpreter::new(api_type))
    // Allows to define, e.g. a function method before the interpreter body
    .prelude(|intrp, out| {
        bufwriteln!(out, :> 4, "def interpret(self):");
        intrp.offset = 8;
    })
    .generate()?;

Structs§

EnumInterpreterErr
Generator
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:
RecordContextData

Enums§

SyntaxInterpreterError

Traits§

BindExt
This trait exists to provide syntactic sugar to create the generator builder from str:
Interpretable
Represents a type with a syntax that can be interpreted as a SimpleX command. The impl should return Ok(None) when the syntax string is empty or return full implementation of the following trait:
SyntaxInterpreter
Implement interpret_ methods and use the provided Self::interpret_syntax to generate the whole interpreter body from the syntax.

Type Aliases§

DeferredGeneration
It’s just a simple closure that provides (interpreter, out_buffer) in its arguments and allows borrowing the outside context.
SyntaxInterpreterResult