schala/src/language.rs

90 lines
1.8 KiB
Rust
Raw Normal View History

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);
#[derive(Debug, Default)]
2017-08-30 19:09:22 -07:00
pub struct EvalOptions {
2017-08-30 19:15:04 -07:00
pub debug_tokens: bool,
pub debug_parse: bool,
pub debug_type: bool,
2017-09-01 02:08:26 -07:00
pub show_llvm_ir: bool,
2017-08-31 16:26:55 -07:00
pub trace_evaluation: bool,
2017-08-30 19:09:22 -07:00
}
2017-08-31 20:59:43 -07:00
#[derive(Debug, Default)]
pub struct ReplOutput {
output: String,
artifacts: Vec<TraceArtifact>
}
impl ReplOutput {
pub fn add_artifact(&mut self, artifact: TraceArtifact) {
self.artifacts.push(artifact);
}
pub fn add_output(&mut self, output: String) {
self.output = output;
}
pub fn to_string(&self) -> String {
let mut acc = String::new();
for line in self.artifacts.iter() {
acc.push_str(&line.debug_output);
}
acc.push_str(&self.output);
acc
}
pub fn print_to_screen(&self) {
for line in self.artifacts.iter() {
println!("{}: {}", line.stage_name, line.debug_output);
}
println!("{}", self.output);
}
}
/*
//TODO I'll probably wanna implement this later
#[derive(Debug)]
pub struct CompilationOutput {
output: LLVMCodeString,
artifacts: Vec<TraceArtifact>,
}
*/
#[derive(Debug)]
pub struct TraceArtifact {
stage_name: String,
debug_output: String,
}
impl TraceArtifact {
pub fn new(stage: &str, debug: String) -> TraceArtifact {
TraceArtifact { stage_name: stage.to_string(), debug_output: debug }
}
}
2017-08-30 19:09:22 -07:00
pub trait ProgrammingLanguageInterface {
2017-09-01 02:08:26 -07:00
fn evaluate_in_repl(&mut self, input: &str, eval_options: &EvalOptions) -> ReplOutput;
2017-08-30 19:09:22 -07:00
fn get_language_name(&self) -> String;
2017-08-31 19:15:32 -07:00
fn compile(&mut self, _input: &str) -> LLVMCodeString {
LLVMCodeString("".to_string())
}
fn can_compile(&self) -> bool {
false
}
2017-08-30 19:09:22 -07:00
}