Skip to main content

kdl_codegen/
lib.rs

1//! # club-kdl-codegen
2//!
3//! Generate type / schema definitions in multiple languages from a single
4//! KDL schema file (KDL-first). Targets: **Rust**, **TypeScript**, **Zod**,
5//! and **SurrealQL**.
6//!
7//! ## Pipeline
8//!
9//! ```text
10//! *.kdl  ──parser──▶  Schema IR  ──emitter──▶  Rust / TypeScript / Zod / SurrealQL
11//! ```
12//!
13//! The intermediate [`ir::Schema`] representation decouples parsing from
14//! emission: the parser is written once, and each target is one [`Emitter`]
15//! implementation.
16//!
17//! See the design memory `mem_1Cb5mWnMTdzXfJVoNGFwup` and `ROADMAP.md`
18//! (Phase 1) for the full plan.
19
20pub mod emit;
21pub mod ir;
22pub mod parser;
23
24/// A code generation target. Each language emitter ([`emit::RustEmitter`] /
25/// [`emit::TypeScriptEmitter`] / [`emit::ZodEmitter`] /
26/// [`emit::SurrealQlEmitter`]) implements this trait against the shared
27/// [`ir::Schema`].
28pub trait Emitter {
29    /// Render the given schema into target-language source text.
30    fn emit(&self, schema: &ir::Schema) -> String;
31}