schala/src/schala_lang/mod.rs

52 lines
1.2 KiB
Rust
Raw Normal View History

2017-08-31 20:59:43 -07:00
use language::{ProgrammingLanguageInterface, EvalOptions, TraceArtifact, ReplOutput};
2017-08-29 04:15:31 -07:00
2017-08-29 04:27:07 -07:00
mod parsing;
2017-08-29 04:15:31 -07:00
pub struct Schala {
}
impl Schala {
pub fn new() -> Schala {
Schala { }
}
}
2017-08-31 14:57:56 -07:00
impl ProgrammingLanguageInterface for Schala {
fn get_language_name(&self) -> String {
2017-08-29 04:15:31 -07:00
"Schala".to_string()
}
2017-09-01 02:08:26 -07:00
fn evaluate_in_repl(&mut self, input: &str, options: &EvalOptions) -> ReplOutput {
2017-08-31 20:59:43 -07:00
let mut output = ReplOutput::default();
2017-08-31 16:26:55 -07:00
let tokens = match parsing::tokenize(input) {
2017-08-31 20:59:43 -07:00
Ok(tokens) => {
if options.debug_tokens {
output.add_artifact(TraceArtifact::new("tokens", format!("{:?}", tokens)));
}
tokens
},
Err(err) => {
output.add_output(format!("Tokenization error: {:?}\n", err.msg));
2017-08-31 16:26:55 -07:00
return output;
}
};
2017-08-31 20:59:43 -07:00
let ast = match parsing::parse(tokens) {
Ok(ast) => {
if options.debug_parse {
output.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast)));
}
ast
},
Err(err) => {
output.add_output(format!("Parse error: {:?}\n", err.msg));
2017-08-31 16:26:55 -07:00
return output;
}
};
2017-08-31 20:59:43 -07:00
let evaluation_output = format!("test eval");
output.add_output(evaluation_output);
return output;
2017-08-29 04:15:31 -07:00
}
}