2017-01-21 14:34:17 -08:00
|
|
|
use std::fmt::Debug;
|
2017-01-21 01:49:45 -08:00
|
|
|
|
2017-01-23 19:51:27 -08:00
|
|
|
#[derive(Debug)]
|
2017-01-21 01:49:45 -08:00
|
|
|
pub struct TokenError {
|
|
|
|
pub msg: String,
|
|
|
|
}
|
|
|
|
|
2017-01-23 19:45:26 -08:00
|
|
|
impl TokenError {
|
|
|
|
pub fn new(msg: &str) -> TokenError {
|
|
|
|
TokenError { msg: msg.to_string() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-23 19:51:27 -08:00
|
|
|
#[derive(Debug)]
|
2017-01-21 01:49:45 -08:00
|
|
|
pub struct ParseError {
|
|
|
|
pub msg: String,
|
|
|
|
}
|
|
|
|
|
2017-01-23 19:11:50 -08:00
|
|
|
pub struct LLVMCodeString(pub String);
|
|
|
|
|
2017-01-31 00:53:31 -08:00
|
|
|
pub trait ProgrammingLanguage {
|
2017-01-21 14:34:17 -08:00
|
|
|
type Token: Debug;
|
|
|
|
type AST: Debug;
|
2017-01-31 00:53:31 -08:00
|
|
|
type Evaluator: EvaluationMachine;
|
2017-01-21 01:49:45 -08:00
|
|
|
|
|
|
|
fn tokenize(input: &str) -> Result<Vec<Self::Token>, TokenError>;
|
|
|
|
fn parse(input: Vec<Self::Token>) -> Result<Self::AST, ParseError>;
|
2017-01-31 00:53:31 -08:00
|
|
|
fn evaluate(ast: Self::AST, evaluator: &mut Self::Evaluator) -> Vec<String>;
|
2017-01-23 19:11:50 -08:00
|
|
|
fn compile(ast: Self::AST) -> LLVMCodeString;
|
2017-01-21 01:49:45 -08:00
|
|
|
}
|
2017-01-24 20:09:14 -08:00
|
|
|
|
|
|
|
pub trait EvaluationMachine {
|
|
|
|
fn set_option(&mut self, option: &str, value: bool) -> bool;
|
|
|
|
fn new() -> Self;
|
|
|
|
}
|
2017-01-31 00:53:31 -08:00
|
|
|
|
|
|
|
pub trait LanguageWrapper {
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<X, T, A, E> LanguageWrapper for X where X: ProgrammingLanguage<Token=T, AST=A, Evaluator=E>, T: Debug, A: Debug, E: EvaluationMachine {
|
|
|
|
|
|
|
|
}
|