1
0

Implement add assignment for strings

This commit is contained in:
Jeff 2023-10-23 15:25:22 -04:00
parent 7342b383dc
commit 9dfe5689e4
3 changed files with 16 additions and 4 deletions

View File

@ -1,4 +1,8 @@
raw_data = (download "https://api.sampleapis.com/futurama/cast") raw_data = (download "https://api.sampleapis.com/futurama/cast")
dust_data = (from_json raw_data) cast_data = (from_json raw_data)
(assert_equal "Billy West", dust_data.0.name) names = transform cast_member in cast_data {
cast_member.name
}
(assert_equal "Billy West", names.0)

View File

@ -32,12 +32,19 @@ impl AbstractTree for For {
let value = self.expression.run(source, context)?; let value = self.expression.run(source, context)?;
let list = value.as_list()?; let list = value.as_list()?;
let key = self.identifier.inner(); let key = self.identifier.inner();
let mut context = context.clone();
let original_value = context.get_value(key)?;
for value in list { for value in list {
context.set_value(key.clone(), value.clone())?; context.set_value(key.clone(), value.clone())?;
self.item.run(source, &mut context)?; self.item.run(source, context)?;
}
if let Some(original_value) = original_value {
context.set_value(key.clone(), original_value)?;
} else {
context.set_value(key.clone(), Value::Empty)?;
} }
Ok(Value::Empty) Ok(Value::Empty)

View File

@ -320,6 +320,7 @@ impl AddAssign for Value {
(Value::Integer(left), Value::Integer(right)) => *left += right, (Value::Integer(left), Value::Integer(right)) => *left += right,
(Value::Float(left), Value::Float(right)) => *left += right, (Value::Float(left), Value::Float(right)) => *left += right,
(Value::Float(left), Value::Integer(right)) => *left += right as f64, (Value::Float(left), Value::Integer(right)) => *left += right as f64,
(Value::String(left), Value::String(right)) => *left += &right,
_ => {} _ => {}
} }
} }