Skip to main content

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//! use std::collections::HashMap;
13//!
14//! let mut engine = Engine::new();
15//!
16//! // Load Lemma code
17//! engine.load(r#"
18//!     spec example
19//!     data price: 100
20//!     data quantity: 5
21//!     rule total: price * quantity
22//! "#, SourceType::Labeled("example.lemma")).expect("failed to load");
23//!
24//! // Evaluate the spec (all rules, no data values)
25//! let now = lemma::DateTimeValue::now();
26//! let response = engine.run("example", Some(&now), HashMap::new(), false).unwrap();
27//! ```
28//!
29//! ## Core Concepts
30//!
31//! ### Specs
32//! A spec is a collection of data and rules. Specs can reference
33//! other specs to build composable logic.
34//!
35//! ### Data
36//! Data are named values: numbers, text, dates, booleans, or typed units
37//! like `50 kilograms` or `100`.
38//!
39//! ### Rules
40//! Rules compute values based on data and other rules. They support
41//! conditional logic through "unless" clauses.
42//!
43//! ### Types
44//! Lemma has a rich type system including units (mass, length, time, money)
45//! with automatic conversions.
46
47#[cfg(test)]
48mod tests;
49
50pub(crate) mod computation;
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 engine::{Context, Engine, Errors, SourceType};
68pub use error::{Error, ErrorKind, RequestErrorKind};
69pub use evaluation::explanation;
70pub use evaluation::operations::{
71    ComputationKind, OperationKind, OperationRecord, OperationResult, VetoType,
72};
73pub use evaluation::response::{DataGroup, Response, RuleResult};
74pub use formatting::{format_source, format_specs};
75pub use inversion::{Bound, Domain, InversionResponse, Solution, Target, TargetOp};
76pub use limits::ResourceLimits;
77pub use parsing::ast::{
78    DateTimeValue, DepthTracker, LemmaData, LemmaRule, LemmaSpec, MetaField, MetaValue, Span,
79};
80pub use parsing::parse;
81pub use parsing::ParseResult;
82pub use parsing::Source;
83pub use planning::semantics::{
84    is_same_spec, DataPath, LemmaType, LiteralValue, RatioUnit, RatioUnits, RulePath, ScaleUnit,
85    ScaleUnits, SemanticDurationUnit, TypeDefiningSpec, TypeSpecification, ValueKind,
86};
87pub use planning::{
88    ExecutionPlan, ExecutionPlanSet, LemmaSpecSet, PlanningResult, SpecPlanningResult, SpecSchema,
89    SpecSetPlanningResult,
90};
91#[cfg(feature = "registry")]
92pub use registry::LemmaBase;
93pub use registry::{
94    resolve_registry_references, Registry, RegistryBundle, RegistryError, RegistryErrorKind,
95};
96pub use spec_set_id::parse_spec_set_id;