Skip to main content

Crate lemma

Crate lemma 

Source
Expand description

§Lemma Engine

Rules for man and machine

Lemma is a declarative programming language for expressing rules, data, and business logic in a way that is both human-readable and machine-executable.

§Quick Start

use lemma::{Engine, SourceType};

let mut engine = Engine::new();

// Load Lemma code
engine.load(r#"
    spec example
    data price: 100
    data quantity: 5
    rule total: price * quantity
"#, SourceType::Path(std::sync::Arc::new(std::path::PathBuf::from("example.lemma")))).expect("failed to load");

// Evaluate the spec (all rules, no data values)
let now = lemma::DateTimeValue::now();
let response = engine.run(None, "example", Some(&now), std::collections::HashMap::new(), false).unwrap();

§Core Concepts

§Specs

A spec is a collection of data and rules. Specs can reference other Specs to build composable logic.

§Data

Data are named values: numbers, text, dates, booleans, or typed units like 50 kilograms or 100.

§Rules

Rules compute values based on data and other rules. They support conditional logic through “unless” clauses.

§Types

Lemma has a rich type system including units (mass, length, time, money) with automatic conversions.

Re-exports§

pub use deps::dependency_cache_file;
pub use deps::dependency_identifier_from_dependency_path;
pub use deps::lemma_deps_dir;
pub use deps::relative_dependency_cache_path;
pub use engine::collect_lemma_sources;
pub use engine::Context;
pub use engine::Engine;
pub use engine::Errors;
pub use engine::ResolvedRepository;
pub use error::Error;
pub use error::ErrorKind;
pub use error::RequestErrorKind;
pub use evaluation::explanation;
pub use evaluation::operations::OperationResult;
pub use evaluation::operations::VetoType;
pub use evaluation::response::DataGroup;
pub use evaluation::response::Response;
pub use evaluation::response::RuleResult;
pub use formatting::format_source;
pub use inversion::Bound;
pub use inversion::Domain;
pub use inversion::Target;
pub use limits::ResourceLimits;
pub use parsing::ast::DateTimeValue;
pub use parsing::ast::EffectiveDate;
pub use parsing::ast::LemmaRepository;
pub use parsing::ast::LemmaSpec;
pub use parsing::parse;
pub use parsing::source::SourceType;
pub use parsing::ParseResult;
pub use planning::semantics::DataPath;
pub use planning::semantics::LemmaType;
pub use planning::semantics::LiteralValue;
pub use planning::semantics::TypeSpecification;
pub use planning::semantics::ValueKind;
pub use planning::ExecutionPlan;
pub use planning::LemmaSpecSet;
pub use planning::SpecSchema;

Modules§

deps
Dependency cache layout under <workdir>/.deps/, shared by CLI fetch and LSP.
engine
error
evaluation
Pure Rust evaluation engine for Lemma
formatting
Lemma source code formatting.
inversion
World-based inverse reasoning for Lemma rules
limits
parsing
planning
Planning module for Lemma specs
registry
Registry trait, types, and resolution logic for external repository references.
serialization
Serialization: Lemma values ↔ JSON.
spec_set_id
Parse spec set identifiers: a single spec set name.