Pass symbol table reference to to_repl
This commit is contained in:
parent
3caf9c763c
commit
12ed2f5c8e
@ -70,12 +70,12 @@ fn paren_wrapped_vec(terms: impl Iterator<Item=String>) -> String {
|
|||||||
|
|
||||||
|
|
||||||
impl Node {
|
impl Node {
|
||||||
fn to_repl(&self) -> String {
|
fn to_repl(&self, symbol_table: &SymbolTable) -> String {
|
||||||
match self {
|
match self {
|
||||||
Node::Expr(e) => e.to_repl(),
|
Node::Expr(e) => e.to_repl(symbol_table),
|
||||||
Node::PrimObject { name, items, .. } if items.len() == 0 => format!("{}", name),
|
Node::PrimObject { name, items, .. } if items.len() == 0 => format!("{}", name),
|
||||||
Node::PrimObject { name, items, .. } => format!("{}{}", name, paren_wrapped_vec(items.iter().map(|x| x.to_repl()))),
|
Node::PrimObject { name, items, .. } => format!("{}{}", name, paren_wrapped_vec(items.iter().map(|x| x.to_repl(symbol_table)))),
|
||||||
Node::PrimTuple { items } => format!("{}", paren_wrapped_vec(items.iter().map(|x| x.to_repl()))),
|
Node::PrimTuple { items } => format!("{}", paren_wrapped_vec(items.iter().map(|x| x.to_repl(symbol_table)))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn is_true(&self) -> bool {
|
fn is_true(&self) -> bool {
|
||||||
@ -100,10 +100,12 @@ impl Expr {
|
|||||||
fn to_node(self) -> Node {
|
fn to_node(self) -> Node {
|
||||||
Node::Expr(self)
|
Node::Expr(self)
|
||||||
}
|
}
|
||||||
fn to_repl(&self) -> String {
|
fn to_repl(&self, symbol_table: &SymbolTable) -> String {
|
||||||
use self::Lit::*;
|
use self::Lit::*;
|
||||||
use self::Func::*;
|
use self::Func::*;
|
||||||
|
|
||||||
|
let _ = symbol_table;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Expr::Lit(ref l) => match l {
|
Expr::Lit(ref l) => match l {
|
||||||
Nat(n) => format!("{}", n),
|
Nat(n) => format!("{}", n),
|
||||||
@ -120,7 +122,7 @@ impl Expr {
|
|||||||
Expr::Constructor { type_name, arity, .. } => {
|
Expr::Constructor { type_name, arity, .. } => {
|
||||||
format!("<constructor for `{}` arity {}>", type_name, arity)
|
format!("<constructor for `{}` arity {}>", type_name, arity)
|
||||||
},
|
},
|
||||||
Expr::Tuple(exprs) => paren_wrapped_vec(exprs.iter().map(|x| x.to_repl())),
|
Expr::Tuple(exprs) => paren_wrapped_vec(exprs.iter().map(|x| x.to_repl(symbol_table))),
|
||||||
_ => format!("{:?}", self),
|
_ => format!("{:?}", self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,7 +156,10 @@ impl<'a> State<'a> {
|
|||||||
|
|
||||||
for statement in ast.0 {
|
for statement in ast.0 {
|
||||||
match self.statement(statement) {
|
match self.statement(statement) {
|
||||||
Ok(Some(ref output)) if repl => acc.push(Ok(output.to_repl())),
|
Ok(Some(ref output)) if repl => {
|
||||||
|
let ref symbol_table = self.symbol_table_handle.borrow();
|
||||||
|
acc.push(Ok(output.to_repl(symbol_table)))
|
||||||
|
},
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
acc.push(Err(format!("Runtime error: {}", error)));
|
acc.push(Err(format!("Runtime error: {}", error)));
|
||||||
@ -338,11 +343,13 @@ impl<'a> State<'a> {
|
|||||||
|
|
||||||
/* builtin functions */
|
/* builtin functions */
|
||||||
(IOPrint, &[ref anything]) => {
|
(IOPrint, &[ref anything]) => {
|
||||||
print!("{}", anything.to_repl());
|
let ref symbol_table = self.symbol_table_handle.borrow();
|
||||||
|
print!("{}", anything.to_repl(symbol_table));
|
||||||
Expr::Unit
|
Expr::Unit
|
||||||
},
|
},
|
||||||
(IOPrintLn, &[ref anything]) => {
|
(IOPrintLn, &[ref anything]) => {
|
||||||
println!("{}", anything.to_repl());
|
let ref symbol_table = self.symbol_table_handle.borrow();
|
||||||
|
println!("{}", anything.to_repl(symbol_table));
|
||||||
Expr::Unit
|
Expr::Unit
|
||||||
},
|
},
|
||||||
(IOGetLine, &[]) => {
|
(IOGetLine, &[]) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user