mirror of
https://github.com/gorules/zen.git
synced 2026-10-04 08:02:28 +00:00
* feat: declared dates as date values - graph format:date/date-time inputs and policy date properties arrive as dates that keep their original text for output, string() and string functions - d() keeps the instant of offset/Z strings, resolves DST gaps and accepts ISO forms without offset, compact, slash-separated, YYYY-MM and YYYY - dates compare with date strings in ==, !=, <, >, in and contains, and concatenate with strings; deprecated date helpers accept dates - string(date), type() reports date, and date-to-string at string inputs * fix: close review gaps in date inputs - parse new date formats by exact shape; keep master formats first and guard DST-gap and extreme-year overflows - text-carrying dates act as strings for object keys, in-object, index, slice, concatenation and bool - deprecated helpers fall back to the date instant; time() accepts dates - schema-less child inputs receive date text; dates satisfy string parameters and slicing in the type checker - convert policy input before validation so dates are parsed once; share rewrite helpers between graph and policy conversion * fix: align date text, unions, references and child inputs - every valid date exposes a text form (original or RFC3339), so string functions and slicing on computed dates match the type checker - date and string types merge to string; reference ids typed as dates resolve through their text - input nodes convert declared dates and hand every other converted date back as its original text, following combinators only for structure - date format checks no longer allocate
84 lines
2.8 KiB
Rust
84 lines
2.8 KiB
Rust
//! A lightweight expression language designed for the evaluation of expressions in various contexts.
|
|
//!
|
|
//! Zen Expression is a versatile single-threaded expression language designed for simplicity
|
|
//! high-performance. It's primarily used for evaluating and processing JSON data offers key components that empower developers in creating responsive and
|
|
//! non-blocking I/O applications
|
|
//! Out of the box, it comes with amazing benefits:
|
|
//! - 🚀 Blazingly fast - Perform millions of evaluations per second
|
|
//! - 🧠 Intuitive syntax - Minimalistic and expressive syntax
|
|
//! - 💼 Portable - Can be compiled for all standard architectures including WASM
|
|
//!
|
|
//! For a full list of language references, visit [documentation](https://gorules.io/docs/rules-engine/expression-language/).
|
|
//!
|
|
//! # Example
|
|
//! Evaluate expression using isolate:
|
|
//! ```
|
|
//! use zen_expression::evaluate_expression;
|
|
//! use zen_expression::variable::Variable;
|
|
//! use rust_decimal_macros::dec;
|
|
//! use serde_json::json;
|
|
//!
|
|
//! fn main() {
|
|
//! let context = json!({ "tax": { "percentage": 10 } });
|
|
//! let tax_amount = evaluate_expression("50 * tax.percentage / 100", context.into()).unwrap();
|
|
//!
|
|
//! assert_eq!(tax_amount, Variable::Number(dec!(5)));
|
|
//! }
|
|
//! ```
|
|
//!
|
|
//! ## High Performance
|
|
//! When evaluating a lot of expressions at once, you can use Isolate directly. Under the hood, Isolate
|
|
//! will re-use allocated memory from previous evaluations, drastically improving performance.
|
|
//!
|
|
//! ```
|
|
//! use zen_expression::Isolate;
|
|
//! use zen_expression::variable::Variable;
|
|
//! use rust_decimal_macros::dec;
|
|
//! use serde_json::json;
|
|
//!
|
|
//! fn main() {
|
|
//! let context = json!({ "tax": { "percentage": 10 } });
|
|
//! let mut isolate = Isolate::with_environment(context.into());
|
|
//!
|
|
//! // Fast 🚀
|
|
//! for _ in 0..1_000 {
|
|
//! let tax_amount = isolate.run_standard("50 * tax.percentage / 100").unwrap();
|
|
//! assert_eq!(tax_amount, Variable::Number(dec!(5)));
|
|
//! }
|
|
//! }
|
|
//! ```
|
|
//!
|
|
//! # Feature flags
|
|
//!
|
|
//! Name | Description | Default?
|
|
//! ---|---|---
|
|
//! `regex-deprecated` | Uses standard `regex` crate | Yes
|
|
//! `regex-lite` | Opts for usage of lightweight `regex-lite` crate. Useful for reducing build size, especially in WASM. | No
|
|
|
|
#![forbid(unsafe_code)]
|
|
|
|
mod isolate;
|
|
|
|
pub mod compiler;
|
|
mod dates;
|
|
mod exports;
|
|
pub mod expression;
|
|
pub mod functions;
|
|
pub mod intellisense;
|
|
pub mod lexer;
|
|
pub mod parser;
|
|
pub mod scope;
|
|
pub mod slot;
|
|
pub mod validate;
|
|
pub mod variable;
|
|
pub mod vm;
|
|
|
|
pub use dates::DateValue;
|
|
pub use exports::{
|
|
compile_expression, compile_unary_expression, evaluate_expression, evaluate_unary_expression,
|
|
};
|
|
pub use expression::{Expression, ExpressionKind, OpcodeCache};
|
|
pub use isolate::{Isolate, IsolateError};
|
|
pub use scope::Scope;
|
|
pub use variable::Variable;
|