Module equality

Source
Expand description

Equality expression parsing and evaluation for the AIMX language.

This module provides parsers and evaluation logic for equality expressions using the = and != operators. The AIMX grammar accepts both == and = for equality comparison, and both != and <> for inequality comparison.

Equality expressions form an important part of the expression hierarchy, handling comparisons between values of the same type. They have lower precedence than relational operators (<, <=, >, >=) but higher precedence than logical operators (&, |).

§Grammar

The equality operators have left associativity and follow this grammar rule:

equality := relational (S? ('=' | "!=" | '==') S? relational)?

Where S represents optional whitespace.

§Operator Support

OperatorMeaningAliases
=Equality==
!=Inequality

§Examples

5 = 5                    // true (number equality)
"hello" != "world"       // true (text inequality)
1 + 2 = 3                // true (arithmetic result comparison)
x > 0 = y < 10           // (x > 0) = (y < 10) - relational comparison equality
true = false             // false (boolean equality)

§Type Behavior

Equality operations require operands of compatible types. The evaluation system uses type promotion via evaluate_and_promote to ensure both operands have the same type before comparison:

  • Boolean: true = falsefalse
  • Number: 5 = 5.0true (numeric equality)
  • Text: "abc" = "abc"true (string equality)
  • Date: DateTime equality comparison
  • Task: Task status equality comparison

§AST Flattening Optimization

Like other expression modules, equality expressions use AST flattening where expressions that don’t contain equality operators are flattened to Primary expressions for improved evaluation performance.

§Error Handling

Equality evaluation provides detailed error messages when type promotion fails or incompatible types are compared:

"Expected Bool, Date, Number, Task or Text, found Type1 = Type2 ~formula"
  • relational - Higher precedence relational operations
  • logical - Lower precedence logical operations
  • expression - Top-level expression parsing
  • evaluate - Core evaluation traits and type promotion

Enums§

Equality
An equality expression node in the abstract syntax tree.

Functions§

parse_equality
Parse an equality expression from a string slice.