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;
12//! use std::collections::HashMap;
13//!
14//! let mut engine = Engine::new();
15//!
16//! // Load Lemma code
17//! let mut files = HashMap::new();
18//! files.insert("example.lemma".to_string(), r#"
19//! doc example
20//! fact price = 100
21//! fact quantity = 5
22//! rule total = price * quantity
23//! "#.to_string());
24//!
25//! tokio::runtime::Runtime::new().unwrap()
26//! .block_on(engine.add_lemma_files(files))
27//! .expect("failed to add files");
28//!
29//! // Evaluate the document (all rules, no fact values)
30//! let response = engine.evaluate("example", vec![], HashMap::new()).unwrap();
31//! ```
32//!
33//! ## Core Concepts
34//!
35//! ### Documents
36//! A document is a collection of facts and rules. Documents can reference
37//! other documents to build composable logic.
38//!
39//! ### Facts
40//! Facts are named values: numbers, text, dates, booleans, or typed units
41//! like `50 kilograms` or `100`.
42//!
43//! ### Rules
44//! Rules compute values based on facts and other rules. They support
45//! conditional logic through "unless" clauses.
46//!
47//! ### Types
48//! Lemma has a rich type system including units (mass, length, time, money)
49//! with automatic conversions.
50
51#[cfg(test)]
52mod tests;
53
54pub mod computation;
55pub mod engine;
56pub mod error;
57pub mod evaluation;
58pub mod formatting;
59pub mod inversion;
60pub mod limits;
61pub mod parsing;
62pub mod planning;
63pub mod registry;
64pub mod serialization;
65
66#[cfg(target_arch = "wasm32")]
67pub mod wasm;
68
69pub use engine::Engine;
70pub use error::LemmaError;
71pub use evaluation::operations::{
72 ComputationKind, OperationKind, OperationRecord, OperationResult,
73};
74pub use evaluation::proof;
75pub use evaluation::response::{Facts, Response, RuleResult};
76pub use formatting::{format_docs, format_source};
77pub use inversion::{
78 invert, Bound, DerivedExpression, Domain, InversionResponse, Solution, Target, TargetOp,
79};
80pub use limits::ResourceLimits;
81pub use parsing::ast::*;
82pub use parsing::ast::{DepthTracker, Span};
83pub use parsing::parse;
84pub use parsing::Source;
85pub use planning::semantics::{
86 FactPath, LemmaType, LiteralValue, RatioUnit, RatioUnits, RulePath, ScaleUnit, ScaleUnits,
87 SemanticDurationUnit, TypeSpecification, ValueKind,
88};
89pub use planning::{DocumentSchema, ExecutionPlan};
90#[cfg(feature = "registry")]
91pub use registry::LemmaBase;
92pub use registry::{
93 resolve_registry_references, Registry, RegistryBundle, RegistryError, RegistryErrorKind,
94};
95
96/// Result type for Lemma operations
97pub type LemmaResult<T> = Result<T, LemmaError>;