# 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
```rust
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.