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 CategoryBuilder;
use Deriver;
use ;
use Path;
// Define and derive
let ccc = new
.with_base
.with_base
.with_terminal
.with_products
.with_exponentials
.cartesian
.build
.unwrap;
let type_system = derive;
// Generate Rust code
generate
.expect;
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.