lemma/lib.rs
1//! # Lemma Engine
2//!
3//! **Rules for man and machine**
4//!
5//! Lemma is a declarative programming language for expressing rules, data, 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, SourceType};
12//!
13//! let mut engine = Engine::new();
14//!
15//! // Load Lemma code
16//! engine.load(r#"
17//! spec example
18//! data price: 100
19//! data quantity: 5
20//! rule total: price * quantity
21//! "#, SourceType::Path(std::sync::Arc::new(std::path::PathBuf::from("example.lemma")))).expect("failed to load");
22//!
23//! // Evaluate the spec (all rules, no data values)
24//! let now = lemma::DateTimeValue::now();
25//! let response = engine.run(None, "example", Some(&now), std::collections::HashMap::new(), false).unwrap();
26//! ```
27//!
28//! ## Core Concepts
29//!
30//! ### Specs
31//! A spec is a collection of data and rules. Specs can reference
32//! other Specs to build composable logic.
33//!
34//! ### Data
35//! Data are named values: numbers, text, dates, booleans, or typed units
36//! like `50 kilograms` or `100`.
37//!
38//! ### Rules
39//! Rules compute values based on data and other rules. They support
40//! conditional logic through "unless" clauses.
41//!
42//! ### Types
43//! Lemma has a rich type system including units (mass, length, time, money)
44//! with automatic conversions.
45
46#[cfg(test)]
47mod tests;
48
49pub(crate) mod computation;
50pub mod deps;
51pub mod engine;
52pub mod error;
53pub mod evaluation;
54pub mod formatting;
55pub mod inversion;
56pub mod limits;
57pub(crate) mod literals;
58pub mod parsing;
59pub mod planning;
60pub mod registry;
61pub mod serialization;
62pub mod spec_set_id;
63
64#[cfg(target_arch = "wasm32")]
65pub mod wasm;
66
67pub use deps::{
68 dependency_cache_file, dependency_identifier_from_dependency_path, lemma_deps_dir,
69 relative_dependency_cache_path,
70};
71#[cfg(not(target_arch = "wasm32"))]
72pub use engine::collect_lemma_sources;
73pub use engine::{Context, Engine, Errors, ResolvedRepository};
74pub use error::{Error, ErrorKind, RequestErrorKind};
75pub use evaluation::explanation;
76pub use evaluation::operations::{OperationResult, VetoType};
77pub use evaluation::response::{DataGroup, Response, RuleResult};
78pub use formatting::format_source;
79pub use inversion::{Bound, Domain, Target};
80pub use limits::ResourceLimits;
81pub use parsing::ast::{DateTimeValue, EffectiveDate, LemmaRepository, LemmaSpec};
82pub use parsing::parse;
83pub use parsing::source::SourceType;
84pub use parsing::ParseResult;
85pub use planning::semantics::{DataPath, LemmaType, LiteralValue, TypeSpecification, ValueKind};
86pub use planning::{ExecutionPlan, LemmaSpecSet, SpecSchema};