Skip to main content

Crate lemma

Crate lemma 

Source
Expand description

§Lemma Engine

Rules for man and machine

Consumer API: load → specs → show / source → evaluate.

Re-exports§

pub use api::evaluate_data_value_from_json_value;
pub use api::parse_evaluate_data_object;
pub use api::resolve_evaluate_rules;
pub use api::show_document;
pub use api::evaluate_data_value_from_json_value as run_data_value_from_json_value;
pub use api::parse_evaluate_data_object as parse_run_data_object;
pub use api::resolve_evaluate_rules as resolve_run_rules;
pub use result_value::CalendarResult;
pub use result_value::RangeResult;
pub use result_value::RowReference;
pub use result_value::RowResult;
pub use result_value::RuleResultValue;
pub use result_value::RuleResultValueFailure;
pub use result_value::SpecResult;
pub use result_value::SpecRuleResult;
pub use quality::Recommendation;

Modules§

api
JSON API types for Engine boundary documents.
deps
Dependency layout under <workdir>/lemma_deps/, shared by CLI install and LSP.
documentation
Embedded language guides and example specs.
mcp
Pure Lemma MCP tools: Engine + arguments in, catalog or text out.
quality
Structural quality analysis over loaded specs.
result_value
API value for a rule result, ShowData.value, or ShowData.suggestion.

Structs§

ArithmeticTerm
One operand of a NormalFormKind::Sum or NormalFormKind::Product. inverse marks a subtracted (Sum) or divided (Product) operand. The first term of a Sum/Product is never inverse.
BoundValueKind
Canonical suggestion/fill value plus the written measure unit when one was declared.
Cause
Context
Ordered store of specs keyed by (repository, name) and grouped into LemmaSpecSets.
DataPath
Resolved path to a data (created during planning from AST DataReference)
DateTimeValue
Engine
Engine for evaluating Lemma rules.
EngineError
Flat wire view of Error matching EngineError in engine/schemas/api.v1.json and engine/packages/npm/lemma.d.ts. Missing optionals serialize as JSON null.
EngineErrorSource
Source location attached to an EngineError. Line and column are 1-based; length is the UTF-8 byte length of the offending span.
ErrorDetails
Detailed error information with optional source location.
Errors
Load failure: errors plus the source texts we attempted to load.
EvaluateData
User-provided data values resolved against a plan’s type declarations.
ExecutableRule
A named rule’s root in the normal-form table, plus declaration metadata.
ExecutionPlan
A complete execution plan ready for the evaluator
ExplainedRule
One narrated rule body stored in an explanation’s rules table.
ExplainedRuleId
Compact id of a rule in an crate::evaluation::explanations::Explanation’s rules table. Assigned in first-reach order from the root.
Explanation
Fetch
Header
HttpResponse
IndexMap
A hash table where the iteration order of the key-value pairs is independent of the hash values of the keys.
Install
KeyField
One field in a list’s row key: display name and resolved template data path.
LemmaBase
LemmaBase registry: bound to https://lemmabase.com. Not configurable.
LemmaData
LemmaRepository
A Lemma repository header. Identity carrier; never owns specs.
LemmaSpec
A Lemma spec containing data and rules.
LemmaSpecSet
All spec versions sharing a (repository, name) identity, keyed by effective_from.
LemmaType
Resolved type after planning
Lexer
LiteralValue
Runtime literal payload. Type lives on NormalForm.result_type / DataDefinition / explicit computation parameters — not on the value.
MeasureUnit
A single unit within a Measure type.
MeasureUnits
NormalForm
One node in THE DAG: algebraic Kind, stamped result type, optional conversion span, optional fold origin, optional rule use-site identity.
NormalFormId
Index into a [NormalFormInterner] / shipped crate::planning::execution_plan::ExecutionPlan::normal_forms.
ParseResult
PathSegment
A single segment in a resolved path traversal
RatioUnit
RatioUnits
RationalInteger
Registries
The registries the host composes. Default is LemmaBase alone.
RegistryBundle
RegistryError
Repository
Repository group from Engine::specs.
RepositoryInstallResult
Result of Install: LemmaBase repository source text and normalized id.
RepositoryQualifier
Textual repository qualifier as written in source (for example @iso/countries). name stores the qualifier verbatim, including a leading @ when present. The planner resolves a RepositoryQualifier to an Arc<LemmaRepository> against the active context.
Resolve
ResolvedSpecTypes
Fully resolved types for a single spec. After resolution, all imports are inlined — specs are independent.
ResourceLimits
Limits to prevent abuse and enable predictable resource usage
Response
Response from evaluating a Lemma spec
RowInstance
A row instance: its spec, where it came from, and its bound fields.
RowRead
A member chain read on a row, through the row spec’s template plans: every end but the last reads a uses slot, as that instance; the last is the member read.
RulePath
Resolved path to a rule (created during planning from a rule reference).
RuleResult
Result of evaluating a single rule. Struct fields match the API JSON shape.
SerializedConversionTraceStep
Show
Consumer [Engine::show] result: local offered types, inputs rules need, this spec’s own rules (empty path), and resolved temporal window. Source: [Engine::source]. Branch Rule leaves may name reachable imports that are not keys of Self::rules; follow those via show on the imported spec.
ShowBranch
One arm of a rule’s flat last-match table on Show.
ShowData
One data entry in a Show.
ShowRule
Local rule on Show: result type, authored branches, stored topo deps.
SignatureFactor
One resolved unit in a signature: declared name, owning family, exponent.
Source
Positional source location: source id and span.
Span
Span representing a location in source code
SpecDependency
One uses target from a spec version’s source.
SpecIdentity
Resolved spec a value or rule result refers to: one temporal slice of one version.
SpecInstance
The hops that name a spec instance, relative to the plan holding it: uses hops (rack.low), or a list hop with its row number (staff.2).
SpecRef
A spec reference written in source.
SpecVersion
One temporal spec version from Engine::specs.
TimezoneValue
UTC offset in signed whole minutes; |offset_minutes| is at most 23:59.
TransportFailure
TypeFamily
Root of a custom type’s extension chain: the spec version that declares the root type, and its name. Types share a unit family only when they share this root declaration; a local money and an imported pricing.money are different families. Two versions of pricing declare different pricing <date>.money families; values from different versions do not mix. Interface drift across unpinned versions compares structure with LemmaType::same_interface, which ignores the family’s effective date.
TypedLiteral
Planning-time literal: value plus resolved type.
UnitIndex
Expression-scope units after bind: every declarer per bare unit name.
VetoExpression
A veto expression that prohibits any valid verdict from the rule

Enums§

ArithmeticComputation
Arithmetic computations
BranchOutcome
Outcome of inspecting a branch condition or a boolean operand.
CalendarPeriodUnit
Granularity of a calendar-period check.
CommandArg
A parsed constraint command argument, preserving the literal kind from the grammar rule command_arg: { number_literal | boolean_literal | text_literal | label }.
ComparisonComputation
Comparison computations
ConversionTraceRole
ConversionTypeKind
Primitive kind that can appear as an as conversion target. Excludes Text (display formatting is not a conversion) and the range kinds (a range is not a cast target — use a range literal or ... operator instead). The parser rejects as text at the as target position; data x: text declarations still use [PrimitiveKind::Text] via [crate::parsing::lexer::token_kind_to_primitive].
DataDefinition
Resolved data value for the execution plan: aligned with [DataValue] but with source per variant.
DataOrigin
Who wrote a data slot’s definition.
DataValue
Parse-time data value (before type resolution)
DateCalendarKind
Calendar-period membership checks.
DateGranularity
DateRelativeKind
Whether a date is relative to now in the past or future direction.
DispatchKey
One breakpoint in an ordered dispatch table.
DispatchRegion
One region body of a NormalFormKind::OrderedDispatch table.
EffectiveDate
Error
Error types for the Lemma system with source location tracking
ErrorKind
Classification of an Error. Serialized as the kind field on the flat object returned to JavaScript from WASM (engine/src/wasm.rs, JsError).
EvaluateDataValue
Neutral overlay tree. EvaluateData::resolve reads each value by declared type.
ExplainedListOp
List command identity on a narrated ExplanationNode::ListCommand.
ExplanationNode
InstallStep
LeafKind
Leaves in the shipped equation DAG: literals and data only.
ListKey
How a list addresses its rows.
ListPredKind
ListPredicateForm
LogicalConnective
MathematicalComputation
Mathematical computations
NormalFormKind
Algebraic structure only. Children are NormalFormId. Hash/Eq drive cons — no source spans or rule-ref identity here (those live on NormalForm).
NormalFormListOp
NumberArithmeticFailure
NumericFailure
OperationResult
Result of evaluating a rule, expression, or data leaf.
ParentType
Parent type in a type definition: built-in primitive or custom type name.
PiecewiseDecision
Where the Piecewise arm scan stopped. Arm 0 is the default; unless arms 1..arm_count are scanned from the highest index down, like the evaluator.
RangeBound
Which endpoint of a range lower / upper reads.
ReferenceTarget
What a DataDefinition::Reference copies its value from: either another data path or a rule whose result becomes this data’s value.
RegistryErrorKind
The kind of failure that occurred during a Registry operation.
RequestErrorKind
Distinguishes HTTP 404 (not found) from 400 (bad request) for request errors.
ResolveStep
RoundingMode
Direction of a -> round|floor|ceil <step> command.
RowBinding
A field of a RowInstance.
RowEnd
Field of a row read through the row spec’s template plan.
RowOrigin
Where a row instance came from. Names missing fields and explanations.
ShowConversionTarget
Conversion target on a Show as expression (no owning type — inspection only).
ShowExpression
Resolved expression tree for Show branches (tag = "type" on the API mirror).
SourceType
TokenKind
TypeConstraintCommand
Constraint command for type definitions. Derived from lexer tokens; no string matching.
TypeSpecification
UnitScale
Conversion factor of a measure unit: a plan-time rational, or a data/rule reference whose value is known only during evaluation.
ValueKind
Value payload (shape of a literal).
VetoType
Why an operation yielded no value (domain veto).

Constants§

API_V1_SCHEMA_JSON
Checked-in JSON Schema for Show, Response, and related wire types (engine/schemas/api.v1.json). Regenerated by cargo run -p xtask -- schema.
COMPLETION_KEYWORD_LABELS
Spellings shared by [keyword_from_identifier] and LSP completion.
EMBEDDED_STDLIB_REPOSITORY
Repository name reserved for the embedded standard library (repo lemma, spec units). User Engine::load must not target this name via SourceType::Dependency.
MAX_DATA_NAME_LENGTH
MAX_RULE_NAME_LENGTH
MAX_SPEC_NAME_LENGTH
UNITS_LEMMA

Traits§

HttpTransport
Synchronous driver for Rust hosts. wasm drives the steps itself with async fetch.
Registry
A registry is a request builder and response interpreter. It never performs I/O.

Functions§

arithmetic_operation
Perform type-aware arithmetic operation, returning OperationResult (Veto for runtime errors).
attribute_evaluate_data_error
Attribute a walker error to its top-level data key unless already attributed.
attribute_run_data_error
Attribute a walker error to its top-level data key unless already attributed.
can_be_label
Returns true if the token kind can be used as a label or reference segment (identifier, or one of the keywords past / future / permille / is in label position).
checked_div
checked_mul
comparison_operation
Perform type-aware comparison, returning OperationResult (Veto on error).
condition_outcome
How a piecewise unless-arm condition or a logical operand decides.
convert_unit_operand
Apply a type cast when the operand is already held as BoundValueKind.
decimal_to_rational
evaluate_data_from_entries
Top-level run-data entries from a host walker. Keys differing only in case: request Error.
evaluate_data_map_from_entries
Nested object entries from a host walker. Keys differing only in case: request Error.
evaluate_data_null_list_item
Host list item that is null (JSON null, JS null / undefined, Java null, Elixir nil). A list has no unsupplied row, so this is a request Error, never an omitted item. position is 1-based within its list.
format_explanation
format_parse_result
Format a ParseResult (repository groups + specs) into canonical Lemma source.
format_repositories
Text view of Engine::specs, as lemma specs prints it.
format_source
Parse a source string and format it to canonical Lemma source.
format_specs
Format a sequence of parsed specs into canonical Lemma source.
negated_comparison
Logical computation operators (defined in semantics, not used by the parser). Returns the logical negation of a comparison (used by De Morgan / NOT-normal-form rewriting).
number_arithmetic
numbered_row_origin
1-based numbered origin of a list row (items.2).
parse
parse_data_value
parse_spec_set_id
Validate and normalize a spec set identifier (a spec name in the default repository).
piecewise_decision
Scan unless-arm conditions high to low. outcome(arm) reports the condition’s decision, or None when there is none to read.
primitive_number_arc
rational_new
region_count
Number of regions for boundary_count breakpoints.
region_of_scrutinee
Region index for an evaluated, non-veto scrutinee value. The one decision procedure shared by value evaluation, explain’s winner check and missing_data liveness. A calendar or rational failure is the veto the dispatch evaluates to. A value kind the fold excludes is a planning bug.
resolve_effective
Resolve an optional effective datetime string for planning or evaluation.
row_field_input_key
Input key of a field of a numbered list row (items.2.weight).
run_data_from_entries
Top-level run-data entries from a host walker. Keys differing only in case: request Error.
run_data_map_from_entries
Nested object entries from a host walker. Keys differing only in case: request Error.
run_data_null_list_item
Host list item that is null (JSON null, JS null / undefined, Java null, Elixir nil). A list has no unsupplied row, so this is a request Error, never an omitted item. position is 1-based within its list.
try_parse_type_constraint_command
Parses a constraint command name. Returns None for unknown (parser returns error).
type_detail_lines
Produce a human-readable summary of type constraints, or None when there are no constraints worth showing (e.g. bare boolean). Returns one formatted string per constraint or property of the type specification. Uses display_str for all rational bounds so they render as decimals, not as raw fractions.

Type Aliases§

RunDataValueDeprecated
SignatureIndex
Reverse index mapping a resolved unit signature to the unit (by name) and its owning measure type.