Expand description
Relational expression parsing and evaluation for the AIMX expression grammar.
This module provides parsers and evaluation logic for relational expressions in the AIMX (Agentic Inference Markup Expressions) language. Relational operations include comparison operators such as less than, greater than, less than or equal, and greater than or equal. These operators have left-to-right associativity and form an important part of the expression hierarchy, handling comparisons between values of compatible types.
§Relational Operators (Left-to-Right Associativity)
| Operator | Description | Associativity |
|---|---|---|
< | Less than | Left to right |
> | Greater than | Left to right |
<= | Less than or equal | Left to right |
>= | Greater than or equal | Left to right |
§Supported Type Comparisons
Relational operators support comparisons between comparable types:
- Numbers: Standard numeric comparisons
- Booleans:
false<true(false = 0, true = 1) - Dates: Chronological order comparisons
- Text: Lexicographical order
- Tasks: Status-based comparison (pending < completed < failed)
§Operator Precedence
Relational operators have higher precedence than equality operators (=, !=)
but lower precedence than additive operators (+, -).
§Examples
use aimx::expressions::relational::{parse_relational, Relational};
use aimx::{ExpressionLike, Context, Value, Literal};
// Basic numeric comparisons
let (_, expr) = parse_relational("5 < 10").unwrap();
let mut context = Context::new();
let result = expr.evaluate(&mut context).unwrap();
assert_eq!(result.to_string(), "true");
// Floating point comparisons
let (_, expr) = parse_relational("3.14 > 2.71").unwrap();
let result = expr.evaluate(&mut context).unwrap();
assert_eq!(result.to_string(), "true");
// Variable comparisons
let mut context = Context::new()
.with_value("threshold", Value::Literal(Literal::Number(50.0)))
.with_value("value", Value::Literal(Literal::Number(42.0)));
let (_, expr) = parse_relational("value <= threshold").unwrap();
let result = expr.evaluate(&mut context).unwrap();
assert_eq!(result.to_string(), "true");
// String comparisons (lexicographical order)
let (_, expr) = parse_relational("\"apple\" < \"banana\"").unwrap();
let result = expr.evaluate(&mut context).unwrap();
assert_eq!(result.to_string(), "true");§Usage in Workflow Rules
Relational expressions are commonly used in workflow rules for conditional logic:
// Example workflow rules using relational expressions
IS_BUDGET_EXCEEDED: Bool = actual_cost > budget_limit
IS_DEADLINE_MISSED: Bool = current_date > deadline
IS_PRIORITY_HIGH: Bool = priority_level >= 8
DISCOUNT_ELIGIBLE: Bool = order_total >= 100.0Enums§
- Relational
- Represents a relational expression in the AIMX grammar.
Functions§
- parse_
relational - Parse a relational expression from a string.