schala/src/schala_lang/mod.rs

55 lines
1.4 KiB
Rust
Raw Normal View History

use ::std::marker::PhantomData;
2017-01-23 11:27:11 -08:00
pub mod tokenizer;
pub mod parser;
pub mod eval;
pub mod compilation;
use language::{ProgrammingLanguage, EvaluationMachine, ParseError, TokenError, LLVMCodeString};
pub use self::eval::Evaluator as SchalaEvaluator;
2017-01-23 11:27:11 -08:00
pub struct Schala<'a> { marker: PhantomData<&'a ()> }
impl<'a> Schala<'a> {
pub fn new() -> Schala<'a> {
Schala { marker: PhantomData }
}
}
2017-01-23 11:27:11 -08:00
impl<'a> ProgrammingLanguage for Schala<'a> {
2017-01-23 11:27:11 -08:00
type Token = tokenizer::Token;
type AST = parser::AST;
type Evaluator = SchalaEvaluator<'a>;
2017-01-23 11:27:11 -08:00
2017-02-02 01:04:15 -08:00
fn name() -> String {
"Schala".to_string()
}
2017-01-23 11:27:11 -08:00
fn tokenize(input: &str) -> Result<Vec<Self::Token>, TokenError> {
2017-01-23 19:45:26 -08:00
tokenizer::tokenize(input)
2017-01-23 11:27:11 -08:00
}
fn parse(input: Vec<Self::Token>) -> Result<Self::AST, ParseError> {
parser::parse(&input, &[]).map_err(|x| ParseError { msg: x.msg })
}
fn evaluate(ast: Self::AST, evaluator: &mut Self::Evaluator) -> Vec<String> {
2017-01-23 11:27:11 -08:00
evaluator.run(ast)
}
2017-01-23 19:11:50 -08:00
fn compile(ast: Self::AST) -> LLVMCodeString {
2017-01-23 11:27:11 -08:00
compilation::compile_ast(ast)
}
}
impl<'a> EvaluationMachine for SchalaEvaluator<'a> {
fn set_option(&mut self, option: &str, value: bool) -> bool {
if option == "trace_evaluation" {
self.trace_evaluation = value;
return true;
}
false
}
fn new() -> SchalaEvaluator<'a> {
SchalaEvaluator::new(None)
}
}