From 8e3a571d67a3333ed359a0cd37b3198c8816f812 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 31 Jul 2015 01:38:35 -0700 Subject: [PATCH] .env dirctive to display environment --- src/evaluate.rs | 6 +++--- src/main.rs | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/evaluate.rs b/src/evaluate.rs index c2ff8d7..dadc571 100644 --- a/src/evaluate.rs +++ b/src/evaluate.rs @@ -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) => { diff --git a/src/main.rs b/src/main.rs index 8d7774c..0669e3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); },