.env dirctive to display environment

This commit is contained in:
greg 2015-07-31 01:38:35 -07:00
parent f88f115567
commit 8e3a571d67
2 changed files with 8 additions and 5 deletions

View File

@ -23,7 +23,7 @@ impl Environment {
}
}
fn display(&self) {
pub fn display(&self) {
match *self {
Environment(ref hash_map) =>
for (var, binding) in hash_map {
@ -37,7 +37,7 @@ impl Environment {
pub fn evaluate(ast: AST, env: Environment) -> (String, Environment) {
let (mut reduced_ast, final_env) = reduce((ast, env));
let (reduced_ast, final_env) = reduce((ast, env));
let output = match reduced_ast {
DoNothing => "".to_string(),
@ -51,7 +51,7 @@ pub fn evaluate(ast: AST, env: Environment) -> (String, Environment) {
}
fn reduce(evr: EvalResult) -> EvalResult {
let (mut ast, mut env) = evr;
let (ast, mut env) = evr;
match ast {
Name(name) => {

View File

@ -34,7 +34,7 @@ fn repl() {
break;
}
if handle_interpreter_directive(&buf) {
if handle_interpreter_directive(&buf, &env) {
continue;
}
@ -59,7 +59,7 @@ fn repl() {
}
}
fn handle_interpreter_directive(input: &str) -> bool {
fn handle_interpreter_directive(input: &str, env: &Environment) -> bool {
match input.chars().nth(0) {
Some('.') => (),
@ -72,6 +72,9 @@ fn handle_interpreter_directive(input: &str) -> bool {
println!("Siturei simasu");
process::exit(0);
},
Some(s) if *s == ".env" => {
env.display();
},
Some(s) => {
println!("Unknown directive: {}", s);
},