Make operator enum public
This is required for better error messages. Relates to #60
This commit is contained in:
parent
88719317a5
commit
2ec3dc74c1
@ -15,6 +15,7 @@
|
|||||||
* Add API for value decomposition
|
* Add API for value decomposition
|
||||||
* Allow using context operations in `eval` calls without context
|
* Allow using context operations in `eval` calls without context
|
||||||
* Operator assignment operators for each binary operation (`+=`, `-=`, ...)
|
* Operator assignment operators for each binary operation (`+=`, `-=`, ...)
|
||||||
|
* The `Operator` enum is now public for better error types
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@ -464,6 +464,7 @@ pub use crate::{
|
|||||||
error::{EvalexprError, EvalexprResult},
|
error::{EvalexprError, EvalexprResult},
|
||||||
function::Function,
|
function::Function,
|
||||||
interface::*,
|
interface::*,
|
||||||
|
operator::Operator,
|
||||||
tree::Node,
|
tree::Node,
|
||||||
value::{value_type::ValueType, EmptyType, FloatType, IntType, TupleType, Value, EMPTY_VALUE},
|
value::{value_type::ValueType, EmptyType, FloatType, IntType, TupleType, Value, EMPTY_VALUE},
|
||||||
};
|
};
|
||||||
|
@ -4,44 +4,86 @@ use crate::{context::Context, error::*, value::Value};
|
|||||||
|
|
||||||
mod display;
|
mod display;
|
||||||
|
|
||||||
|
/// An enum that represents operators in the operator tree.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Operator {
|
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,
|
RootNode,
|
||||||
|
|
||||||
|
/// A binary addition operator.
|
||||||
Add,
|
Add,
|
||||||
|
/// A binary subtraction operator.
|
||||||
Sub,
|
Sub,
|
||||||
|
/// A unary negation operator.
|
||||||
Neg,
|
Neg,
|
||||||
|
/// A binary multiplication operator.
|
||||||
Mul,
|
Mul,
|
||||||
|
/// A binary division operator.
|
||||||
Div,
|
Div,
|
||||||
|
/// A binary modulo operator.
|
||||||
Mod,
|
Mod,
|
||||||
|
/// A binary exponentiation operator.
|
||||||
Exp,
|
Exp,
|
||||||
|
|
||||||
|
/// A binary equality comparator.
|
||||||
Eq,
|
Eq,
|
||||||
|
/// A binary inequality comparator.
|
||||||
Neq,
|
Neq,
|
||||||
|
/// A binary greater-than comparator.
|
||||||
Gt,
|
Gt,
|
||||||
|
/// A binary lower-than comparator.
|
||||||
Lt,
|
Lt,
|
||||||
|
/// A binary greater-than-or-equal comparator.
|
||||||
Geq,
|
Geq,
|
||||||
|
/// A binary lower-than-or-equal comparator.
|
||||||
Leq,
|
Leq,
|
||||||
|
/// A binary logical and operator.
|
||||||
And,
|
And,
|
||||||
|
/// A binary logical or operator.
|
||||||
Or,
|
Or,
|
||||||
|
/// A binary logical not operator.
|
||||||
Not,
|
Not,
|
||||||
|
|
||||||
|
/// A binary assignment operator.
|
||||||
Assign,
|
Assign,
|
||||||
|
/// A binary add-assign operator.
|
||||||
AddAssign,
|
AddAssign,
|
||||||
|
/// A binary subtract-assign operator.
|
||||||
SubAssign,
|
SubAssign,
|
||||||
|
/// A binary multiply-assign operator.
|
||||||
MulAssign,
|
MulAssign,
|
||||||
|
/// A binary divide-assign operator.
|
||||||
DivAssign,
|
DivAssign,
|
||||||
|
/// A binary modulo-assign operator.
|
||||||
ModAssign,
|
ModAssign,
|
||||||
|
/// A binary exponentiate-assign operator.
|
||||||
ExpAssign,
|
ExpAssign,
|
||||||
|
/// A binary and-assign operator.
|
||||||
AndAssign,
|
AndAssign,
|
||||||
|
/// A binary or-assign operator.
|
||||||
OrAssign,
|
OrAssign,
|
||||||
|
|
||||||
|
/// An n-ary tuple constructor.
|
||||||
Tuple,
|
Tuple,
|
||||||
|
/// An n-ary subexpression chain.
|
||||||
Chain,
|
Chain,
|
||||||
|
|
||||||
Const { value: Value },
|
/// A constant value.
|
||||||
VariableIdentifier { identifier: String },
|
Const {
|
||||||
FunctionIdentifier { identifier: String },
|
/** 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 {
|
impl Operator {
|
||||||
|
Loading…
Reference in New Issue
Block a user