clifford_codegen/spec/mod.rs
1//! Algebra specification parsing and representation.
2//!
3//! This module provides types and functions for parsing TOML specifications
4//! that describe geometric algebras and their types.
5//!
6//! # Specification Format
7//!
8//! Specifications are written in TOML with the following structure:
9//!
10//! ```toml
11//! [algebra]
12//! name = "euclidean3" # Required: identifier
13//! module_path = "euclidean::dim3" # Optional: Rust module path
14//! description = "3D Euclidean GA" # Optional: documentation
15//!
16//! [signature]
17//! positive = ["e1", "e2", "e3"] # Basis vectors squaring to +1
18//! negative = [] # Basis vectors squaring to -1
19//! zero = [] # Basis vectors squaring to 0
20//!
21//! [blades]
22//! e12 = "xy" # Custom blade names
23//! e13 = "xz"
24//! e23 = "yz"
25//!
26//! [types.Vector]
27//! grades = [1] # Which grades this type contains
28//! field_map = [ # Field-to-blade mappings
29//! { name = "x", blade = "e1" },
30//! { name = "y", blade = "e2" },
31//! { name = "z", blade = "e3" }
32//! ]
33//!
34//! [types.Rotor]
35//! grades = [0, 2]
36//! field_map = [
37//! { name = "s", blade = "s" },
38//! { name = "xy", blade = "e12" },
39//! { name = "xz", blade = "e13" },
40//! { name = "yz", blade = "e23" }
41//! ]
42//! ```
43//!
44//! # Example
45//!
46//! ```
47//! use clifford_codegen::spec::parse_spec;
48//!
49//! let spec = parse_spec(r#"
50//! [algebra]
51//! name = "euclidean2"
52//! complete = false
53//!
54//! [signature]
55//! positive = ["e1", "e2"]
56//!
57//! [types.Vector]
58//! grades = [1]
59//! field_map = [
60//! { name = "x", blade = "e1" },
61//! { name = "y", blade = "e2" }
62//! ]
63//! "#).unwrap();
64//!
65//! assert_eq!(spec.name, "euclidean2");
66//! assert_eq!(spec.signature.dim(), 2);
67//! ```
68
69mod bundled;
70mod error;
71mod ir;
72mod parser;
73mod raw;
74
75pub use bundled::{EUCLIDEAN2, EUCLIDEAN3};
76pub use error::ParseError;
77pub use ir::{
78 AlgebraSpec, BasisVector, FieldSpec, InvolutionKind, NormSpec, ProductEntry, ProductsSpec,
79 SignatureSpec, TypeSpec, WrapperKind,
80};
81pub use parser::parse_spec;