Starting work to trait-ify language
This commit is contained in:
parent
eaf86ea908
commit
f5022a771c
@ -16,5 +16,6 @@ c = if a {
|
||||
}
|
||||
|
||||
q = 4
|
||||
q = q + 2
|
||||
q + 1 + c
|
||||
|
||||
|
18
src/language.rs
Normal file
18
src/language.rs
Normal 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);
|
||||
}
|
32
src/main.rs
32
src/main.rs
@ -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!()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user