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 = 4
|
||||||
|
q = q + 2
|
||||||
q + 1 + c
|
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;
|
use eval::Evaluator;
|
||||||
mod eval;
|
mod eval;
|
||||||
|
|
||||||
|
use language::{ProgrammingLanguage, ParseError, TokenError};
|
||||||
|
mod language;
|
||||||
|
|
||||||
use compilation::{compilation_sequence, compile_ast};
|
use compilation::{compilation_sequence, compile_ast};
|
||||||
mod compilation;
|
mod compilation;
|
||||||
mod llvm_wrap;
|
mod llvm_wrap;
|
||||||
@ -137,6 +140,13 @@ impl<'a> Repl<'a> {
|
|||||||
println!("Exiting...");
|
println!("Exiting...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn new_input_handler(input: &str) -> String {
|
||||||
|
|
||||||
|
let language = Schala {};
|
||||||
|
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
fn input_handler(&mut self, input: &str) -> String {
|
fn input_handler(&mut self, input: &str) -> String {
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
|
|
||||||
@ -226,3 +236,25 @@ impl<'a> Repl<'a> {
|
|||||||
return true;
|
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