From fb009497a4f1403c1cc8a06e0077b7840ee04fd8 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 31 Aug 2017 16:26:55 -0700 Subject: [PATCH] Still more cleanup --- src/language.rs | 2 +- src/main.rs | 12 +++++++----- src/schala_lang/mod.rs | 20 ++++++++++++++++++-- src/schala_lang/parsing.rs | 3 +++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/language.rs b/src/language.rs index 8bae75e..90ff0b4 100644 --- a/src/language.rs +++ b/src/language.rs @@ -103,7 +103,7 @@ pub struct EvalOptions { pub debug_tokens: bool, pub debug_parse: bool, pub debug_type: bool, - pub debug_eval: bool, + pub trace_evaluation: bool, } pub trait ProgrammingLanguageInterface { diff --git a/src/main.rs b/src/main.rs index 774084b..021c770 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ mod maaru_lang; mod robo_lang; mod language; -use language::{ProgrammingLanguage, LanguageInterface, ProgrammingLanguageInterface, EvalOptions, LLVMCodeString}; +use language::{ProgrammingLanguageInterface, EvalOptions, LLVMCodeString}; mod llvm_wrap; @@ -77,9 +77,11 @@ fn main() { .and_then(|lang| { language_names.iter().position(|x| { *x == lang }) }) .unwrap_or(0); + let mut options = EvalOptions::default(); let show_llvm_ir = option_matches.opt_present("v"); + options.trace_evaluation = option_matches.opt_present("t"); + let compile = !option_matches.opt_present("i"); - let trace_evaluation = option_matches.opt_present("t"); match option_matches.free[..] { [] | [_] => { @@ -89,7 +91,7 @@ fn main() { } [_, ref filename, _..] => { let mut language = maaru_lang::Maaru::new(); - run_noninteractive(filename, &mut language, trace_evaluation, compile); + run_noninteractive(filename, &mut language, options, compile); } }; } @@ -124,7 +126,7 @@ fn program_options() -> getopts::Options { options } -fn run_noninteractive(filename: &str, language: &mut T, trace_evaluation: bool, compile: bool) { +fn run_noninteractive(filename: &str, language: &mut T, options: EvalOptions, compile: bool) { let mut source_file = File::open(&Path::new(filename)).unwrap(); let mut buffer = String::new(); source_file.read_to_string(&mut buffer).unwrap(); @@ -222,7 +224,7 @@ impl Repl { fn input_handler(&mut self, input: &str) -> String { let ref mut language = self.languages[self.current_language_index]; - let mut options = language::EvalOptions::default(); + let options = language::EvalOptions::default(); /* options.show_tokens = self.show_tokens; options.show_parse = self.show_parse; diff --git a/src/schala_lang/mod.rs b/src/schala_lang/mod.rs index 62fdbb3..4284bad 100644 --- a/src/schala_lang/mod.rs +++ b/src/schala_lang/mod.rs @@ -16,7 +16,23 @@ impl ProgrammingLanguageInterface for Schala { "Schala".to_string() } - fn evaluate_in_repl(&mut self, input: &str, eval_options: EvalOptions) -> Vec { - vec!(format!("evaluation")) + fn evaluate_in_repl(&mut self, input: &str, _eval_options: EvalOptions) -> Vec { + let mut output = vec!(format!("test eval")); + + let tokens = match parsing::tokenize(input) { + Ok(tokens) => tokens, + Err(e) => { output.push(format!("{}", e.msg)); + return output; + } + }; + + let _ast = match parsing::parse(tokens) { + Ok(ast) => ast, + Err(e) => { output.push(format!("{}", e.msg)); + return output; + } + }; + + output } } diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index eca748f..f89b4db 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -1,6 +1,7 @@ use language::{TokenError, ParseError}; use std::rc::Rc; +#[allow(dead_code)] #[derive(Debug)] pub enum Token { Newline, @@ -82,9 +83,11 @@ postop := ε | LParen exprlist RParen | LBracket expression RBracket op := '+', '-', etc. */ +#[allow(dead_code)] #[derive(Debug)] pub struct AST { } +#[allow(dead_code)] pub fn parse(input: Vec) -> Result { Ok(AST { }) }