Print output of tuples

This commit is contained in:
greg 2018-03-03 13:26:22 -08:00
parent a7672171a6
commit 86d9e90e7c

View File

@ -1,7 +1,11 @@
use schala_lang::parsing::{AST, Statement, Declaration, Expression, Variant, ExpressionType};
use schala_lang::builtin::{BinOp, PrefixOp};
use std::collections::HashMap; use std::collections::HashMap;
use std::rc::Rc; use std::rc::Rc;
use std::fmt::Write;
use itertools::Itertools;
use schala_lang::parsing::{AST, Statement, Declaration, Expression, Variant, ExpressionType};
use schala_lang::builtin::{BinOp, PrefixOp};
pub struct State<'a> { pub struct State<'a> {
parent_frame: Option<&'a State<'a>>, parent_frame: Option<&'a State<'a>>,
@ -59,7 +63,18 @@ impl FullyEvaluatedExpr {
&Str(ref s) => format!("\"{}\"", s), &Str(ref s) => format!("\"{}\"", s),
&Bool(ref b) => format!("{}", b), &Bool(ref b) => format!("{}", b),
&Custom { ref string_rep } => format!("{}", string_rep), &Custom { ref string_rep } => format!("{}", string_rep),
&Tuple(ref _items) => format!("(tuple to be defined later)"), &Tuple(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
},
&FuncLit(ref name) => format!("<function {}>", name), &FuncLit(ref name) => format!("<function {}>", name),
} }
} }