Starting work to trait-ify language

This commit is contained in:
greg 2017-01-21 01:49:45 -08:00
parent eaf86ea908
commit f5022a771c
3 changed files with 51 additions and 0 deletions

View File

@ -16,5 +16,6 @@ c = if a {
}
q = 4
q = q + 2
q + 1 + c

18
src/language.rs Normal file
View File

@ -0,0 +1,18 @@
pub struct TokenError {
pub msg: String,
}
pub struct ParseError {
pub msg: String,
}
pub trait ProgrammingLanguage {
type Token;
type AST;
fn tokenize(input: &str) -> Result<Vec<Self::Token>, TokenError>;
fn parse(input: Vec<Self::Token>) -> Result<Self::AST, ParseError>;
fn evaluate(input: &Self::AST);
fn compile(input: &Self::AST);
}

View File

@ -16,6 +16,9 @@ mod parser;
use eval::Evaluator;
mod eval;
use language::{ProgrammingLanguage, ParseError, TokenError};
mod language;
use compilation::{compilation_sequence, compile_ast};
mod compilation;
mod llvm_wrap;
@ -137,6 +140,13 @@ impl<'a> Repl<'a> {
println!("Exiting...");
}
fn new_input_handler(input: &str) -> String {
let language = Schala {};
unimplemented!()
}
fn input_handler(&mut self, input: &str) -> String {
let mut output = String::new();
@ -226,3 +236,25 @@ impl<'a> Repl<'a> {
return true;
}
}
struct Schala { }
impl ProgrammingLanguage for Schala {
type Token = tokenizer::Token;
type AST = parser::AST;
fn tokenize(input: &str) -> Result<Vec<Self::Token>, TokenError> {
tokenizer::tokenize(input).map_err(|x| TokenError { msg: x.msg })
}
fn parse(input: Vec<Self::Token>) -> Result<Self::AST, ParseError> {
unimplemented!()
}
fn evaluate(input: &Self::AST) {
unimplemented!()
}
fn compile(input: &Self::AST) {
unimplemented!()
}
}