Crate csw_generate

Crate csw_generate 

Source
Expand description

§csw-generate

Code generation for the Categorical Semantics Workbench.

This crate generates working type checkers, interpreters, and parsers from derived type systems. The generated code is standalone and can be used directly in your projects.

§Overview

Given a TypeSystem (from csw-derive), this crate can generate:

  • Type checkers: Verify that terms are well-typed
  • Interpreters: Evaluate terms to values
  • Parsers: Parse source code into ASTs (optional)
  • Documentation: Markdown documentation of the type system

§Example

use csw_core::CategoryBuilder;
use csw_derive::Deriver;
use csw_generate::RustGenerator;
use std::path::Path;

// Define and derive
let ccc = CategoryBuilder::new("STLC")
    .with_terminal()
    .with_products()
    .with_exponentials()
    .cartesian()
    .build()
    .unwrap();

let type_system = Deriver::derive(&ccc);

// Generate Rust code
RustGenerator::generate(&type_system, Path::new("generated/stlc/"))
    .expect("code generation failed");

§Generated Output

The generator creates a complete Rust crate:

generated/stlc/
├── Cargo.toml
├── src/
│   ├── lib.rs
│   ├── types.rs      # Type enum
│   ├── terms.rs      # Term enum
│   ├── checker.rs    # Type checker
│   └── interpreter.rs # Evaluator
└── README.md

Structs§

GeneratorOptions
Options for code generation.
RustGenerator
Rust code generator.

Enums§

RustGeneratorError
Errors that can occur during Rust code generation.

Traits§

Generator
Trait for code generators.