From b54c71633cb72fb4daad968bd0511cff8b72bd14 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 8 Mar 2018 12:42:05 -0800 Subject: [PATCH] Eval list literals --- src/schala_lang/eval.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/schala_lang/eval.rs b/src/schala_lang/eval.rs index fa940e1..ec1061b 100644 --- a/src/schala_lang/eval.rs +++ b/src/schala_lang/eval.rs @@ -51,6 +51,7 @@ enum FullyEvaluatedExpr { string_rep: Rc, }, Tuple(Vec), + List(Vec) } impl FullyEvaluatedExpr { @@ -76,6 +77,18 @@ impl FullyEvaluatedExpr { buf }, &FuncLit(ref name) => format!("", 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")) } }, + ListLiteral(items) => Ok(List(items.into_iter().map(|item| self.eval_expr(item)).collect::,_>>()?)), x => Err(format!("Unimplemented thing {:?}", x)), } }