lemma/
lib.rs

1//! # Lemma Engine
2//!
3//! **Rules for man and machine**
4//!
5//! Lemma is a declarative programming language for expressing rules, facts, and business logic
6//! in a way that is both human-readable and machine-executable.
7//!
8//! ## Quick Start
9//!
10//! ```rust,no_run
11//! use lemma::{Engine, LemmaResult};
12//!
13//! fn main() -> LemmaResult<()> {
14//!     let mut engine = Engine::new();
15//!
16//!     // Load Lemma code
17//!     engine.add_lemma_code(r#"
18//!         doc example
19//!         fact price = 100 USD
20//!         fact quantity = 5
21//!         rule total = price * quantity
22//!     "#, "example.lemma")?;
23//!
24//!     // Evaluate the document
25//!     let response = engine.evaluate("example", None, None)?;
26//!
27//!     Ok(())
28//! }
29//! ```
30//!
31//! ## Core Concepts
32//!
33//! ### Documents
34//! A document is a collection of facts and rules. Documents can reference
35//! other documents to build composable logic.
36//!
37//! ### Facts
38//! Facts are named values: numbers, text, dates, booleans, or typed units
39//! like `50 kilograms` or `100 USD`.
40//!
41//! ### Rules
42//! Rules compute values based on facts and other rules. They support
43//! conditional logic through "unless" clauses.
44//!
45//! ### Types
46//! Lemma has a rich type system including units (mass, length, time, money)
47//! with automatic conversions.
48
49pub mod analysis;
50pub mod ast;
51pub mod engine;
52pub mod error;
53pub mod evaluator;
54pub mod inversion;
55pub mod operation_result;
56pub mod parser;
57pub mod resource_limits;
58pub mod response;
59pub mod semantic;
60pub mod serializers;
61pub mod validator;
62
63#[cfg(target_arch = "wasm32")]
64pub mod wasm;
65
66pub use ast::{ExpressionId, ExpressionIdGenerator, Span};
67pub use engine::Engine;
68/// Temporary alias to align with the Inversion plan's unified naming.
69/// Workspace is functionally identical to Engine and will eventually replace it.
70pub type Workspace = Engine;
71pub use error::LemmaError;
72pub use inversion::{Bound, BranchOutcome, Domain, Shape, ShapeBranch, Target, TargetOp};
73pub use operation_result::OperationResult;
74pub use parser::{parse, parse_facts};
75pub use resource_limits::ResourceLimits;
76pub use response::{OperationRecord, Response, RuleResult};
77pub use semantic::*;
78pub use validator::{ValidatedDocuments, Validator};
79
80/// Result type for Lemma operations
81pub type LemmaResult<T> = Result<T, LemmaError>;
82
83#[cfg(test)]
84mod tests;