diff options
Diffstat (limited to 'crates/rebel-lang/src/value.rs')
-rw-r--r-- | crates/rebel-lang/src/value.rs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/crates/rebel-lang/src/value.rs b/crates/rebel-lang/src/value.rs index 1e5750e..db15d10 100644 --- a/crates/rebel-lang/src/value.rs +++ b/crates/rebel-lang/src/value.rs @@ -25,7 +25,7 @@ pub enum Value { Str(String), Tuple(Vec<Value>), Array(Vec<Value>), - Map(HashMap<String, Value>), + Struct(HashMap<String, Value>), Fn(Box<Func>), } @@ -46,7 +46,7 @@ impl Value { Box::new(Self::array_elem_type(elems)?), ArrayLen::Fixed(elems.len()), ), - Value::Map(entries) => Type::Map( + Value::Struct(entries) => Type::Struct( entries .iter() .map(|(k, v)| Ok((k.clone(), v.typ()?))) @@ -238,7 +238,7 @@ impl Value { let index: usize = name.parse().or(Err(EvalError))?; elems.into_iter().nth(index).ok_or(EvalError)? } - Map(mut entries) => entries.remove(name).ok_or(EvalError)?, + Struct(mut entries) => entries.remove(name).ok_or(EvalError)?, _ => return Err(EvalError), }) } @@ -281,12 +281,14 @@ impl Value { .map(|elem| Self::eval(ctx, elem)) .collect::<Result<_>>()?, ), - Literal::Map(entries) => Map(entries - .iter() - .map(|ast::MapEntry { key, value }| { - Ok(((*key).to_owned(), Self::eval(ctx, value)?)) - }) - .collect::<Result<_>>()?), + Literal::Struct(entries) => Struct( + entries + .iter() + .map(|ast::StructField { key, value }| { + Ok(((*key).to_owned(), Self::eval(ctx, value)?)) + }) + .collect::<Result<_>>()?, + ), }) } } @@ -325,7 +327,7 @@ impl Display for Value { } f.write_str("]") } - Value::Map(entries) => { + Value::Struct(entries) => { let mut first = true; f.write_str("{")?; for (key, value) in entries { |