Converted Robo to new style trait

This commit is contained in:
greg 2017-08-31 03:19:36 -07:00
parent 7a6dfbbd0e
commit 14ccf9f1be
2 changed files with 92 additions and 92 deletions

View File

@ -31,10 +31,10 @@ fn main() {
let languages: Vec<Box<ProgrammingLanguageInterface>> = let languages: Vec<Box<ProgrammingLanguageInterface>> =
vec![ vec![
Box::new(maaru_lang::Maaru::new()), Box::new(maaru_lang::Maaru::new()),
Box::new(robo_lang::Robo::new()),
/* /*
Box::new((schala_lang::Schala::new(), schala_lang::SchalaEvaluator::new())), Box::new((schala_lang::Schala::new(), schala_lang::SchalaEvaluator::new())),
Box::new((maaru_lang::Maaru::new(), maaru_lang::MaaruEvaluator::new(None))), Box::new((maaru_lang::Maaru::new(), maaru_lang::MaaruEvaluator::new(None))),
Box::new((robo_lang::Robo::new(), robo_lang::RoboEvaluator::new())),
*/ */
]; ];

View File

@ -1,7 +1,7 @@
extern crate itertools; extern crate itertools;
use self::itertools::Itertools; use self::itertools::Itertools;
use language::{ProgrammingLanguage, EvaluationMachine, ParseError, TokenError, LLVMCodeString}; use language::{ProgrammingLanguageInterface, EvalOptions, ProgrammingLanguage, EvaluationMachine, ParseError, TokenError, LLVMCodeString};
pub struct Robo { pub struct Robo {
} }
@ -56,16 +56,7 @@ pub enum Expression {
} }
impl ProgrammingLanguage for Robo { fn tokenize(input: &str) -> Result<Vec<Token>, TokenError> {
type Token = Token;
type AST = AST;
type Evaluator = RoboEvaluator;
fn name() -> String {
"Robo".to_string()
}
fn tokenize(input: &str) -> Result<Vec<Self::Token>, TokenError> {
use self::Token::*; use self::Token::*;
let mut tokens = Vec::new(); let mut tokens = Vec::new();
let mut iter = input.chars().peekable(); let mut iter = input.chars().peekable();
@ -138,16 +129,25 @@ impl ProgrammingLanguage for Robo {
} }
Ok(tokens) Ok(tokens)
}
impl ProgrammingLanguageInterface for Robo {
fn get_language_name(&self) -> String {
"Robo".to_string()
} }
fn parse(_input: Vec<Self::Token>) -> Result<Self::AST, ParseError> { fn evaluate_in_repl(&mut self, input: &str, eval_options: EvalOptions) -> Vec<String> {
Ok(vec!()) let mut output = vec!();
let tokens = match tokenize(input) {
Ok(tokens) => tokens,
Err(e) => {
output.push(format!("Tokenize error: {:?}", e));
return output;
} }
fn evaluate(_ast: Self::AST, _evaluator: &mut Self::Evaluator) -> Vec<String> { };
vec!["Unimplemented".to_string()]
} output.push(format!("{:?}", tokens));
fn compile(_ast: Self::AST) -> LLVMCodeString { output
unimplemented!()
} }
} }