pub struct BeTree<Op, Atom>where
Op: Debug + Clone + PartialEq,
Atom: Debug + Clone,{ /* private fields */ }
Expand description
An expression which may contain unary and binary operations
Implementations
sourceimpl<Op, Atom> BeTree<Op, Atom>where
Op: Debug + Clone + PartialEq,
Atom: Debug + Clone,
impl<Op, Atom> BeTree<Op, Atom>where
Op: Debug + Clone + PartialEq,
Atom: Debug + Clone,
pub fn node(&self, node_id: NodeId) -> Option<&Node<Op>>
pub fn atom(&self, atom_id: AtomId) -> Option<&Atom>
pub fn head(&self) -> &Node<Op>
sourcepub fn iter_atoms<'a>(&'a self) -> Iter<'a, Atom>
pub fn iter_atoms<'a>(&'a self) -> Iter<'a, Atom>
iterate on all atoms
sourcepub fn current_atom<'a>(&'a self) -> Option<&'a Atom>
pub fn current_atom<'a>(&'a self) -> Option<&'a Atom>
returns a reference to the last atom if it’s the last pushed token. Return none in other cases (including when no atom has been pushed at all)
sourcepub fn get_openess(&self) -> usize
pub fn get_openess(&self) -> usize
return the count of open parenthesis minus the one of closing parenthesis. Illegal closing parenthesis are ignored (hence why this count can be a usize)
sourcepub fn push(&mut self, token: Token<Op, Atom>)
pub fn push(&mut self, token: Token<Op, Atom>)
add one of the possible token: parenthesis, operator or atom
sourcepub fn mutate_or_create_atom<Create>(&mut self, create: Create) -> &mut Atomwhere
Create: Fn() -> Atom,
pub fn mutate_or_create_atom<Create>(&mut self, create: Create) -> &mut Atomwhere
Create: Fn() -> Atom,
if the last change was an atom pushed or modified, return a mutable reference to this atom. If not, push a new atom and return a mutable reference to it.
sourcepub fn push_operator(&mut self, operator: Op)
pub fn push_operator(&mut self, operator: Op)
add an operator right of the expression
The context will decide whether it’s unary or binary
sourcepub fn accept_unary_operator(&self) -> bool
pub fn accept_unary_operator(&self) -> bool
tell whether it would make sense to push a unary operator at this point (for example it makes no sense just after an atom)
sourcepub fn accept_binary_operator(&self) -> bool
pub fn accept_binary_operator(&self) -> bool
tell whether it would make sense to push a binary operator at this point (for example it makes no sense just after another operator)
sourcepub fn accept_atom(&self) -> bool
pub fn accept_atom(&self) -> bool
tell whether it would make sense to push an atom at this point (for example it makes no sense just after a closing parenthesis)
sourcepub fn accept_opening_par(&self) -> bool
pub fn accept_opening_par(&self) -> bool
tell whether it would make sense to open a parenthesis at this point (for example it makes no sense just after a closing parenthesis)
sourcepub fn accept_closing_par(&self) -> bool
pub fn accept_closing_par(&self) -> bool
tell whether it would make sense to close a parenthesis at this point (for example it makes no sense just after an operator or if there are more closing parenthesis than opening ones)
sourcepub fn try_map_atoms<Atom2, Err, F>(
&self,
f: F
) -> Result<BeTree<Op, Atom2>, Err>where
Atom2: Debug + Clone,
F: Fn(&Atom) -> Result<Atom2, Err>,
pub fn try_map_atoms<Atom2, Err, F>(
&self,
f: F
) -> Result<BeTree<Op, Atom2>, Err>where
Atom2: Debug + Clone,
F: Fn(&Atom) -> Result<Atom2, Err>,
produce a new expression by applying a transformation on all atoms
The operation will stop at the first error
sourcepub fn eval<R, EvalAtom, EvalOp, ShortCircuit>(
&self,
eval_atom: EvalAtom,
eval_op: EvalOp,
short_circuit: ShortCircuit
) -> Option<R>where
EvalAtom: Fn(&Atom) -> R,
EvalOp: Fn(&Op, R, Option<R>) -> R,
ShortCircuit: Fn(&Op, &R) -> bool,
pub fn eval<R, EvalAtom, EvalOp, ShortCircuit>(
&self,
eval_atom: EvalAtom,
eval_op: EvalOp,
short_circuit: ShortCircuit
) -> Option<R>where
EvalAtom: Fn(&Atom) -> R,
EvalOp: Fn(&Op, R, Option<R>) -> R,
ShortCircuit: Fn(&Op, &R) -> bool,
evaluate the expression.
eval_atom
will be called on all atoms (leafs) of the expression while eval_op
will be used to join values until the final result is obtained.
short_circuit
will be called on all binary operations with the operator
and the left operands as arguments. If it returns true
then the right
operand isn’t evaluated (it’s guaranteed so it may serve as guard).
This function should be used when neither atom evaluation nor operator execution can raise errors (this usually means consistency checks have been done during parsing).
sourcepub fn eval_faillible<Err, R, EvalAtom, EvalOp, ShortCircuit>(
&self,
eval_atom: EvalAtom,
eval_op: EvalOp,
short_circuit: ShortCircuit
) -> Result<Option<R>, Err>where
EvalAtom: Fn(&Atom) -> Result<R, Err>,
EvalOp: Fn(&Op, R, Option<R>) -> Result<R, Err>,
ShortCircuit: Fn(&Op, &R) -> bool,
pub fn eval_faillible<Err, R, EvalAtom, EvalOp, ShortCircuit>(
&self,
eval_atom: EvalAtom,
eval_op: EvalOp,
short_circuit: ShortCircuit
) -> Result<Option<R>, Err>where
EvalAtom: Fn(&Atom) -> Result<R, Err>,
EvalOp: Fn(&Op, R, Option<R>) -> Result<R, Err>,
ShortCircuit: Fn(&Op, &R) -> bool,
evaluate the expression.
eval_atom
will be called on all atoms (leafs) of the expression while eval_op
will be used to join values until the final result is obtained.
short_circuit
will be called on all binary operations with the operator
and the left operands as arguments. If it returns true
then the right
operand isn’t evaluated (it’s guaranteed so it may serve as guard).
This function should be used when errors are expected during either atom evaluation or operator execution (for example because parsing was lax). The first Error returned by one of those functions breaks the evaluation and is returned.