From a36d4d3815ec3d00a881421d1c35c64897c578c7 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Thu, 29 Aug 2019 18:06:39 +0300 Subject: [PATCH] Use mutable contexts in eval methods of Node This was forgotten when closing #45. Relates to #45 --- src/tree/mod.rs | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 58b59d1..9d7a78d 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -1,8 +1,4 @@ -use crate::{ - token::Token, - value::{TupleType, EMPTY_VALUE}, - EmptyContext, EmptyType, FloatType, IntType, -}; +use crate::{token::Token, value::{TupleType, EMPTY_VALUE}, EmptyType, FloatType, IntType, HashMapContext}; use crate::{ context::Context, @@ -138,11 +134,11 @@ impl Node { self.operator().eval_mut(&arguments, context) } - /// Evaluates the operator tree rooted at this node with an empty context. + /// Evaluates the operator tree rooted at this node. /// /// Fails, if one of the operators in the expression tree fails. pub fn eval(&self) -> EvalexprResult { - self.eval_with_context(&EmptyContext) + self.eval_with_context_mut(&mut HashMapContext::new()) } /// Evaluates the operator tree rooted at this node into a string with an the given context. @@ -318,54 +314,54 @@ impl Node { } } - /// Evaluates the operator tree rooted at this node into a string with an empty context. + /// Evaluates the operator tree rooted at this node into a string. /// /// Fails, if one of the operators in the expression tree fails. pub fn eval_string(&self) -> EvalexprResult { - self.eval_string_with_context(&EmptyContext) + self.eval_string_with_context_mut(&mut HashMapContext::new()) } - /// Evaluates the operator tree rooted at this node into a float with an empty context. + /// Evaluates the operator tree rooted at this node into a float. /// /// Fails, if one of the operators in the expression tree fails. pub fn eval_float(&self) -> EvalexprResult { - self.eval_float_with_context(&EmptyContext) + self.eval_float_with_context_mut(&mut HashMapContext::new()) } - /// Evaluates the operator tree rooted at this node into an integer with an empty context. + /// Evaluates the operator tree rooted at this node into an integer. /// /// Fails, if one of the operators in the expression tree fails. pub fn eval_int(&self) -> EvalexprResult { - self.eval_int_with_context(&EmptyContext) + self.eval_int_with_context_mut(&mut HashMapContext::new()) } - /// Evaluates the operator tree rooted at this node into a float with an empty context. + /// Evaluates the operator tree rooted at this node into a float. /// If the result of the expression is an integer, it is silently converted into a float. /// /// Fails, if one of the operators in the expression tree fails. pub fn eval_number(&self) -> EvalexprResult { - self.eval_number_with_context(&EmptyContext) + self.eval_number_with_context_mut(&mut HashMapContext::new()) } - /// Evaluates the operator tree rooted at this node into a boolean with an empty context. + /// Evaluates the operator tree rooted at this node into a boolean. /// /// Fails, if one of the operators in the expression tree fails. pub fn eval_boolean(&self) -> EvalexprResult { - self.eval_boolean_with_context(&EmptyContext) + self.eval_boolean_with_context_mut(&mut HashMapContext::new()) } - /// Evaluates the operator tree rooted at this node into a tuple with an empty context. + /// Evaluates the operator tree rooted at this node into a tuple. /// /// Fails, if one of the operators in the expression tree fails. pub fn eval_tuple(&self) -> EvalexprResult { - self.eval_tuple_with_context(&EmptyContext) + self.eval_tuple_with_context_mut(&mut HashMapContext::new()) } - /// Evaluates the operator tree rooted at this node into an empty value with an empty context. + /// Evaluates the operator tree rooted at this node into an empty value. /// /// Fails, if one of the operators in the expression tree fails. pub fn eval_empty(&self) -> EvalexprResult { - self.eval_empty_with_context(&EmptyContext) + self.eval_empty_with_context_mut(&mut HashMapContext::new()) } fn children(&self) -> &[Node] {