schala/src/maaru_lang/mod.rs

71 lines
1.6 KiB
Rust
Raw Normal View History

2017-08-29 00:28:19 -07:00
use ::std::marker::PhantomData;
pub mod tokenizer;
pub mod parser;
pub mod eval;
pub mod compilation;
2017-02-03 11:34:26 -08:00
2017-08-30 19:15:04 -07:00
use language::{ProgrammingLanguageInterface, EvalOptions, ProgrammingLanguage, EvaluationMachine, ParseError, TokenError, LLVMCodeString};
2017-08-29 00:28:19 -07:00
pub use self::eval::Evaluator as MaaruEvaluator;
2017-08-30 19:15:04 -07:00
pub struct NewMaaru<'a> {
evaluator: MaaruEvaluator<'a>
}
impl<'a> NewMaaru<'a> {
pub fn new() -> NewMaaru<'a> {
2017-08-30 19:15:04 -07:00
NewMaaru {
evaluator: MaaruEvaluator::new(None),
}
}
}
impl<'a> ProgrammingLanguageInterface for NewMaaru<'a> {
fn get_language_name(&self) -> String {
"Maaru".to_string()
}
fn evaluate_in_repl(&mut self, input: &str, options: EvalOptions) -> Vec<String> {
let mut output = vec![];
let tokens = match tokenizer::tokenize(input) {
Ok(tokens) => {
if options.debug_tokens {
output.push(format!("{:?}", tokens));
}
tokens
},
Err(err) => {
let msg = format!("Tokenization error: {:?}\n", err.msg);
output.push(msg);
return output;
}
};
let ast = match parser::parse(&tokens, &[]) {
Ok(ast) => {
if options.debug_parse {
output.push(format!("{:?}", ast));
}
ast
},
Err(err) => {
let msg = format!("Parse error: {:?}\n", err.msg);
output.push(msg);
return output;
}
};
let evaluation_output = self.evaluator.run(ast);
output.extend(evaluation_output);
return output;
}
}
2017-08-29 00:28:19 -07:00
pub struct Maaru<'a> { marker: PhantomData<&'a ()> }
impl<'a> Maaru<'a> {
pub fn new() -> Maaru <'a> {
Maaru { marker: PhantomData }
2017-02-02 01:21:40 -08:00
}
}