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//!
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, lemma::EvaluationRequest::default()).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;
63pub(crate) mod stdlib;
64
65#[cfg(target_arch = "wasm32")]
66pub mod wasm;
67
68pub use computation::rational::{
69    checked_mul, commit_rational_to_decimal, decimal_to_rational, rational_to_display_str,
70    NumericFailure, NumericOperation, RationalInteger,
71};
72pub use deps::{
73    dependency_cache_file, dependency_identifier_from_dependency_path, lemma_deps_dir,
74    relative_dependency_cache_path,
75};
76#[cfg(not(target_arch = "wasm32"))]
77pub use engine::collect_lemma_sources;
78pub use engine::{Context, Engine, Errors, ResolvedRepository};
79pub use error::{Error, ErrorKind, RequestErrorKind};
80pub use evaluation::explanation;
81pub use evaluation::operations::{OperationResult, VetoType};
82pub use evaluation::request::{parse_rule_result_conversion_strings, EvaluationRequest};
83pub use evaluation::response::{DataGroup, Response, RuleResult};
84pub use formatting::format_source;
85pub use inversion::{Bound, Domain, Target};
86pub use limits::ResourceLimits;
87pub use parsing::ast::{DateTimeValue, EffectiveDate, LemmaRepository, LemmaSpec};
88pub use parsing::parse;
89pub use parsing::source::SourceType;
90pub use parsing::ParseResult;
91pub use planning::semantics::{DataPath, LemmaType, LiteralValue, TypeSpecification, ValueKind};
92pub use planning::{ExecutionPlan, LemmaSpecSet, SpecSchema};