litto 0.1.0

Building blocks for DSL scripting language interpreters that interact with native Rust code.
Documentation
//! A mini language that extends `tinylang` with more types and stdlib
//! functions.

#[cfg(feature = "parse")]
pub(crate) mod parser;
pub mod stdlib;
pub mod types;
pub use super::tinylang;
pub use super::tinylang::TinyLang;
use crate::Interpreter;

/// Extends `TinyLang` with more stdlib functions and types.
#[derive(Clone)]
pub struct MiniLang;

impl Interpreter for MiniLang {
    type Value = <TinyLang as Interpreter>::Value;
    type Error = <TinyLang as Interpreter>::Error;
    type Env = <TinyLang as Interpreter>::Env;
    type Expr = <TinyLang as Interpreter>::Expr;

    fn parse(code: &str) -> Result<Self::Expr, Self::Error> {
        #[cfg(feature = "parse")]
        {
            parser::parse(code)
        }
        #[cfg(not(feature = "parse"))]
        {
            let _ = code;
            Err("parse() requires 'parse' feature".into())
        }
    }

    fn global_env() -> Self::Env {
        let env = TinyLang::global_env();
        stdlib::register(&env);
        env
    }

    fn evaluate(env: &Self::Env, expr: &Self::Expr) -> Result<Self::Value, Self::Error> {
        TinyLang::evaluate(env, expr)
    }
}