Expand description
RulesXP - Multi-language rules expression evaluator
This crate provides a minimalistic expression evaluator that supports both Scheme syntax and JSONLogic operations with strict typing. It implements a proper subset of both languages designed for reliable rule evaluation with predictable behavior.
§Dual Language Support
The evaluator accepts expressions in Scheme or JSONLogic syntax:
;; Scheme syntax
(+ 1 2 3) ; arithmetic
(if #t "yes" "no") ; conditionals
(and #t #f) ; boolean logic
(car '(1 2 3)) ; list operationsThe same operations can be represented in JSONLogic:
{"+": [1, 2, 3]}
{"if": [true, "yes", "no"]}
{"and": [true, false]}
{"car": [[1, 2, 3]]}§Strict Typing
This interpreter implements stricter semantics than standard Scheme or JSONLogic:
- No type coercion (numbers don’t become strings, etc.)
- Boolean operations require actual boolean values (no “truthiness”)
- Arithmetic overflow detection and error reporting
- Strict arity checking for all functions
Any program accepted by this interpreter will give identical results in standard Scheme R7RS-small or JSONLogic interpreters, but the converse is not true due to our additional type safety requirements.
§Modules
scheme: S-expression parsing from textevaluator: Core expression evaluation enginebuiltinops: Built-in operations with dual-language mappingjsonlogic: JSONLogic format conversion and integration
Modules§
- ast
- builtinops
- Built-in operations registry with dual Scheme/JSONLogic support.
- evaluator
- jsonlogic
- scheme
Enums§
- Error
- Error types for the interpreter
Constants§
- MAX_
EVAL_ DEPTH - Maximum evaluation depth to prevent stack overflow in recursive evaluation This limits deeply nested function calls and expressions during evaluation Set higher than parse depth to allow for nested function applications
- MAX_
PARSE_ DEPTH - Maximum parsing depth to prevent stack overflow attacks This limits deeply nested structures in both S-expression and JSONLogic parsers