Clean up tests and docs

This commit is contained in:
Jeff 2023-08-23 19:33:04 -04:00
parent 8728bf5e46
commit 673616ac2a
4 changed files with 82 additions and 283 deletions

54
Cargo.lock generated
View File

@ -924,6 +924,33 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "dust"
version = "0.3.0"
dependencies = [
"chrono",
"clap",
"comfy-table",
"csv",
"eframe",
"egui_extras",
"git2",
"json",
"lazy_static",
"nu-ansi-term",
"rand",
"rayon",
"reedline",
"reqwest",
"serde",
"serde_json",
"sys-info",
"sysinfo",
"toml",
"toml_edit",
"trash",
]
[[package]] [[package]]
name = "ecolor" name = "ecolor"
version = "0.22.0" version = "0.22.0"
@ -3449,33 +3476,6 @@ dependencies = [
"web-sys", "web-sys",
] ]
[[package]]
name = "whale"
version = "0.3.0"
dependencies = [
"chrono",
"clap",
"comfy-table",
"csv",
"eframe",
"egui_extras",
"git2",
"json",
"lazy_static",
"nu-ansi-term",
"rand",
"rayon",
"reedline",
"reqwest",
"serde",
"serde_json",
"sys-info",
"sysinfo",
"toml",
"toml_edit",
"trash",
]
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"

View File

@ -1,19 +1,19 @@
[package] [package]
name = "whale" name = "dust"
version = "0.3.0" version = "0.3.0"
description = "Data-oriented programming language and interactive shell." description = "Data-oriented programming language and interactive shell."
authors = ["jeff <dev@jeffa.io.com>"] authors = ["jeff <dev@jeffa.io.com>"]
repository = "https://git.jeffa.io/jeff/whale.git" repository = "https://git.jeffa.io/jeff/dust.git"
homepage = "https://git.jeffa.io/jeff/whale" homepage = "https://git.jeffa.io/jeff/dust"
readme = "README.md" readme = "README.md"
license = "MIT" license = "MIT"
edition = "2018" edition = "2018"
[[bin]] [[bin]]
name = "whale" name = "dust"
[lib] [lib]
name = "whale_lib" name = "dust_lib"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]

View File

@ -206,7 +206,7 @@ impl Macro for RemoveDir {
fn run(&self, argument: &Value) -> Result<Value> { fn run(&self, argument: &Value) -> Result<Value> {
let path = argument.as_string()?; let path = argument.as_string()?;
fs::remove_file(path)?; fs::remove_dir(path)?;
Ok(Value::Empty) Ok(Value::Empty)
} }
@ -310,21 +310,34 @@ pub struct RemoveFile;
impl Macro for RemoveFile { impl Macro for RemoveFile {
fn info(&self) -> MacroInfo<'static> { fn info(&self) -> MacroInfo<'static> {
MacroInfo { MacroInfo {
identifier: "write", identifier: "remove_file",
description: "Write data to a file.", description: "Permanently delete a file.",
group: "filesystem", group: "filesystem",
inputs: vec![], inputs: vec![
ValueType::String,
ValueType::ListOf(Box::new(ValueType::String)),
],
} }
} }
fn run(&self, argument: &Value) -> Result<Value> { fn run(&self, argument: &Value) -> Result<Value> {
let strings = argument.as_list()?; if let Ok(path) = argument.as_string() {
fs::remove_file(path)?;
Error::expect_function_argument_amount(self.info().identifier, strings.len(), 2)?; return Ok(Value::Empty);
}
let _path = strings.first().unwrap().as_string()?; if let Ok(path_list) = argument.as_list() {
for path in path_list {
let path = path.as_string()?;
todo!(); fs::remove_file(path)?;
}
return Ok(Value::Empty);
}
Err(Error::expected_string(argument.clone()))
} }
} }

View File

@ -11,7 +11,6 @@ use std::{
mem, mem,
}; };
// Exclude display module from coverage, as it prints not well-defined prefix notation.
#[cfg(not(tarpaulin_include))] #[cfg(not(tarpaulin_include))]
mod iter; mod iter;
@ -20,18 +19,6 @@ mod iter;
/// It can be evaluated for a given context with the `Node::eval` method. /// It can be evaluated for a given context with the `Node::eval` method.
/// ///
/// The advantage of constructing the operator tree separately from the actual evaluation is that it can be evaluated arbitrarily often with different contexts. /// The advantage of constructing the operator tree separately from the actual evaluation is that it can be evaluated arbitrarily often with different contexts.
///
/// # Examples
///
/// ```rust
/// use evalexpr::*;
///
/// let mut context = HashMapContext::new();
/// context.set_value("alpha".into(), 2.into()).unwrap(); // Do proper error handling here
/// let node = build_operator_tree("1 + alpha").unwrap(); // Do proper error handling here
/// assert_eq!(node.eval_with_context(&context), Ok(Value::from(3)));
/// ```
///
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub struct Node { pub struct Node {
operator: Operator, operator: Operator,
@ -50,22 +37,6 @@ impl Node {
Self::new(Operator::RootNode) Self::new(Operator::RootNode)
} }
/// Returns an iterator over all identifiers in this expression.
/// Each occurrence of an identifier is returned separately.
///
/// # Examples
///
/// ```rust
/// use evalexpr::*;
///
/// let tree = build_operator_tree("a + b + c * f()").unwrap(); // Do proper error handling here
/// let mut iter = tree.iter_identifiers();
/// assert_eq!(iter.next(), Some("a"));
/// assert_eq!(iter.next(), Some("b"));
/// assert_eq!(iter.next(), Some("c"));
/// assert_eq!(iter.next(), Some("f"));
/// assert_eq!(iter.next(), None);
/// ```
pub fn iter_identifiers(&self) -> impl Iterator<Item = &str> { pub fn iter_identifiers(&self) -> impl Iterator<Item = &str> {
self.iter().filter_map(|node| match node.operator() { self.iter().filter_map(|node| match node.operator() {
Operator::VariableIdentifierWrite { identifier } Operator::VariableIdentifierWrite { identifier }
@ -77,26 +48,6 @@ impl Node {
/// Returns an iterator over all identifiers in this expression, allowing mutation. /// Returns an iterator over all identifiers in this expression, allowing mutation.
/// Each occurrence of an identifier is returned separately. /// Each occurrence of an identifier is returned separately.
///
/// # Examples
///
/// ```rust
/// use evalexpr::*;
///
/// let mut tree = build_operator_tree("a + b + c * f()").unwrap(); // Do proper error handling here
///
/// for identifier in tree.iter_identifiers_mut() {
/// *identifier = String::from("x");
/// }
///
/// let mut iter = tree.iter_identifiers();
///
/// assert_eq!(iter.next(), Some("x"));
/// assert_eq!(iter.next(), Some("x"));
/// assert_eq!(iter.next(), Some("x"));
/// assert_eq!(iter.next(), Some("x"));
/// assert_eq!(iter.next(), None);
/// ```
pub fn iter_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> { pub fn iter_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> {
self.iter_operators_mut() self.iter_operators_mut()
.filter_map(|operator| match operator { .filter_map(|operator| match operator {
@ -109,19 +60,6 @@ impl Node {
/// Returns an iterator over all variable identifiers in this expression. /// Returns an iterator over all variable identifiers in this expression.
/// Each occurrence of a variable identifier is returned separately. /// Each occurrence of a variable identifier is returned separately.
///
/// # Examples
///
/// ```rust
/// use evalexpr::*;
///
/// let tree = build_operator_tree("a + f(b + c)").unwrap(); // Do proper error handling here
/// let mut iter = tree.iter_variable_identifiers();
/// assert_eq!(iter.next(), Some("a"));
/// assert_eq!(iter.next(), Some("b"));
/// assert_eq!(iter.next(), Some("c"));
/// assert_eq!(iter.next(), None);
/// ```
pub fn iter_variable_identifiers(&self) -> impl Iterator<Item = &str> { pub fn iter_variable_identifiers(&self) -> impl Iterator<Item = &str> {
self.iter().filter_map(|node| match node.operator() { self.iter().filter_map(|node| match node.operator() {
Operator::VariableIdentifierWrite { identifier } Operator::VariableIdentifierWrite { identifier }
@ -132,26 +70,6 @@ impl Node {
/// Returns an iterator over all variable identifiers in this expression, allowing mutation. /// Returns an iterator over all variable identifiers in this expression, allowing mutation.
/// Each occurrence of a variable identifier is returned separately. /// Each occurrence of a variable identifier is returned separately.
///
/// # Examples
///
/// ```rust
/// use evalexpr::*;
///
/// let mut tree = build_operator_tree("a + b + c * f()").unwrap(); // Do proper error handling here
///
/// for identifier in tree.iter_variable_identifiers_mut() {
/// *identifier = String::from("x");
/// }
///
/// let mut iter = tree.iter_identifiers();
///
/// assert_eq!(iter.next(), Some("x"));
/// assert_eq!(iter.next(), Some("x"));
/// assert_eq!(iter.next(), Some("x"));
/// assert_eq!(iter.next(), Some("f"));
/// assert_eq!(iter.next(), None);
/// ```
pub fn iter_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> { pub fn iter_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> {
self.iter_operators_mut() self.iter_operators_mut()
.filter_map(|operator| match operator { .filter_map(|operator| match operator {
@ -163,19 +81,6 @@ impl Node {
/// Returns an iterator over all read variable identifiers in this expression. /// Returns an iterator over all read variable identifiers in this expression.
/// Each occurrence of a variable identifier is returned separately. /// Each occurrence of a variable identifier is returned separately.
///
/// # Examples
///
/// ```rust
/// use evalexpr::*;
///
/// let tree = build_operator_tree("d = a + f(b + c)").unwrap(); // Do proper error handling here
/// let mut iter = tree.iter_read_variable_identifiers();
/// assert_eq!(iter.next(), Some("a"));
/// assert_eq!(iter.next(), Some("b"));
/// assert_eq!(iter.next(), Some("c"));
/// assert_eq!(iter.next(), None);
/// ```
pub fn iter_read_variable_identifiers(&self) -> impl Iterator<Item = &str> { pub fn iter_read_variable_identifiers(&self) -> impl Iterator<Item = &str> {
self.iter().filter_map(|node| match node.operator() { self.iter().filter_map(|node| match node.operator() {
Operator::VariableIdentifierRead { identifier } => Some(identifier.as_str()), Operator::VariableIdentifierRead { identifier } => Some(identifier.as_str()),
@ -185,27 +90,6 @@ impl Node {
/// Returns an iterator over all read variable identifiers in this expression, allowing mutation. /// Returns an iterator over all read variable identifiers in this expression, allowing mutation.
/// Each occurrence of a variable identifier is returned separately. /// Each occurrence of a variable identifier is returned separately.
///
/// # Examples
///
/// ```rust
/// use evalexpr::*;
///
/// let mut tree = build_operator_tree("d = a + f(b + c)").unwrap(); // Do proper error handling here
///
/// for identifier in tree.iter_read_variable_identifiers_mut() {
/// *identifier = String::from("x");
/// }
///
/// let mut iter = tree.iter_identifiers();
///
/// assert_eq!(iter.next(), Some("d"));
/// assert_eq!(iter.next(), Some("x"));
/// assert_eq!(iter.next(), Some("f"));
/// assert_eq!(iter.next(), Some("x"));
/// assert_eq!(iter.next(), Some("x"));
/// assert_eq!(iter.next(), None);
/// ```
pub fn iter_read_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> { pub fn iter_read_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> {
self.iter_operators_mut() self.iter_operators_mut()
.filter_map(|operator| match operator { .filter_map(|operator| match operator {
@ -216,17 +100,6 @@ impl Node {
/// Returns an iterator over all write variable identifiers in this expression. /// Returns an iterator over all write variable identifiers in this expression.
/// Each occurrence of a variable identifier is returned separately. /// Each occurrence of a variable identifier is returned separately.
///
/// # Examples
///
/// ```rust
/// use evalexpr::*;
///
/// let tree = build_operator_tree("d = a + f(b + c)").unwrap(); // Do proper error handling here
/// let mut iter = tree.iter_write_variable_identifiers();
/// assert_eq!(iter.next(), Some("d"));
/// assert_eq!(iter.next(), None);
/// ```
pub fn iter_write_variable_identifiers(&self) -> impl Iterator<Item = &str> { pub fn iter_write_variable_identifiers(&self) -> impl Iterator<Item = &str> {
self.iter().filter_map(|node| match node.operator() { self.iter().filter_map(|node| match node.operator() {
Operator::VariableIdentifierWrite { identifier } => Some(identifier.as_str()), Operator::VariableIdentifierWrite { identifier } => Some(identifier.as_str()),
@ -236,27 +109,6 @@ impl Node {
/// Returns an iterator over all write variable identifiers in this expression, allowing mutation. /// Returns an iterator over all write variable identifiers in this expression, allowing mutation.
/// Each occurrence of a variable identifier is returned separately. /// Each occurrence of a variable identifier is returned separately.
///
/// # Examples
///
/// ```rust
/// use evalexpr::*;
///
/// let mut tree = build_operator_tree("d = a + f(b + c)").unwrap(); // Do proper error handling here
///
/// for identifier in tree.iter_write_variable_identifiers_mut() {
/// *identifier = String::from("x");
/// }
///
/// let mut iter = tree.iter_identifiers();
///
/// assert_eq!(iter.next(), Some("x"));
/// assert_eq!(iter.next(), Some("a"));
/// assert_eq!(iter.next(), Some("f"));
/// assert_eq!(iter.next(), Some("b"));
/// assert_eq!(iter.next(), Some("c"));
/// assert_eq!(iter.next(), None);
/// ```
pub fn iter_write_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> { pub fn iter_write_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> {
self.iter_operators_mut() self.iter_operators_mut()
.filter_map(|operator| match operator { .filter_map(|operator| match operator {
@ -267,17 +119,6 @@ impl Node {
/// Returns an iterator over all function identifiers in this expression. /// Returns an iterator over all function identifiers in this expression.
/// Each occurrence of a function identifier is returned separately. /// Each occurrence of a function identifier is returned separately.
///
/// # Examples
///
/// ```rust
/// use evalexpr::*;
///
/// let tree = build_operator_tree("a + f(b + c)").unwrap(); // Do proper error handling here
/// let mut iter = tree.iter_function_identifiers();
/// assert_eq!(iter.next(), Some("f"));
/// assert_eq!(iter.next(), None);
/// ```
pub fn iter_function_identifiers(&self) -> impl Iterator<Item = &str> { pub fn iter_function_identifiers(&self) -> impl Iterator<Item = &str> {
self.iter().filter_map(|node| match node.operator() { self.iter().filter_map(|node| match node.operator() {
Operator::FunctionIdentifier { identifier } => Some(identifier.as_str()), Operator::FunctionIdentifier { identifier } => Some(identifier.as_str()),
@ -287,27 +128,6 @@ impl Node {
/// Returns an iterator over all function identifiers in this expression, allowing mutation. /// Returns an iterator over all function identifiers in this expression, allowing mutation.
/// Each occurrence of a variable identifier is returned separately. /// Each occurrence of a variable identifier is returned separately.
///
/// # Examples
///
/// ```rust
/// use evalexpr::*;
///
/// let mut tree = build_operator_tree("d = a + f(b + c)").unwrap(); // Do proper error handling here
///
/// for identifier in tree.iter_function_identifiers_mut() {
/// *identifier = String::from("x");
/// }
///
/// let mut iter = tree.iter_identifiers();
///
/// assert_eq!(iter.next(), Some("d"));
/// assert_eq!(iter.next(), Some("a"));
/// assert_eq!(iter.next(), Some("x"));
/// assert_eq!(iter.next(), Some("b"));
/// assert_eq!(iter.next(), Some("c"));
/// assert_eq!(iter.next(), None);
/// ```
pub fn iter_function_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> { pub fn iter_function_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> {
self.iter_operators_mut() self.iter_operators_mut()
.filter_map(|operator| match operator { .filter_map(|operator| match operator {
@ -316,9 +136,8 @@ impl Node {
}) })
} }
/// Evaluates the operator tree rooted at this node with the given context. /// Evaluates the operator tree rooted at this node with the given context. Fails if one of the
/// /// operators in the expression tree fails.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_with_context(&self, context: &VariableMap) -> Result<Value> { pub fn eval_with_context(&self, context: &VariableMap) -> Result<Value> {
let mut arguments = Vec::new(); let mut arguments = Vec::new();
for child in self.children() { for child in self.children() {
@ -328,8 +147,7 @@ impl Node {
} }
/// Evaluates the operator tree rooted at this node with the given mutable context. /// Evaluates the operator tree rooted at this node with the given mutable context.
/// /// Fails if one of the operators in the expression tree fails.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_with_context_mut(&self, context: &mut VariableMap) -> Result<Value> { pub fn eval_with_context_mut(&self, context: &mut VariableMap) -> Result<Value> {
let mut arguments = Vec::new(); let mut arguments = Vec::new();
for child in self.children() { for child in self.children() {
@ -339,15 +157,13 @@ impl Node {
} }
/// Evaluates the operator tree rooted at this node. /// Evaluates the operator tree rooted at this node.
/// /// Fails if one of the operators in the expression tree fails.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval(&self) -> Result<Value> { pub fn eval(&self) -> Result<Value> {
self.eval_with_context_mut(&mut VariableMap::new()) self.eval_with_context_mut(&mut VariableMap::new())
} }
/// Evaluates the operator tree rooted at this node into a string with an the given context. /// Evaluates the operator tree rooted at this node into a string with an the given context.
/// /// Fails if one of the operators in the expression tree fails.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_string_with_context(&self, context: &VariableMap) -> Result<String> { pub fn eval_string_with_context(&self, context: &VariableMap) -> Result<String> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::String(string)) => Ok(string), Ok(Value::String(string)) => Ok(string),
@ -357,8 +173,7 @@ impl Node {
} }
/// Evaluates the operator tree rooted at this node into a float with an the given context. /// Evaluates the operator tree rooted at this node into a float with an the given context.
/// /// Fails if one of the operators in the expression tree fails.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_float_with_context(&self, context: &VariableMap) -> Result<f64> { pub fn eval_float_with_context(&self, context: &VariableMap) -> Result<f64> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::Float(float)) => Ok(float), Ok(Value::Float(float)) => Ok(float),
@ -368,8 +183,7 @@ impl Node {
} }
/// Evaluates the operator tree rooted at this node into an integer with an the given context. /// Evaluates the operator tree rooted at this node into an integer with an the given context.
/// /// Fails if one of the operators in the expression tree fails.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_int_with_context(&self, context: &VariableMap) -> Result<i64> { pub fn eval_int_with_context(&self, context: &VariableMap) -> Result<i64> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::Integer(int)) => Ok(int), Ok(Value::Integer(int)) => Ok(int),
@ -378,10 +192,8 @@ impl Node {
} }
} }
/// Evaluates the operator tree rooted at this node into a float with an the given context. /// Evaluates the operator tree rooted at this node into a float with an the given context. If
/// If the result of the expression is an integer, it is silently converted into a float. /// 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.
///
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_number_with_context(&self, context: &VariableMap) -> Result<f64> { pub fn eval_number_with_context(&self, context: &VariableMap) -> Result<f64> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::Integer(int)) => Ok(int as f64), Ok(Value::Integer(int)) => Ok(int as f64),
@ -391,9 +203,8 @@ impl Node {
} }
} }
/// Evaluates the operator tree rooted at this node into a boolean with an the given context. /// Evaluates the operator tree rooted at this node into a boolean with an the given context
/// /// Fails if one of the operators in the expression tree fails.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_boolean_with_context(&self, context: &VariableMap) -> Result<bool> { pub fn eval_boolean_with_context(&self, context: &VariableMap) -> Result<bool> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::Boolean(boolean)) => Ok(boolean), Ok(Value::Boolean(boolean)) => Ok(boolean),
@ -403,8 +214,7 @@ impl Node {
} }
/// Evaluates the operator tree rooted at this node into a tuple with an the given context. /// Evaluates the operator tree rooted at this node into a tuple with an the given context.
/// /// Fails if one of the operators in the expression tree fails.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_tuple_with_context(&self, context: &VariableMap) -> Result<Vec<Value>> { pub fn eval_tuple_with_context(&self, context: &VariableMap) -> Result<Vec<Value>> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::List(tuple)) => Ok(tuple), Ok(Value::List(tuple)) => Ok(tuple),
@ -414,8 +224,7 @@ impl Node {
} }
/// Evaluates the operator tree rooted at this node into an empty value with an the given context. /// Evaluates the operator tree rooted at this node into an empty value with an the given context.
/// /// Fails if one of the operators in the expression tree fails.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_empty_with_context(&self, context: &VariableMap) -> Result<()> { pub fn eval_empty_with_context(&self, context: &VariableMap) -> Result<()> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::Empty) => Ok(()), Ok(Value::Empty) => Ok(()),
@ -425,8 +234,7 @@ impl Node {
} }
/// Evaluates the operator tree rooted at this node into a string with an the given mutable context. /// Evaluates the operator tree rooted at this node into a string with an the given mutable context.
/// /// Fails if one of the operators in the expression tree fails.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_string_with_context_mut(&self, context: &mut VariableMap) -> Result<String> { pub fn eval_string_with_context_mut(&self, context: &mut VariableMap) -> Result<String> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::String(string)) => Ok(string), Ok(Value::String(string)) => Ok(string),
@ -436,8 +244,7 @@ impl Node {
} }
/// Evaluates the operator tree rooted at this node into a float with an the given mutable context. /// Evaluates the operator tree rooted at this node into a float with an the given mutable context.
/// /// Fails if one of the operators in the expression tree fails.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_float_with_context_mut(&self, context: &mut VariableMap) -> Result<f64> { pub fn eval_float_with_context_mut(&self, context: &mut VariableMap) -> Result<f64> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::Float(float)) => Ok(float), Ok(Value::Float(float)) => Ok(float),
@ -447,8 +254,7 @@ impl Node {
} }
/// Evaluates the operator tree rooted at this node into an integer with an the given mutable context. /// Evaluates the operator tree rooted at this node into an integer with an the given mutable context.
/// /// Fails if one of the operators in the expression tree fails.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_int_with_context_mut(&self, context: &mut VariableMap) -> Result<i64> { pub fn eval_int_with_context_mut(&self, context: &mut VariableMap) -> Result<i64> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::Integer(int)) => Ok(int), Ok(Value::Integer(int)) => Ok(int),
@ -459,8 +265,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node into a float with an the given mutable context. /// Evaluates the operator tree rooted at this node into a float with an the given mutable context.
/// If the result of the expression is an integer, it is silently converted 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.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_number_with_context_mut(&self, context: &mut VariableMap) -> Result<f64> { pub fn eval_number_with_context_mut(&self, context: &mut VariableMap) -> Result<f64> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::Integer(int)) => Ok(int as f64), Ok(Value::Integer(int)) => Ok(int as f64),
@ -470,9 +275,7 @@ impl Node {
} }
} }
/// Evaluates the operator tree rooted at this node into a boolean with an the given mutable context. /// Evaluates the operator tree rooted at this node into a boolean with an the given mutable /// context. Fails if one of the operators in the expression tree fails.
///
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_boolean_with_context_mut(&self, context: &mut VariableMap) -> Result<bool> { pub fn eval_boolean_with_context_mut(&self, context: &mut VariableMap) -> Result<bool> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::Boolean(boolean)) => Ok(boolean), Ok(Value::Boolean(boolean)) => Ok(boolean),
@ -481,9 +284,7 @@ impl Node {
} }
} }
/// Evaluates the operator tree rooted at this node into a tuple with an the given mutable context. /// Evaluates the operator tree rooted at this node into a tuple with an the given mutable /// context. Fails if one of the operators in the expression tree fails.
///
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_tuple_with_context_mut(&self, context: &mut VariableMap) -> Result<Vec<Value>> { pub fn eval_tuple_with_context_mut(&self, context: &mut VariableMap) -> Result<Vec<Value>> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::List(tuple)) => Ok(tuple), Ok(Value::List(tuple)) => Ok(tuple),
@ -492,9 +293,7 @@ impl Node {
} }
} }
/// Evaluates the operator tree rooted at this node into an empty value with an the given mutable context. /// Evaluates the operator tree rooted at this node into an empty value with an the given /// mutable context. Fails if one of the operators in the expression tree fails.
///
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_empty_with_context_mut(&self, context: &mut VariableMap) -> Result<()> { pub fn eval_empty_with_context_mut(&self, context: &mut VariableMap) -> Result<()> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::Empty) => Ok(()), Ok(Value::Empty) => Ok(()),
@ -503,52 +302,39 @@ impl Node {
} }
} }
/// Evaluates the operator tree rooted at this node into a string. /// Evaluates the operator tree rooted at this node into a string. Fails if one of the /// operators in the expression tree fails.
///
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_string(&self) -> Result<String> { pub fn eval_string(&self) -> Result<String> {
self.eval_string_with_context_mut(&mut VariableMap::new()) self.eval_string_with_context_mut(&mut VariableMap::new())
} }
/// Evaluates the operator tree rooted at this node into a float. /// Evaluates the operator tree rooted at this node into a float. Fails if one of the operators /// in the expression tree fails.
///
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_float(&self) -> Result<f64> { pub fn eval_float(&self) -> Result<f64> {
self.eval_float_with_context_mut(&mut VariableMap::new()) self.eval_float_with_context_mut(&mut VariableMap::new())
} }
/// Evaluates the operator tree rooted at this node into an integer. /// Evaluates the operator tree rooted at this node into an integer. Fails if one of the
/// /// operators in the expression tree fails.
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_int(&self) -> Result<i64> { pub fn eval_int(&self) -> Result<i64> {
self.eval_int_with_context_mut(&mut VariableMap::new()) self.eval_int_with_context_mut(&mut VariableMap::new())
} }
/// Evaluates the operator tree rooted at this node into a float. /// Evaluates the operator tree rooted at this node into a float. If the result of the
/// If the result of the expression is an integer, it is silently converted into a float. /// expression is an integer, it is silently converted into a float. Fails if one of the /// operators in the expression tree fails.
///
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_number(&self) -> Result<f64> { pub fn eval_number(&self) -> Result<f64> {
self.eval_number_with_context_mut(&mut VariableMap::new()) self.eval_number_with_context_mut(&mut VariableMap::new())
} }
/// Evaluates the operator tree rooted at this node into a boolean. /// Evaluates the operator tree rooted at this node into a boolean. Fails if one of the /// operators in the expression tree fails.
///
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_boolean(&self) -> Result<bool> { pub fn eval_boolean(&self) -> Result<bool> {
self.eval_boolean_with_context_mut(&mut VariableMap::new()) self.eval_boolean_with_context_mut(&mut VariableMap::new())
} }
/// Evaluates the operator tree rooted at this node into a tuple. /// Evaluates the operator tree rooted at this node into a tuple. Fails if one of the operators /// in the expression tree fails.
///
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_tuple(&self) -> Result<Vec<Value>> { pub fn eval_tuple(&self) -> Result<Vec<Value>> {
self.eval_tuple_with_context_mut(&mut VariableMap::new()) self.eval_tuple_with_context_mut(&mut VariableMap::new())
} }
/// Evaluates the operator tree rooted at this node into an empty value. /// Evaluates the operator tree rooted at this node into an empty value. Fails if one of the /// operators in the expression tree fails.
///
/// Fails, if one of the operators in the expression tree fails.
pub fn eval_empty(&self) -> Result<()> { pub fn eval_empty(&self) -> Result<()> {
self.eval_empty_with_context_mut(&mut VariableMap::new()) self.eval_empty_with_context_mut(&mut VariableMap::new())
} }