2017-01-21 14:34:17 -08:00
|
|
|
use std::fmt::Debug;
|
2017-01-21 01:49:45 -08:00
|
|
|
|
|
|
|
pub struct TokenError {
|
|
|
|
pub msg: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ParseError {
|
|
|
|
pub msg: String,
|
|
|
|
}
|
|
|
|
|
2017-01-23 00:03:08 -08:00
|
|
|
pub trait ProgrammingLanguage<Evaluator> {
|
2017-01-21 14:34:17 -08:00
|
|
|
type Token: Debug;
|
|
|
|
type AST: Debug;
|
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-23 00:03:08 -08:00
|
|
|
fn evaluate(input: Self::AST, evaluator: &mut Evaluator) -> Vec<String>;
|
2017-01-21 01:49:45 -08:00
|
|
|
fn compile(input: &Self::AST);
|
|
|
|
}
|