csw-generate

Crates.iocsw-generate
lib.rscsw-generate
version0.1.0
created_at2025-12-05 16:54:15.412209+00
updated_at2025-12-05 16:54:15.412209+00
descriptionCode generation for the Categorical Semantics Workbench - generate type checkers and interpreters from derived type systems
homepagehttps://github.com/ibrahimcesar/categorical-semantics-workbench
repositoryhttps://github.com/ibrahimcesar/categorical-semantics-workbench
max_upload_size
id1968701
size24,216
Ibrahim Cesar (ibrahimcesar)

documentation

https://docs.rs/csw-generate

README

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

Usage

use csw_core::CategoryBuilder;
use csw_derive::Deriver;
use csw_generate::{RustGenerator, Generator};
use std::path::Path;

// Define and derive
let ccc = CategoryBuilder::new("STLC")
    .with_base("Int")
    .with_base("Bool")
    .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

Supported Targets

Currently supported:

  • Rust: Full support for type checker + interpreter

Planned:

  • TypeScript
  • Python
  • Haskell

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Commit count: 0

cargo fmt