csw-generate 0.1.0

Code generation for the Categorical Semantics Workbench - generate type checkers and interpreters from derived type systems
Documentation
//! Code generator traits and utilities.

use csw_derive::TypeSystem;
use std::path::Path;

/// Trait for code generators.
///
/// Implement this trait to add support for generating code in a new language.
pub trait Generator {
    /// The error type for this generator.
    type Error: std::error::Error;

    /// Generate code for the given type system.
    ///
    /// # Arguments
    ///
    /// * `ts` - The type system to generate code for
    /// * `output_dir` - Directory to write generated files to
    fn generate(ts: &TypeSystem, output_dir: &Path) -> Result<(), Self::Error>;
}

/// Options for code generation.
#[derive(Clone, Debug, Default)]
pub struct GeneratorOptions {
    /// Generate a type checker
    pub checker: bool,

    /// Generate an interpreter
    pub interpreter: bool,

    /// Generate a parser
    pub parser: bool,

    /// Generate documentation
    pub docs: bool,

    /// Generate tests
    pub tests: bool,
}

impl GeneratorOptions {
    /// Create options for generating everything.
    pub fn all() -> Self {
        Self {
            checker: true,
            interpreter: true,
            parser: true,
            docs: true,
            tests: true,
        }
    }

    /// Create options for generating only the checker.
    pub fn checker_only() -> Self {
        Self {
            checker: true,
            ..Default::default()
        }
    }
}