Kill old trait infrastructure

This commit is contained in:
greg 2018-04-30 14:34:15 -07:00
parent 491face68b
commit 83fe71f721
5 changed files with 18 additions and 31 deletions

View File

@ -7,7 +7,7 @@ mod parser;
mod eval;
mod compilation;
use schala_repl::{ProgrammingLanguageInterface, EvalOptions, LanguageOutput, TraceArtifact};
use schala_repl::{ProgrammingLanguageInterface, EvalOptions, UnfinishedComputation, FinishedComputation, TraceArtifact};
#[derive(Debug)]
pub struct TokenError {
@ -42,8 +42,8 @@ impl<'a> ProgrammingLanguageInterface for Maaru<'a> {
format!("maaru")
}
fn evaluate_in_repl(&mut self, input: &str, options: &EvalOptions) -> LanguageOutput {
let mut output = LanguageOutput::default();
fn execute_pipeline(&mut self, input: &str, options: &EvalOptions) -> FinishedComputation {
let mut output = UnfinishedComputation::default();
let tokens = match tokenizer::tokenize(input) {
Ok(tokens) => {
@ -53,8 +53,7 @@ impl<'a> ProgrammingLanguageInterface for Maaru<'a> {
tokens
},
Err(err) => {
output.add_output(format!("Tokenization error: {:?}\n", err.msg));
return output;
return output.finish(Err(format!("Tokenization error: {:?}\n", err.msg)))
}
};
@ -66,16 +65,14 @@ impl<'a> ProgrammingLanguageInterface for Maaru<'a> {
ast
},
Err(err) => {
output.add_output(format!("Parse error: {:?}\n", err.msg));
return output;
return output.finish(Err(format!("Parse error: {:?}\n", err.msg)))
}
};
let mut evaluation_output = String::new();
for s in self.evaluator.run(ast).iter() {
evaluation_output.push_str(s);
}
output.add_output(evaluation_output);
return output;
output.finish(Ok(evaluation_output))
}
/* TODO make this work with new framework */

View File

@ -4,7 +4,7 @@ extern crate itertools;
extern crate schala_repl;
use itertools::Itertools;
use schala_repl::{ProgrammingLanguageInterface, EvalOptions, LanguageOutput};
use schala_repl::{ProgrammingLanguageInterface, EvalOptions, FinishedComputation, UnfinishedComputation};
pub struct Robo {
}
@ -155,18 +155,16 @@ impl ProgrammingLanguageInterface for Robo {
format!("robo")
}
fn evaluate_in_repl(&mut self, input: &str, _eval_options: &EvalOptions) -> LanguageOutput {
let mut output = LanguageOutput::default();
fn execute_pipeline(&mut self, input: &str, _eval_options: &EvalOptions) -> FinishedComputation {
let output = UnfinishedComputation::default();
let tokens = match tokenize(input) {
Ok(tokens) => tokens,
Err(e) => {
output.add_output(format!("Tokenize error: {:?}", e));
return output;
return output.finish(Err(format!("Tokenize error: {:?}", e)));
}
};
output.add_output(format!("{:?}", tokens));
output
output.finish(Ok(format!("{:?}", tokens)))
}
}

View File

@ -4,7 +4,7 @@ extern crate itertools;
extern crate schala_repl;
use itertools::Itertools;
use schala_repl::{ProgrammingLanguageInterface, EvalOptions, LanguageOutput};
use schala_repl::{ProgrammingLanguageInterface, EvalOptions, UnfinishedComputation, FinishedComputation};
use std::iter::Peekable;
use std::vec::IntoIter;
use std::str::Chars;
@ -73,12 +73,11 @@ impl ProgrammingLanguageInterface for Rukka {
format!("rukka")
}
fn evaluate_in_repl(&mut self, input: &str, _eval_options: &EvalOptions) -> LanguageOutput {
let mut output = LanguageOutput::default();
fn execute_pipeline(&mut self, input: &str, _eval_options: &EvalOptions) -> FinishedComputation {
let mut output = UnfinishedComputation::default();
let sexps = match read(input) {
Err(err) => {
output.add_output(format!("Error: {}", err));
return output;
return output.finish(Err(format!("Error: {}", err)));
},
Ok(sexps) => sexps
};
@ -89,8 +88,7 @@ impl ProgrammingLanguageInterface for Rukka {
Err(err) => format!("{} Error: {}", i, err),
}
}).intersperse(format!("\n")).collect();
output.add_output(output_str);
output
output.finish(Ok(output_str))
}
}

View File

@ -163,12 +163,6 @@ impl TraceArtifact {
}
pub trait ProgrammingLanguageInterface {
/* old */
fn evaluate_in_repl(&mut self, _: &str, _: &EvalOptions) -> LanguageOutput {
LanguageOutput { output: format!("Defunct"), artifacts: vec![], failed: false }
}
/* old */
fn execute_pipeline(&mut self, _input: &str, _eval_options: &EvalOptions) -> FinishedComputation {
FinishedComputation { artifacts: HashMap::new(), text_output: Err(format!("Execution pipeline not done")) }
}

View File

@ -35,8 +35,8 @@ struct Output {
fn interpreter_input(input: Json<Input>, generators: State<Vec<PLIGenerator>>) -> Json<Output> {
let schala_gen = generators.get(0).unwrap();
let mut schala: Box<ProgrammingLanguageInterface> = schala_gen();
let code_output = schala.evaluate_in_repl(&input.source, &EvalOptions::default());
Json(Output { text: code_output.to_string() })
let code_output = schala.execute_pipeline(&input.source, &EvalOptions::default());
Json(Output { text: code_output.to_repl() })
}
pub fn web_main(language_generators: Vec<PLIGenerator>) {