diff --git a/src/abstract_tree/assignment.rs b/src/abstract_tree/assignment.rs index 336e2f9..42cbe67 100644 --- a/src/abstract_tree/assignment.rs +++ b/src/abstract_tree/assignment.rs @@ -103,7 +103,7 @@ impl AbstractTree for Assignment { statement_type }; - context.set(variable_key, Value::Option(None), Some(variable_type))?; + context.set(variable_key, Value::none(), Some(variable_type))?; Ok(Assignment { identifier, @@ -143,7 +143,7 @@ impl AbstractTree for Assignment { context.set(key.clone(), new_value, None)?; } - Ok(Value::Option(None)) + Ok(Value::none()) } fn expected_type(&self, _context: &Map) -> Result { diff --git a/src/abstract_tree/block.rs b/src/abstract_tree/block.rs index 150f4df..a11a7f0 100644 --- a/src/abstract_tree/block.rs +++ b/src/abstract_tree/block.rs @@ -52,7 +52,7 @@ impl AbstractTree for Block { fn run(&self, source: &str, context: &Map) -> Result { if self.is_async { let statements = &self.statements; - let final_result = RwLock::new(Ok(Value::Option(None))); + let final_result = RwLock::new(Ok(Value::none())); statements .into_par_iter() @@ -74,7 +74,7 @@ impl AbstractTree for Block { None } }) - .unwrap_or(final_result.into_inner().unwrap()) + .unwrap_or(final_result.into_inner()?) } else { let mut prev_result = None; @@ -86,7 +86,7 @@ impl AbstractTree for Block { prev_result = Some(statement.run(source, context)); } - prev_result.unwrap_or(Ok(Value::Option(None))) + prev_result.unwrap_or(Ok(Value::none())) } } diff --git a/src/abstract_tree/for.rs b/src/abstract_tree/for.rs index 41e5618..61dd71f 100644 --- a/src/abstract_tree/for.rs +++ b/src/abstract_tree/for.rs @@ -71,7 +71,7 @@ impl AbstractTree for For { } } - Ok(Value::Option(None)) + Ok(Value::none()) } fn expected_type(&self, _context: &Map) -> Result { diff --git a/src/abstract_tree/if_else.rs b/src/abstract_tree/if_else.rs index a03717d..1baf0ec 100644 --- a/src/abstract_tree/if_else.rs +++ b/src/abstract_tree/if_else.rs @@ -76,7 +76,7 @@ impl AbstractTree for IfElse { if let Some(block) = &self.else_block { block.run(source, context) } else { - Ok(Value::Option(None)) + Ok(Value::none()) } } } diff --git a/src/abstract_tree/index_assignment.rs b/src/abstract_tree/index_assignment.rs index bb3bf44..91e14f8 100644 --- a/src/abstract_tree/index_assignment.rs +++ b/src/abstract_tree/index_assignment.rs @@ -70,7 +70,7 @@ impl AbstractTree for IndexAssignment { previous_value += value; previous_value } else { - Value::Option(None) + Value::none() } } AssignmentOperator::MinusEqual => { @@ -80,7 +80,7 @@ impl AbstractTree for IndexAssignment { previous_value -= value; previous_value } else { - Value::Option(None) + Value::none() } } AssignmentOperator::Equal => value, @@ -88,7 +88,7 @@ impl AbstractTree for IndexAssignment { index_context.set(index_key.clone(), new_value, None)?; - Ok(Value::Option(None)) + Ok(Value::none()) } fn expected_type(&self, _context: &Map) -> Result { diff --git a/src/abstract_tree/match.rs b/src/abstract_tree/match.rs index ad27c4e..f0f436d 100644 --- a/src/abstract_tree/match.rs +++ b/src/abstract_tree/match.rs @@ -72,7 +72,7 @@ impl AbstractTree for Match { if let Some(fallback) = &self.fallback { fallback.run(source, context) } else { - Ok(Value::Option(None)) + Ok(Value::none()) } } diff --git a/src/abstract_tree/mod.rs b/src/abstract_tree/mod.rs index bfee31a..1e2cdbf 100644 --- a/src/abstract_tree/mod.rs +++ b/src/abstract_tree/mod.rs @@ -59,7 +59,7 @@ impl AbstractTree for Root { } fn run(&self, source: &str, context: &Map) -> Result { - let mut value = Value::Option(None); + let mut value = Value::none(); for statement in &self.statements { value = statement.run(source, context)?; diff --git a/src/abstract_tree/type_definition.rs b/src/abstract_tree/type_definition.rs index 5b1c519..6c08711 100644 --- a/src/abstract_tree/type_definition.rs +++ b/src/abstract_tree/type_definition.rs @@ -215,7 +215,7 @@ impl AbstractTree for Type { } fn run(&self, _source: &str, _context: &Map) -> Result { - Ok(Value::Option(None)) + Ok(Value::none()) } fn expected_type(&self, _context: &Map) -> Result { diff --git a/src/abstract_tree/value_node.rs b/src/abstract_tree/value_node.rs index f32d9bc..690b505 100644 --- a/src/abstract_tree/value_node.rs +++ b/src/abstract_tree/value_node.rs @@ -57,7 +57,7 @@ impl AbstractTree for ValueNode { { function_context.set( parameter_name.inner().clone(), - Value::Option(None), + Value::none(), Some(parameter_type.clone()), )?; } diff --git a/src/abstract_tree/while.rs b/src/abstract_tree/while.rs index 210e19e..9828b50 100644 --- a/src/abstract_tree/while.rs +++ b/src/abstract_tree/while.rs @@ -30,7 +30,7 @@ impl AbstractTree for While { self.block.run(source, context)?; } - Ok(Value::Option(None)) + Ok(Value::none()) } fn expected_type(&self, context: &Map) -> Result { diff --git a/src/built_in_functions/assert.rs b/src/built_in_functions/assert.rs index c9c7905..6a3968e 100644 --- a/src/built_in_functions/assert.rs +++ b/src/built_in_functions/assert.rs @@ -14,7 +14,7 @@ impl BuiltInFunction for Assert { } } - Ok(Value::Option(None)) + Ok(Value::none()) } fn r#type(&self) -> Type { @@ -39,7 +39,7 @@ impl BuiltInFunction for AssertEqual { let right = arguments.get(1).unwrap(); if left == right { - Ok(Value::Option(None)) + Ok(Value::none()) } else { Err(Error::AssertEqualFailed { expected: left.clone(), diff --git a/src/built_in_functions/fs.rs b/src/built_in_functions/fs.rs index b017b80..b0c6771 100644 --- a/src/built_in_functions/fs.rs +++ b/src/built_in_functions/fs.rs @@ -65,7 +65,7 @@ impl BuiltInFunction for Write { write(path, file_content)?; - Ok(Value::Option(None)) + Ok(Value::none()) } fn r#type(&self) -> Type { @@ -86,11 +86,11 @@ impl BuiltInFunction for Append { fn run(&self, arguments: &[Value], _context: &Map) -> Result { let file_content = arguments .first() - .unwrap_or(&Value::Option(None)) + .unwrap_or(&Value::none()) .as_string()?; let path = arguments .get(1) - .unwrap_or(&Value::Option(None)) + .unwrap_or(&Value::none()) .as_string()?; File::options() @@ -99,7 +99,7 @@ impl BuiltInFunction for Append { .open(path)? .write_all(file_content.as_bytes())?; - Ok(Value::Option(None)) + Ok(Value::none()) } fn r#type(&self) -> Type { diff --git a/src/built_in_functions/packages.rs b/src/built_in_functions/packages.rs index ffa2891..4a468ef 100644 --- a/src/built_in_functions/packages.rs +++ b/src/built_in_functions/packages.rs @@ -23,7 +23,7 @@ impl BuiltInFunction for InstallPackages { command.spawn()?.wait()?; - Ok(Value::Option(None)) + Ok(Value::none()) } fn r#type(&self) -> Type { diff --git a/src/value/map.rs b/src/value/map.rs index f41fd2f..8bc22ef 100644 --- a/src/value/map.rs +++ b/src/value/map.rs @@ -58,7 +58,7 @@ impl Map { pub fn unset_all(&self) -> Result<()> { for (_key, (value, r#_type)) in self.variables.write()?.iter_mut() { - *value = Value::Option(None); + *value = Value::none(); } Ok(()) diff --git a/src/value/mod.rs b/src/value/mod.rs index de253ca..582cdc5 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -88,7 +88,7 @@ impl Value { } pub fn none() -> Self { - Value::Option(None) + Value::none() } pub fn is_string(&self) -> bool { @@ -120,7 +120,7 @@ impl Value { } pub fn is_none(&self) -> bool { - matches!(self, Value::Option(None)) + matches!(self, Value::none()) } pub fn is_map(&self) -> bool { @@ -234,7 +234,7 @@ impl Value { } } - /// Returns `()`, or returns `Err` if `self` is not a `Value::Option(None)`. + /// Returns `()`, or returns `Err` if `self` is not a `Value::none()`. pub fn as_none(&self) -> Result<()> { match self { Value::Option(option) => { @@ -255,7 +255,7 @@ impl Value { impl Default for &Value { fn default() -> Self { - &Value::Option(None) + &Value::none() } } @@ -546,7 +546,7 @@ impl From for Result { impl From<()> for Value { fn from(_: ()) -> Self { - Value::Option(None) + Value::none() } } @@ -769,7 +769,7 @@ impl<'de> Visitor<'de> for ValueVisitor { where E: serde::de::Error, { - Ok(Value::Option(None)) + Ok(Value::none()) } fn visit_some(self, deserializer: D) -> std::result::Result @@ -787,7 +787,7 @@ impl<'de> Visitor<'de> for ValueVisitor { where E: serde::de::Error, { - Ok(Value::Option(None)) + Ok(Value::none()) } fn visit_newtype_struct(self, deserializer: D) -> std::result::Result diff --git a/tests/interpret.rs b/tests/interpret.rs index ae27ea0..4ac9c5d 100644 --- a/tests/interpret.rs +++ b/tests/interpret.rs @@ -81,13 +81,13 @@ mod for_loop { fn modify_value_async() { let result = interpret( " - list = [] - async for i in [1 2 3] { list += i } - length(list) + fn = (x ) {} + + fn(1) ", ); - assert_eq!(Ok(Value::Integer(3)), result); + assert_eq!(Ok(Value::none()), result); } }