diff --git a/CHANGELOG.md b/CHANGELOG.md index c2a3364..8dba73a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * Add API for value decomposition * Allow using context operations in `eval` calls without context * Operator assignment operators for each binary operation (`+=`, `-=`, ...) + * The `Operator` enum is now public for better error types ### Removed diff --git a/src/lib.rs b/src/lib.rs index b2a8e85..72e66b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -464,6 +464,7 @@ pub use crate::{ error::{EvalexprError, EvalexprResult}, function::Function, interface::*, + operator::Operator, tree::Node, value::{value_type::ValueType, EmptyType, FloatType, IntType, TupleType, Value, EMPTY_VALUE}, }; diff --git a/src/operator/mod.rs b/src/operator/mod.rs index 9a5dca0..db7b7c3 100644 --- a/src/operator/mod.rs +++ b/src/operator/mod.rs @@ -4,44 +4,86 @@ use crate::{context::Context, error::*, value::Value}; mod display; +/// An enum that represents operators in the operator tree. #[derive(Debug, PartialEq)] pub enum Operator { + /// A root node in the operator tree. + /// The whole expression is stored under a root node, as well as each subexpression surrounded by parentheses. RootNode, + /// A binary addition operator. Add, + /// A binary subtraction operator. Sub, + /// A unary negation operator. Neg, + /// A binary multiplication operator. Mul, + /// A binary division operator. Div, + /// A binary modulo operator. Mod, + /// A binary exponentiation operator. Exp, + /// A binary equality comparator. Eq, + /// A binary inequality comparator. Neq, + /// A binary greater-than comparator. Gt, + /// A binary lower-than comparator. Lt, + /// A binary greater-than-or-equal comparator. Geq, + /// A binary lower-than-or-equal comparator. Leq, + /// A binary logical and operator. And, + /// A binary logical or operator. Or, + /// A binary logical not operator. Not, + /// A binary assignment operator. Assign, + /// A binary add-assign operator. AddAssign, + /// A binary subtract-assign operator. SubAssign, + /// A binary multiply-assign operator. MulAssign, + /// A binary divide-assign operator. DivAssign, + /// A binary modulo-assign operator. ModAssign, + /// A binary exponentiate-assign operator. ExpAssign, + /// A binary and-assign operator. AndAssign, + /// A binary or-assign operator. OrAssign, + /// An n-ary tuple constructor. Tuple, + /// An n-ary subexpression chain. Chain, - Const { value: Value }, - VariableIdentifier { identifier: String }, - FunctionIdentifier { identifier: String }, + /// A constant value. + Const { + /** The value of the constant. */ + value: Value, + }, + /// A variable identifier. + VariableIdentifier { + /// The identifier of the variable. + identifier: String, + }, + /// A function identifier. + FunctionIdentifier { + /// The identifier of the function. + identifier: String, + }, } impl Operator {