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