Eval list literals

This commit is contained in:
greg 2018-03-08 12:42:05 -08:00
parent 4c88a7ada6
commit 7e23e40a2f

View File

@ -51,6 +51,7 @@ enum FullyEvaluatedExpr {
string_rep: Rc<String>, string_rep: Rc<String>,
}, },
Tuple(Vec<FullyEvaluatedExpr>), Tuple(Vec<FullyEvaluatedExpr>),
List(Vec<FullyEvaluatedExpr>)
} }
impl FullyEvaluatedExpr { impl FullyEvaluatedExpr {
@ -76,6 +77,18 @@ impl FullyEvaluatedExpr {
buf buf
}, },
&FuncLit(ref name) => format!("<function {}>", name), &FuncLit(ref name) => format!("<function {}>", name),
&List(ref items) => {
let mut buf = String::new();
write!(buf, "[").unwrap();
for term in items.iter().map(|e| Some(e)).intersperse(None) {
match term {
Some(e) => write!(buf, "{}", e.to_string()).unwrap(),
None => write!(buf, ", ").unwrap()
}
}
write!(buf, "]").unwrap();
buf
}
} }
} }
} }
@ -194,6 +207,7 @@ impl<'a> State<'a> {
_ => Err(format!("Bad index expression")) _ => Err(format!("Bad index expression"))
} }
}, },
ListLiteral(items) => Ok(List(items.into_iter().map(|item| self.eval_expr(item)).collect::<Result<Vec<_>,_>>()?)),
x => Err(format!("Unimplemented thing {:?}", x)), x => Err(format!("Unimplemented thing {:?}", x)),
} }
} }