More boilerplate

Note: I need to make this boilerplate situation better
This commit is contained in:
greg 2018-03-10 18:26:26 -08:00
parent c176c1c918
commit a033c82d13

View File

@ -2,6 +2,14 @@ use schala_lib::{ProgrammingLanguageInterface, EvalOptions, TraceArtifact, Langu
use itertools::Itertools; use itertools::Itertools;
use schala_lang::{tokenizing, parsing}; use schala_lang::{tokenizing, parsing};
use self::tokenizing::*;
use self::parsing::*;
fn auto_parse(input: Vec<Token>) -> (Result<AST, ParseError>, Vec<String>) {
let err = ParseError { msg: format!("Not yet implemented") };
(Err(err), vec![])
}
pub struct Schala { } pub struct Schala { }
@ -27,8 +35,30 @@ impl ProgrammingLanguageInterface for Schala {
let token_string = tokens.iter().map(|t| format!("{:?}<L:{},C:{}>", t.token_type, t.offset.0, t.offset.1)).join(", "); let token_string = tokens.iter().map(|t| format!("{:?}<L:{},C:{}>", t.token_type, t.offset.0, t.offset.1)).join(", ");
output.add_artifact(TraceArtifact::new("tokens", format!("{:?}", token_string))); output.add_artifact(TraceArtifact::new("tokens", format!("{:?}", token_string)));
} }
{
let token_errors: Vec<&String> = tokens.iter().filter_map(|t| t.get_error()).collect();
if token_errors.len() != 0 {
output.add_output(format!("Tokenization error: {:?}\n", token_errors));
return output;
}
}
let ast = match auto_parse(tokens) {
(Ok(ast), trace) => {
if options.debug_parse {
output.add_artifact(TraceArtifact::new_parse_trace(trace));
output.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast)));
}
ast
},
(Err(err), trace) => {
output.add_artifact(TraceArtifact::new_parse_trace(trace));
output.add_output(format!("Parse error: {:?}\n", err.msg));
return output;
}
};
output.add_output(format!("{:?}", tokens)); output.add_output(format!("{:?}", ast));
output output
} }
} }