Expand description
Unary expression parsing and evaluation for the AIM expression grammar.
This module provides parsers and evaluation logic for unary expressions in the AIM expression language. Unary operations include logical NOT, unary plus and minus, and type casting operations. These operators have right-to-left associativity and form an important part of the expression hierarchy.
§Overview
Unary expressions operate on a single operand and include:
- Logical operations:
!(NOT) - Arithmetic operations:
+(unary plus),-(unary minus) - Type casting:
(Type)syntax for explicit type conversion
§Operator Precedence
Unary operators have the fourth-highest precedence in the AIMX grammar, coming after parentheses and postfix operations but before multiplicative operations. They are right-to-left associative, meaning operators group from right to left when chained.
§Unary Operators
| Operator | Description | Example | Result Type |
|---|---|---|---|
! | Logical NOT | !true | Bool |
+ | Unary plus | +5 | Number |
- | Unary minus | -3.14 | Number |
(Bool) | Cast to boolean | (Bool)0 | Bool |
(Date) | Cast to date | (Date)"2023-01-01" | Date |
(Number) | Cast to number | (Number)"123" | Number |
(Task) | Cast to task | (Task)"complete" | Task |
(Text) | Cast to text | (Text)42 | Text |
§Examples
!true // logical NOT → false
+5 // unary plus → 5
-3.14 // unary minus → -3.14
(Number)"123" // cast string to number → 123
!(Bool)0 // cast 0 to bool then negate → true
+-+-5 // multiple unary operators → -5§Type Casting Behavior
Type casting operations convert values between AIMX types:
(Bool): Converts any value to boolean using truthiness rules(Date): Parses strings as ISO 8601 dates(Number): Converts strings and booleans to numbers(Task): Creates task primitives from values(Text): Converts any value to string representation
§Related Modules
postfix- Higher precedence operationsmultiplicative- Lower precedence operationsliteral- Literal value parsingvalue- Runtime value representation
Enums§
- Unary
- Represents a unary expression in the AIM grammar.
Functions§
- parse_
unary - Parse a unary expression.