pub enum Postfix {
Empty,
Function(String, Box<Expression>),
Index(Box<Postfix>, Box<Expression>),
Method(Box<Postfix>, String, Box<Expression>),
Inference(Reference, Box<Expression>),
Primary(Box<Primary>),
}Expand description
Represents a postfix expression in the AIMX grammar.
Postfix expressions are operations that occur after their operands, following the left-to-right associativity rule. This enum captures all possible postfix operations including function calls, method calls, array indexing, and inference operations, as well as flattened primary expressions for optimization.
§Variants
Empty- The empty placeholder_representing no operationFunction- Function call with identifier and argumentsIndex- Array indexing operation with base and indexMethod- Method call on an object with method name and argumentsInference- Inference call on a reference with argumentsPrimary- Flattened primary expression (optimization)
§Examples
use aimx::expressions::postfix::Postfix;
use aimx::expressions::primary::Primary;
use aimx::Literal;
// Empty placeholder
let empty = Postfix::Empty;
assert!(empty.is_empty());
// Function call
let args = aimx::Expression::Empty;
let function = Postfix::Function("sum".to_string(), Box::new(args));
// Array indexing
let base = Box::new(Postfix::Primary(Box::new(Primary::Literal(Literal::Number(42.0)))));
let index = Box::new(aimx::Expression::Empty);
let index_op = Postfix::Index(base, index);
// Method call
let obj = Box::new(Postfix::Primary(Box::new(Primary::Literal(Literal::Text("data".to_string())))));
let method = Postfix::Method(obj, "to_upper".to_string(), Box::new(aimx::Expression::Empty));§AST Flattening
The Primary variant represents an optimization where expressions that consist
solely of primary expressions (literals, references, parentheses) are flattened
to reduce AST depth and improve evaluation performance.
§See Also
parse_postfix- Function to parse postfix expressions from textExpressionLike- Trait for expression evaluationPrimary- Type of flattened primary expressions
Variants§
Empty
The empty placeholder _
Function(String, Box<Expression>)
Function call with function name and argument expression
Index(Box<Postfix>, Box<Expression>)
Array indexing operation with base and index expressions
Method(Box<Postfix>, String, Box<Expression>)
Method call on an object with method name and arguments
Inference(Reference, Box<Expression>)
Inference call on a reference and arguments
Primary(Box<Primary>)
Primary flattened AST optimization
Implementations§
Source§impl Postfix
impl Postfix
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if this postfix expression represents an empty placeholder.
§Returns
bool- True if this is an Empty postfix expression, false otherwise
§Examples
use aimx::expressions::{
postfix::Postfix,
primary::Primary,
};
use aimx::Literal;
let empty = Postfix::Empty;
assert!(empty.is_empty());
let literal = Postfix::Primary(Box::new(Primary::Literal(Literal::Number(42.0))));
assert!(!literal.is_empty());Trait Implementations§
Source§impl ExpressionLike for Postfix
impl ExpressionLike for Postfix
Source§fn evaluate(&self, context: &mut dyn ContextLike) -> Result<Value>
fn evaluate(&self, context: &mut dyn ContextLike) -> Result<Value>
Evaluate this postfix expression within the given context.
This method recursively evaluates the postfix expression tree, delegating to the appropriate evaluation methods for each postfix variant. It handles function calls, method calls, array indexing, and inference operations.
§Arguments
context- The evaluation context providing variable values, function implementations, and method implementations
§Returns
Returns a Result containing the evaluated Value if successful,
or an error if evaluation fails.
§Evaluation Strategy
Emptyexpressions returnValue::EmptyFunctionexpressions delegate toContextLike::function_callIndexexpressions perform array indexing with bounds checkingMethodexpressions delegate toContextLike::method_callInferenceexpressions delegate toContextLike::inference_callPrimaryexpressions delegate toPrimary::evaluate
§Examples
use aimx::expressions::postfix::Postfix;
use aimx::expressions::primary::Primary;
use aimx::{Context, Literal, ExpressionLike};
// Evaluate empty placeholder
let mut context = Context::new();
let postfix = Postfix::Empty;
let result = postfix.evaluate(&mut context).unwrap();
assert_eq!(result, aimx::Value::Empty);
// Evaluate literal expression
let primary = Primary::Literal(Literal::Number(42.0));
let postfix = Postfix::Primary(Box::new(primary));
let result = postfix.evaluate(&mut context).unwrap();
assert_eq!(result.to_string(), "42");§Error Handling
This method returns detailed error messages including:
- Array index out of bounds errors
- Type mismatch errors for array indexing
- Function and method call failures
- Inference call failures
§See Also
ContextLike- Trait for evaluation contextsValue- Result type returned by evaluationPrimary::evaluate- Evaluation of primary expressions
Source§fn to_sanitized(&self) -> String
fn to_sanitized(&self) -> String
Source§fn to_formula(&self) -> String
fn to_formula(&self) -> String
impl StructuralPartialEq for Postfix
Auto Trait Implementations§
impl Freeze for Postfix
impl RefUnwindSafe for Postfix
impl Send for Postfix
impl Sync for Postfix
impl Unpin for Postfix
impl UnwindSafe for Postfix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.