pub enum Procedure {
Array(Vec<Box<Conditional>>),
Primary(Box<Primary>),
}Expand description
Represents a procedure (sequence of expressions) in the AIMX language.
Procedures are sequences of conditional expressions that can be evaluated sequentially. They are typically used as the body of closure expressions.
§Variants
Array(Vec<Box<Conditional>>): A sequence of conditional expressions separated by semicolonsPrimary(Box<Primary>): An optimized representation when the procedure is a simple primary expression
§Evaluation Behavior
When a procedure contains multiple expressions, they are evaluated in order and the result of the last expression is returned. This allows for sequencing operations while maintaining a functional programming style.
§Examples
// Parses to Procedure::Primary(expression)
x + 1
// Parses to Procedure::Array([expression1, expression2, ...])
x * 2; x + 3; x - 1Variants§
Array(Vec<Box<Conditional>>)
Primary(Box<Primary>)
Primary flattened AST optimization - used when the procedure is a simple primary expression
Trait Implementations§
Source§impl ExpressionLike for Procedure
impl ExpressionLike for Procedure
Source§fn evaluate(&self, context: &mut dyn ContextLike) -> Result<Value>
fn evaluate(&self, context: &mut dyn ContextLike) -> Result<Value>
Evaluates the procedure expression.
For procedure arrays, this evaluates each conditional expression in sequence and returns the result of the last expression. For primary procedures, this evaluates the single expression directly.
§Arguments
context- The evaluation context
§Returns
Returns Result<Value> containing the result of evaluating the procedure.
§Examples
let mut context = Context::new();
let procedure = Procedure::Primary(Box::new(Primary::Literal(aimx::Literal::Number(42.0))));
let result = procedure.evaluate(&mut context)?;
// result should be Value::Literal(Literal::Number(42.0))Source§fn write(&self, writer: &mut Writer)
fn write(&self, writer: &mut Writer)
Writes the procedure expression to a writer.
This method formats the procedure according to its variant and writes it to the provided writer. The output matches the AIMX syntax for procedures.
§Arguments
writer- The writer to write the formatted procedure to
Source§fn to_sanitized(&self) -> String
fn to_sanitized(&self) -> String
Returns a sanitized string representation of the procedure.
Sanitized output is suitable for display to users and may include formatting that makes the expression easier to read.
§Returns
Returns a String containing the sanitized procedure representation.
Source§fn to_formula(&self) -> String
fn to_formula(&self) -> String
Returns a formula string representation of the procedure.
Formula output is suitable for use as input to the parser and matches the exact AIMX syntax.
§Returns
Returns a String containing the formula representation.
impl StructuralPartialEq for Procedure
Auto Trait Implementations§
impl Freeze for Procedure
impl RefUnwindSafe for Procedure
impl Send for Procedure
impl Sync for Procedure
impl Unpin for Procedure
impl UnwindSafe for Procedure
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.