Enum AstExpr

Source
pub enum AstExpr {
    Constant(Real),
    Variable(String),
    Function {
        name: String,
        args: Vec<AstExpr>,
    },
    Array {
        name: String,
        index: Box<AstExpr>,
    },
    Attribute {
        base: String,
        attr: String,
    },
}
Expand description

Abstract Syntax Tree (AST) node representing an expression.

The AST is the core data structure used for representing parsed expressions. Each variant of this enum represents a different type of expression node, forming a tree structure that can be evaluated to produce a result.

Variants§

§

Constant(Real)

A literal numerical value.

Examples: 3.14, 42, -1.5

§

Variable(String)

A named variable reference.

Examples: x, temperature, result

§

Function

A function call with a name and list of argument expressions.

Examples: sin(x), max(a, b), sqrt(x*x + y*y)

Fields

§name: String

The name of the function being called

§args: Vec<AstExpr>

The arguments passed to the function

§

Array

An array element access.

Examples: array[0], values[i+1]

Fields

§name: String

The name of the array

§index: Box<AstExpr>

The expression for the index

§

Attribute

An attribute access on an object.

Examples: point.x, settings.value

Fields

§base: String

The base object name

§attr: String

The attribute name

Implementations§

Source§

impl AstExpr

Source

pub fn pow(self, exp: Real) -> Real

Helper method that raises a constant expression to a power.

This is primarily used in testing to evaluate power operations on constants. For non-constant expressions, it returns 0.0 as a default value.

§Parameters
  • exp - The exponent to raise the constant to
§Returns

The constant raised to the given power, or 0.0 for non-constant expressions

Trait Implementations§

Source§

impl Clone for AstExpr

Source§

fn clone(&self) -> AstExpr

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AstExpr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for AstExpr

Source§

fn eq(&self, other: &AstExpr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for AstExpr

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.