Make Operator::max_argument_amount optional

Relates to #44
This commit is contained in:
Sebastian Schmidt 2019-04-13 19:11:09 +02:00
parent 9989ec98e8
commit 531b7b72a0
2 changed files with 8 additions and 8 deletions

View File

@ -94,20 +94,20 @@ impl Operator {
/// True if this operator is a leaf, meaning it accepts no arguments.
// Make this a const fn once #57563 is resolved
pub(crate) fn is_leaf(&self) -> bool {
self.max_argument_amount() == 0
self.max_argument_amount() == Some(0)
}
/// Returns the maximum amount of arguments required by this operator.
// Make this a const fn once #57563 is resolved
pub(crate) fn max_argument_amount(&self) -> usize {
pub(crate) fn max_argument_amount(&self) -> Option<usize> {
use crate::operator::Operator::*;
match self {
Add | Sub | Mul | Div | Mod | Exp | Eq | Neq | Gt | Lt | Geq | Leq | And | Or
| Tuple | Assign | Chain => 2,
Not | Neg | RootNode => 1,
Const { value: _ } => 0,
VariableIdentifier { identifier: _ } => 0,
FunctionIdentifier { identifier: _ } => 1,
| Tuple | Assign | Chain => Some(2),
Not | Neg | RootNode => Some(1),
Const { value: _ } => Some(0),
VariableIdentifier { identifier: _ } => Some(0),
FunctionIdentifier { identifier: _ } => Some(1),
}
}

View File

@ -362,7 +362,7 @@ impl Node {
}
fn has_enough_children(&self) -> bool {
self.children().len() == self.operator().max_argument_amount()
Some(self.children().len()) == self.operator().max_argument_amount()
}
fn insert_back_prioritized(&mut self, node: Node, is_root_node: bool) -> EvalexprResult<()> {